<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array();
$d = array();
for($x = 1; $x <= $a; $x++)
{
    list($e, $f) = explode(" ", trim(fgets(STDIN)));
    $g = max($e, $f);
    $h = min($e, $f);
    array_push($c, $g);
    array_push($d, $h);
}
rsort($d);
sort($c);
if($c[0] >= $d[0])
{
    if($b > $c[0])
    {
        print $b - $c[0];
    }
    elseif($b < $d[0])
    {
        print $d[0] - $b;
    }
    else
    {
        print "0";
    }
}
else
{
    print "-1";
}
?>

<?php

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

$arr = file($in);
//$data = file_get_contents($in);
//$r = fopen($in, 'r');

list($n, $x0) = explode(' ', array_shift($arr));

$n = intval($n);
$x0 = intval($x0);

while (!trim($arr[count($arr) - 1])) {
	array_pop($arr);
}

for ($i = 0; $i < $n ; $i++) {
	$value = $arr[$i];
	$vals = explode(' ', trim($value));
	sort($vals, SORT_NUMERIC);
	$min = intval(array_shift($vals));
	$max = intval(array_shift($vals));
//	echo "$min $max\n";
	$supermin = isset($supermin) ? ($min > $supermin ? $min : $supermin) : $min;
	$supermax = isset($supermax) ? ($max < $supermax ? $max : $supermax) : $max;
}
//echo "\n";

echo $supermax < $supermin ? '-1' : (($x0 <= $supermax && $x0 >= $supermin ? 0 : min(abs($x0 - $supermin), abs($x0 - $supermax))));

//fclose($r);

<?php
list($n,$m)=explode(' ',rtrim(fgets(STDIN)));
$min_x=$min_y=100;
$max_x=$max_y=-1;
$letter=array();
for ($i=0;$i<$n;$i++) {
  $line=rtrim(fgets(STDIN));
  $letter[]=$line;
  for ($j=0;$j<$m;$j++) {
    if ($line[$j]=='*') {
      $min_x=min($min_x,$j);
      $min_y=min($min_y,$i);
      $max_x=max($max_x,$j);
      $max_y=max($max_y,$i);
    }
  }
}
for ($i=$min_y;$i<=$max_y;$i++) {
  for ($j=$min_x;$j<=$max_x;$j++) {
    echo $letter[$i][$j];
  }
  echo "\n";
}
?>

<?php

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

$arr = file($in);
//$data = file_get_contents($in);
//$r = fopen($in, 'r');

list($n, $x0) = explode(' ', array_shift($arr));

while (!trim($arr[count($arr) - 1])) {
	array_pop($arr);
}

for ($i = 0; $i < $n ; $i++) {
	$value = $arr[$i];
	$vals = explode(' ', trim($value));
	sort($vals, SORT_NUMERIC);
	$min = intval(array_shift($vals));
	$max = intval(array_shift($vals));
//	echo "$min $max\n";
	$supermin = isset($supermin) ? ($min > $supermin ? $min : $supermin) : $min;
	$supermax = isset($supermax) ? ($max < $supermax ? $max : $supermax) : $max;
}
//echo "\n";
//echo "$supermin $supermax\n";

echo $supermax < $supermin ? '-1' : min(abs($x0 - $supermin), abs($x0 - $supermax));

//fclose($r);

<?php

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

$arr = file($in);
//$data = file_get_contents($in);
//$r = fopen($in, 'r');

list($n, $x0) = explode(' ', array_shift($arr));

while (!trim($arr[count($arr) - 1])) {
	array_pop($arr);
}

foreach ($arr as $value) {
	$vals = explode(' ', trim($value));
	sort($vals, SORT_NUMERIC);
	$min = intval(array_shift($vals));
	$max = intval(array_shift($vals));
//	echo "$min $max\n";
	$supermin = isset($supermin) ? ($min > $supermin ? $min : $supermin) : $min;
	$supermax = isset($supermax) ? ($max < $supermax ? $max : $supermax) : $max;
}
//echo "\n";
//echo "$supermin $supermax\n";

echo $supermax < $supermin ? '-1' : min(abs($x0 - $supermin), abs($x0 - $supermax));

//fclose($r);

<?php

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

$arr = file($in);
//$data = file_get_contents($in);
//$r = fopen($in, 'r');

list($n, $x0) = explode(' ', array_shift($arr));

while (!$arr[count($arr) - 1]) {
	array_pop($arr);
}

foreach ($arr as $value) {
	$vals = explode(' ', $value);
	sort($vals, SORT_NUMERIC);
	$min = intval(array_shift($vals));
	$max = intval(array_shift($vals));

	$supermin = isset($supermin) ? ($min > $supermin ? $min : $supermin) : $min;
	$supermax = isset($supermax) ? ($max < $supermax ? $max : $supermax) : $max;
}

echo $supermax < $supermin ? '-1' : min(abs($x0 - $supermin), abs($x0 - $supermax));

//fclose($r);


<?php

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

$data = file($src);
//$data = array('aaaaa', '4');

$str = trim(array_shift($data));
$k = $num = (int) array_shift($data);

$cnt = array_count_values(str_split($str));
asort($cnt);

$letters = array();
while ($k > 0 && $cnt) {
	$m = current($cnt);
	if ($k >= $m) {
		$letters[key($cnt)] = true;
		$k -= $m;
		array_shift($cnt);
	} else {
		$k = 0;
	}
}
echo count($cnt) . PHP_EOL;
if (!count($cnt)) {
	exit;
}
$removed = 0;
for ($i = 0; $i < strlen($str); $i++) {
	if (isset($letters[$str{$i}]) && $removed < $num) {
		$removed++;
	} else {
		echo $str{$i};
	}
}

<?php

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

$data = file($src);
//$data = array('aaaaa', '4');

$str = trim(array_shift($data));
$k = $num = (int) array_shift($data);

$cnt = array_count_values(str_split($str));
asort($cnt);

$letters = array();
while ($k > 0 && $cnt) {
	$m = current($cnt);
	if ($k > $m) {
		$letters[key($cnt)] = true;
		$k -= $m;
		array_shift($cnt);
	} else {
		$k = 0;
	}
}
echo count($cnt) . PHP_EOL;
if (!count($cnt)) {
	exit;
}
$removed = 0;
for ($i = 0; $i < strlen($str); $i++) {
	if (isset($letters[$str{$i}]) && $removed < $num) {
		$removed++;
	} else {
		echo $str{$i};
	}
}

<?php

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

$data = file($src);
//$data = array('aaaaa', '4');

$str = trim(array_shift($data));
$k = $num = (int) array_shift($data);

$cnt = array_count_values(str_split($str));
sort($cnt);

$letters = array();
while ($k > 0 && $cnt) {
	$letters[key($cnt)] = true;
	$k -= array_shift($cnt);
}
echo count($cnt) . PHP_EOL;
if (!count($cnt)) {
	exit;
}
$removed = 0;
for ($i = 0; $i < strlen($str); $i++) {
	if (isset($letters[$str{$i}]) && $removed < $num) {
		$removed++;
	} else {
		echo $str{$i};
	}
}

<?php

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

//$data = file($src);
$data = array('aaaaa', '4');

$str = trim(array_shift($data));
$k = $num = (int) array_shift($data);

$cnt = array_count_values(str_split($str));
sort($cnt);

$letters = array();
while ($k > 0 && $cnt) {
	$letters[key($cnt)] = true;
	$k -= array_shift($cnt);
}
echo count($cnt) . PHP_EOL;
if (!count($cnt)) {
	exit;
}
$removed = 0;
for ($i = 0; $i < strlen($str); $i++) {
	if (isset($letters[$str{$i}]) && $removed < $num) {
		$removed++;
	} else {
		echo $str{$i};
	}
}


<?php
$a = max(array_slice(explode(" ", trim(fgets(STDIN))), 1));
$b = max(array_slice(explode(" ", trim(fgets(STDIN))), 1));
$c = min(array_slice(explode(" ", trim(fgets(STDIN))), 1));
list($d, $e) = explode(" ", trim(fgets(STDIN)));
$f = $a * sqrt(($b * $e) / (($b * $e) + ($c * $d)));
$f = number_format($f, 6, ".", "");
print $f;
?>

<?php

error_reporting(0);

solve();

function solve(){

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

	$N = (int)$Input->in();

	$max_x = -1;

	for ($i = 0; $i < $N; $i++)
	{
		$X = (int)$Input->in();
		$max_x = max($max_x, $X);
	}

	$M = (int)$Input->in();

	$max_y = -1;

	for ($i = 0; $i < $M; $i++)
	{
		$Y = (int)$Input->in();
		$max_y = max($max_y, $Y);
	}

	$K = (int)$Input->in();

	$min_z = 5001;

	for ($i = 0; $i < $K; $i++)
	{
		$Z = (int)$Input->in();
		$min_z = min($min_z, $Z);

	}

	$A = (int)$Input->in();
	$B = (int)$Input->in();
	$temp = ($A / $B) * ($min_z / $max_y) + 1;

	print($max_x / sqrt($temp));
}

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

	public function __construct($localfile){

		if (is_file($localfile)) {

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

		} else {

			$contents = stream_get_contents(STDIN);

		}

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

	public function in(){

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

	}

	public function close(){

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

	}
}

?>

<?php

//$stream = fopen( 'input.txt', 'r' );
$stream = STDIN;

// Input data
$data = stream_get_contents( $stream );

$data = str_replace( array( "\r\n", "\n\r", "\r", "\n" ), ' ', $data );

$data = explode( ' ', $data );

$x = array();
$y = array();
$z = array();

$line_counts = array();

$line_counts[0] = (int) $data[0];
$line_counts[1] = (int) $data[ $line_counts[0] + 1 ];
$line_counts[2] = (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 ];

$A =  (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 + $line_counts[2] + 1 ];
$B =  (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 + $line_counts[2] + 2 ];

for( $i = 1; $i <= $line_counts[0]; $i++ ) {
	$x[] = (int) $data[$i];
}

for( $i = $line_counts[0] + 2; $i <= $line_counts[0] + $line_counts[1] + 1; $i++ ) {
	$y[] = (int) $data[$i];
}

for( $i = $line_counts[0] + $line_counts[1] + 3; $i <= $line_counts[0] + $line_counts[1] + $line_counts[2] + 2; $i++ ) {
	$z[] = (int) $data[$i];
}

$r1 = max( $x );
$p1 = max( $y );
$p2 = min( $z );

$r2 = sqrt( 1 / ( ( ( $A / $B ) + ( $p1 / $p2 ) ) / ( ( $p1 * $r1 * $r1 ) / $p2 ) ) );

$r2 = number_format( $r2, 12, '.', '' );

echo $r2;

<?php
$x = explode(' ',trim(fgets(STDIN)),2);
$xa = explode(' ',$x[1]); sort($xa);
$r1 = $xa[count($xa) - 1];

$y = explode(' ',trim(fgets(STDIN)),2);
$ya = explode(' ',$y[1]); sort($ya);
$p1 = $ya[count($ya) - 1];

$z = explode(' ',trim(fgets(STDIN)),2);
$za = explode(' ',$z[1]); sort($za);
$p2 = $za[0];

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

$r2 = sqrt(($p1 * $r1 * $r1) / ($p2 * ($p1 / $p2 + $a / $b)));

print $r2;
?>

<?php

//$stream = fopen( 'input.txt', 'r' );
$stream = STDIN;

// Input data
$data = stream_get_contents( $stream );

$data = str_replace( array( "\r\n", "\n\r", "\r", "\n" ), ' ', $data );

$data = explode( ' ', $data );

$x = array();
$y = array();
$z = array();

$line_counts = array();

$line_counts[0] = (int) $data[0];
$line_counts[1] = (int) $data[ $line_counts[0] + 1 ];
$line_counts[2] = (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 ];

$A =  (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 + $line_counts[2] + 1 ];
$B =  (int) $data[ $line_counts[0] + 1 + $line_counts[1] + 1 + $line_counts[2] + 2 ];

for( $i = 1; $i <= $line_counts[0]; $i++ ) {
	$x[] = (int) $data[$i];
}

for( $i = $line_counts[0] + 2; $i <= $line_counts[0] + $line_counts[1] + 1; $i++ ) {
	$y[] = (int) $data[$i];
}

for( $i = $line_counts[0] + $line_counts[1] + 2; $i <= $line_counts[0] + $line_counts[1] + $line_counts[2] + 2; $i++ ) {
	$z[] = (int) $data[$i];
}

$r1 = max( $x );
$p1 = max( $y );
$p2 = min( $z );

$r2 = sqrt( 1 / ( ( ( $A / $B ) + ( $p1 / $p2 ) ) / ( ( $p1 * $r1 * $r1 ) / $p2 ) ) );

$r2 = number_format( $r2, 12, '.', '' );

echo $r2;


<?php

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

function readInt() {
  return (int) read() ;
}

function readStrs() {
  return explode(" ",read()) ;
}

function readIntArray() {
  return array_map('intval', readStrs());
}

function readAsArray() {
  return str_split(read()) ;
}

function puts($arg) {
  if($arg === true) print_r("true");
  elseif($arg === false) print_r("false");
  else {
    print_r($arg) ;
  }
  print_r("\n") ;
}
//-----------------------------------//

$t = readInt() ;
while($t--) {
	$a = readInt() ;
	if($a === 1) {
		puts(2) ;
	}
	else puts(ceil($a/3)) ;
}

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

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

    $s = 0;
    if ($n == 1) {
        echo 2 . PHP_EOL;
    } else if ($n >= 2 && $n <= 3) {
        echo 1 . PHP_EOL;
    } else {
        if ($n % 3 == 0) {
            $s =  $n / 3;
        } else {
            $s = ($n / 3) + 1;
        }
        echo (int) $s . PHP_EOL;
    }

}


<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    list($sStudent) = explode(' ', trim(fgets(STDIN)));
    $sTest = stristr($sStudent,'A');
    $aTest = [];
    $k = 0;
    for ($i = 0; $i < strlen($sTest);$i++){
        if ($sTest[$i] == 'P'){
            $k++;
        } else {
            $aTest[] = $k;
            $k = 0;
        }
    }
    $aTest[] = $k;
    echo max($aTest)."\n";
}

<?php
$a = trim(fgets(STDIN));
for($j = 0; $j < $a; $j++){
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $counter = 0;
    $max = 0;
    $bool = false;
    for($i = 0; $i < $b; $i++){
        if((isset($c[$i-1]) && $c[$i-1] == 'A')){
            $bool = true;
        }
        if($c[$i] == 'P' && $bool){
           $counter++;
           if($max <= $counter){
                $max = $counter;
            }
        } else {
            if($max <= $counter){
                $max = $counter;
            }
            $counter = 0;
            $bool = false;
        }
    }
    echo $max."\n";
}

<?php

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

for ($j=0;$j<$t;$j++)
{
    $x = trim(fgets($handle));
    $a = trim(fgets($handle));
    $cnt=0;$max=0;$check=false;
    for($i=0;$i<$x;$i++)
    {
     if($a[$i]=='A')
     {
         $check=true;
         if($cnt>$max)$max=$cnt;
         $cnt=0;
     }else if($check==true)
     {
         $cnt++;
     }
    }
    if($cnt>$max)$max=$cnt;
    echo $max."\n";

}

?>

<?php
$a = trim(fgets(STDIN));
for($j = 0; $j < $a; $j++){
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $counter = 0;
    $max = 0;
    $bool = false;
    for($i = 0; $i < $b; $i++){
        if((isset($c[$i-1]) && $c[$i-1] == 'A')){
            $bool = true;
        }
        if($c[$i] == 'P' && $bool){
           $counter++;
           if($max <= $counter){
                $max = $counter;
            }
        } else {
            if($max <= $counter){
                $max = $counter;
            }
            $counter = 0;
            $bool = false;
        }
    }
    if($c[$b-1] == 'A'){
        $max = 0;
    }
    echo $max."\n";
}

<?php
$a = trim(fgets(STDIN));
for($j = 0; $j < $a; $j++){
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $counter = 0;
    $max = 0;
    for($i = 0; $i < $b; $i++){
        if($c[$i] == 'P'){
           $counter++;
           if($max <= $counter){
                $max = $counter;
            }
        } else {
            if($max <= $counter){
                $max = $counter;
            }
            $counter = 0;
        }
    }
    if($c[$b-1] == 'A'){
        $max = 0;
    }
    echo $max."\n";
}

<?php
$a = trim(fgets(STDIN));
for($j = 0; $j < $a; $j++){
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    $counter = 0;
    $max = 0;
    $bool = false;
    for($i = 0; $i < $b; $i++){
        if($c[$i] == 'A' && !$bool){
            $bool = true;
        } elseif ($c[$i] == 'P' && $bool){
           $counter++;
           if($max <= $counter){
                $max = $counter;
            }
        } elseif ($c[$i] == 'A' && $counter > 0) {
            if($max <= $counter){
                $max = $counter;
            }
            $counter = 0;
            $bool = false;
        }
    }
    echo $max."\n";
}

<?php
$a = trim(fgets(STDIN));
for($j = 0; $j < $a; $j++){
    $b = trim(fgets(STDIN));
    $c = str_split(trim(fgets(STDIN)));
    for($i = $b-1; $i >= 0; $i--){
        if($c[$i] == 'A'){
            echo $b - ($i+1)."\n";
            break;
        }
    }
}


<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
$aAllResults = [];
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
    foreach ($aAllResults as $sRes) {
        IO::line($sRes);
    }
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    $res = [];
    for($i = 0; $i < $n - 1; $i++) {
        $res[] = $a[$i] * $a[$i+1];
    }
    IO::line(max($res));

}

?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aInput = explode(' ', trim(fgets(STDIN)));
    $aAnswer = [];
    for ($i = 0; $i < count($aInput) - 1; $i++) {
        $aAnswer[] = $aInput[$i] * $aInput[$i + 1];
    }
    echo max($aAnswer) .  "\n";
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aInput = explode(' ', trim(fgets(STDIN)));
    $iMax = max($aInput);
    $aMaxKey = array_keys($aInput, $iMax);
    $iMin = min($aInput);
    $aAnswer = [];
    foreach ($aMaxKey as $sK => $sV) {
        $iMin1 = 0;
        $iMin2 = 0;
        if (isset($aInput[$sV - 1])) {
            $iMin1 = $aInput[$sV - 1];
        }
        if (isset($aInput[$sV + 1])) {
            $iMin2 = $aInput[$sV + 1];
        }
        $aAnswer[] = $iMax * $iMin1;
        $aAnswer[] = $iMax * $iMin2;
    }
    echo max($aAnswer) .  "\n";
}


<?php
error_reporting(0);

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

	$N = (int)$Scanner->Scan();
	$K = (int)$Scanner->Scan();
	for ($i = 0; $i < $N; $i++) {
		$TEAMS[$i][] = (int)$Scanner->Scan();
		$TEAMS[$i][] = 100 - (int)$Scanner->Scan();
	}

	rsort($TEAMS);

	$num = $TEAMS[$K - 1][0];
	$time = $TEAMS[$K - 1][1];
	$count = 0;
	for ($i = 0; $i < $N; $i++) {
		if ($TEAMS[$i][0] === $num && $TEAMS[$i][1] === $time)$count++;

		if ($count > 0 && ($TEAMS[$i][0] !== $num || $TEAMS[$i][1] !== $time)) break;	}
	print($count);
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

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

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

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

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

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>

<?php

$stdin = fopen("php://stdin", "r");
//$stdin = fopen("in.txt", "r");

$line = explode(" ", trim(fgets($stdin)));
$n = $line[0];
$k = $line[1];

$groups = array();

for($i = 0; $i < $n; $i++) {
    $lines = explode(" ", trim(fgets($stdin)));
    $groups[$i]["tasks"] = $lines[0];
    $groups[$i]["minuses"] = $lines[1];
}

rsort($groups);

for($i = 0; $i < $n; $i++) {
    for($j = $i+1; $j < $n; $j++) {
        if($groups[$j]["tasks"] < $groups[$i]["tasks"])break;

        if($groups[$i]["minuses"] > $groups[$j]["minuses"]) {
            $tmp = $groups[$j];
            $groups[$j] = $groups[$i];
            $groups[$i] = $tmp;
        }
    }
}

//for($i = 0; $i < $n; $i++) {
//    echo $groups[$i]["tasks"]. " " . $groups[$i]["minuses"]."<br>";
//}

$resTasks = $groups[$k-1]["tasks"];
$resMinuses = $groups[$k-1]["minuses"];

$result = 0;
for($i = 0; $i < $n; $i++) {
    if($groups[$i]["tasks"] == $resTasks && $groups[$i]["minuses"] == $resMinuses)
        $result++;
}

echo $result;

//file_put_contents("out.txt", $result);
?>

<?php
error_reporting(0);

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

	$N = (int)$Scanner->Scan();
	$K = (int)$Scanner->Scan();
	for ($i = 0; $i < $N; $i++) {
		$TEAMS[$i][] = (int)$Scanner->Scan();
		$TEAMS[$i][] = 100 - (int)$Scanner->Scan();
	}

	rsort($TEAMS);

	$num = $TEAMS[$K - 1][0];
	$time = $TEAMS[$K - 1][1];
	$count = 0;
	for ($i = 0; $i < $N; $i++) {
		if ($TEAMS[$i][0] === $num && $TEAMS[$i][1] === $time)$count++;

		if ($count > 0 && ($TEAMS[$i][0] !== $num || $TEAMS[$i][1] !== $time)) break;	}
	print($count);
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

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

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

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

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

class Token{
	private $token;
	private $tok;

	public function __construct($str_line, $tok) {
		$this->tok = $tok;
		$this->token = strtok($str_line, $this->tok);
	}

	public function nextToken() {
		$thisToken = $this->token;
		$this->token = strtok($this->tok);
		return $thisToken;
	}

	public function nextFloat() {
		return (float)$this->nextToken();
	}

  	public function nextInt() {
		return (int)$this->nextToken();
	}

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

function array_printf(array $array) {
		$message = "";
		foreach ($array as $value) {
			$message .= "$value" . " ";
		}
		$message = rtrim($message);
		printf('%s', $message);
}

== function end ======
*/

?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array();
for($x = 1; $x <= $a; $x++)
{
    list($d, $e) = explode(" ", trim(fgets(STDIN)));
    if($e <= $b)
    {
        array_push($c, $d);
    }
    else
    {
        $f = $d - ($e - $b);
        array_push($c, $f);
    }
}
rsort($c);
print $c[0];
?>

<?php
error_reporting(0);
class stdIn{var $ntxt = 0;var $nline = 0;var $arr_txt;var $arr_line;var $linex;var $liney;
function stdIn($local = false){if($local){$dir = fopen("input.txt", 'r');}else{$dir = fopen("php://stdin", 'r');}
$datatxt = stream_get_contents($dir);$del = Array("\n","\r","\n\r");$data = explode("\n",$datatxt);	$il = 0;$id = 0;
foreach($data as $line){if(strlen($line) > 0){$line = str_replace($del,'',$line);$dataex[] = $line;$text = explode(" ",$line);
foreach($text as $txt){$arr_txt[] = $txt;$this->linex[$id] = $il;$this->liney[$il] = $id;$id++;}}$il++;}$this->arr_line = $dataex;$this->arr_txt  = $arr_txt;}
function G(){$ret = $this->arr_txt[$this->ntxt++];$this->nline = $this->linex[$this->ntxt];return $ret;}
function GL(){$this->ntxt = $this->liney[$this->nline]+1;return $this->arr_line[$this->nline++];}}
/*init*/ $dxs = new stdIn(false);
// $x = $dxs-> G(); equivalent to cin>>x;
$n=$dxs->G();
$k=$dxs->G();
$max=-10000000000000000000000000000000;
for ($i = 0; $i < $n; $i++) {
	$j=0;
	$f=$dxs->G();
	$t=$dxs->G();
	if($t>$k){$f=$f-($t-$k);}
	//echo $f;
	//echo $max;
	if($f>$max){
		$max=$f;
	}
}
echo $max;
?>

<?// BismiLahi Rahmani Rahim ?>

<?php

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

for ($i = 0; $i < $n; $i ++) {
	fscanf(STDIN, "%d %d", $f, $t);
	if ($t > $k) {
		$max = isset($max) ? max($max, $f - ($t - $k)) : $f - ($t - $k);
	} else {
		$max = isset($max) ? max($max, $f) : $f;
	}
}

printf("%d", $max);

?>


<?php
    $q = trim(fgets(STDIN));
    for ($i = 0; $i < $q; $i++) {
        list($n, $k) = explode(" ", trim(fgets(STDIN)));
        $a = explode(" ", trim(fgets(STDIN)));
        $max = max($a);
        $min = min($a);
        if ($min + $k >= $max - $k) {
            echo $min + $k . "\n";
        } else {
            echo "-1" . "\n";
        }
    }
?>

<?
$stdin = fopen('php://stdin', 'r');
ini_set('display_errors', '1');
function read() {
    return trim(fgets(STDIN));
}
$t1 = microtime(true);
$debag = 0;
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
$q = read(); // кол-во запросов
$arr = []; // n и k
$data = []; // числа
$resp = [];
for ($i = 0; $i < $q; $i++) {
    $arr[$i] = explode(" ", read());
    $data[$i] = explode(" ", read());
}
/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/

for ($i = 0; $i < $q; $i++) {
    $min = min($data[$i]);
    $max = max($data[$i]);

    if ($min+$arr[$i][1] >= $max-$arr[$i][1]) {
        $resp[$i] = $min+$arr[$i][1];
    } else {
        $resp[$i] = -1;
    }
}
for ($i = 0; $i < $q; $i++) {
    echo $resp[$i]."\n";
}

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
if ($debag === 1) {
    echo '<hr>' . round(microtime(true) - $t1, 3) . ' sec';
}

<?php
    $n = trim(fgets(STDIN));
    $res = array();
    for($i = 0; $i<$n; $i++){
        $a = explode(" ", trim(fgets(STDIN)));
        $b = explode(" ", trim(fgets(STDIN)));
        $max = max($b);
        $min = min($b);
        if($min + $a[1] >= $max - $a[1]){
            $res[] = $min + $a[1];
        } else {
            $res[] = -1;
        }
    }
    foreach($res as $v){
        echo $v."\n";
    }

 ?>

<?php
    $Q = intval(fgets(STDIN));
    while (0 < $Q--) {
        list($n,$k) = array_map('intval', preg_split('/\s+/', trim(fgets(STDIN))));
        $a = array_map('intval', preg_split('/\s+/', trim(fgets(STDIN))));
        $max = min(array_map(function($ai)use($k){ return $ai+$k; },$a));
        $min = max(array_map(function($ai)use($k){ return $ai-$k; },$a));
        echo $min<=$max ? $max : -1;
        echo "\n";
    }

<?php
    $q = trim(fgets(STDIN));
    for ($i = 0; $i < $q; $i++) {
        list($n, $k) = explode(" ", trim(fgets(STDIN)));
        $a = explode(" ", trim(fgets(STDIN)));
        $u = array_unique($a);
        //print_r($u);
        $max = max($a);
        $min = min($a);
        sort($u);
        $r = '-1';
        $b = [];
        foreach ($u AS $v) {
            if ($max - $v <= $k && $v - $min <= $k) {
                $r = $v;
                $b[] = $v;
            }
        }
        if (isset($b) && count($b) == count($u)) {
            echo $min + $k  . "\n";
        } else {
            echo $r . "\n";
        }
    }
?>

<?php
    $q = trim(fgets(STDIN));
    for ($i = 0; $i < $q; $i++) {
        list($n, $k) = explode(" ", trim(fgets(STDIN)));
        $a = explode(" ", trim(fgets(STDIN)));
        $u = array_unique($a);
        //print_r($u);
        $max = max($a);
        $min = min($a);
        sort($u);
        $r = '-1';
        foreach ($u AS $v) {
            if ($max - $v <= $k && $v - $min <= $k) {
                $r = $v;
            }
        }
        echo $r . "\n";
    }
?>


<?php

$input;
$buffer = Array();
init();

function getNext() {
  global $buffer;
  if( count($buffer) > 0 ) {
    return array_shift($buffer);
  }
  $line = preg_replace('/[\\r\\n]+$/', '', getLine());
  $buffer = preg_split('/\\s+/', $line);
  return getNext();
}

function getLine() {
  global $input;
  return fgets($input, 4096);
}

function init() {
  global $input;
  $input = fopen("php://stdin", "r");
}

function main() {

  $a = intval(getNext());
  $b = intval(getNext());

  $n = intval(getNext());

  $max = abs($b);

  for( $i = -$max; $i <= $max; ++$i ) {
    $cur = $a;
    for( $j = 0; $j < $n; ++ $j ) {
      $cur *= $i;
      if( abs($cur) > $max ) { break; }
    }
    if( $cur == $b ) {
      print $i . "\n";
      return;
    }
  }

  print "No solution\n";

}

main();

?>


<?php

function equalizeStrings($str1, $str2) {
    if (strlen($str1) > strlen($str2)) {
        $tmp = $str2;
        $str2 = $str1;
        $str1 = $tmp;
    }

    $str1_len = strlen($str1);
    $str2_len = strlen($str2);

    for ($part_len = $str1_len; $part_len > 0; $part_len--) {
        for ($i = 0; $i <= $str1_len - $part_len; $i++) {
            $part = substr($str1, $i, $part_len);
            if (false !== strpos($str2, $part)) {
                return $str1_len + $str2_len - 2 * $part_len;
            }
        }
    }

    return $str1_len + $str2_len;
}

$t = readline();

for ($i = 0; $i < $t; $i++) {
    $str1 = readline();
    $str2 = readline();
    echo equalizeStrings($str1, $str2) . PHP_EOL;
}

<?php
$t = readline();

for ($i = 0; $i < $t; $i++) {
    $str1 = readline();
    $str2 = readline();
    echo equalizeStrings($str1, $str2) . PHP_EOL;
}

function equalizeStrings($string1, $string2) {
if(strlen($string1) >= strlen($string2)){
    $shortStr = $string2;
    $shortStrLen = strlen($string2);
    $longStr = $string1;
    $longStrLen = strlen($string1);
}
else{
    $shortStr = $string1;
    $shortStrLen = strlen($string1);
    $longStr = $string2;
    $longStrLen = strlen($string2);
}
//----------------------------------------
//echo $longStr."
".$shortStr."

";
//---------------------------------------

$maxSubLen = 0;
for($i = 0; $i < $shortStrLen; $i++){
    $subStr = substr($shortStr, $i, 1);
    if(strpos($longStr, $subStr) !== false){
        $len = 2;
        while(strpos($longStr, $subStr) !== false){
            //
            if($len > $shortStrLen + 1 || ($i-1 + $len) > $shortStrLen)
                break;
            $subStr = substr($shortStr, $i, $len);
            $len++;
        }
        if($len - 2 > $maxSubLen){
            $maxSubLen = $len -2;
        }
    }
    else{
        continue;
    }
}

$res = ($shortStrLen - $maxSubLen) + ($longStrLen - $maxSubLen);
echo $res.PHP_EOL;
}

<?php

# asdasd
# asa sd

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = str_split(IO::str());
    $res = [];
   for ($i = 0; $i < count($a); $i++) {
       for($j = 0; $j < count($b); $j++) {
           $k = $j;
           $len = 0;
           if($a[$i] == $b[$j]) {
               for($x = $i; $x < count($a); $x++) {
                   if(!isset($b[$k])) {
                       break;
                   }
                   if ($a[$x] == $b[$k]) {
                       $len++;
                       $k++;
                   } else {
                       break;
                   }
               }
           }
           $res[$len] = $len;
       }
   }
   $len = max($res);
   $result = (count($a) - $len) + (count($b) - $len);
    IO::line($result);
}

?>

<?php

# asdasd
# asa sd

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = str_split(IO::str());
    $res = [];
   for ($i = 0; $i < count($a); $i++) {
       $len = 0;
       $k = $i;
       $rj = 0;
       for($j = 0; $j < count($b); $j++) {
           if($a[$k] == $b[$j]) {
               if($len == 0) {
                   $rj = $j;
               }
               $len++;
               $k++;
           } else {
               $res[$len] = $len;
               $len = 0;
               $k = $i;
               if ($len > 0) {
                   $j = $rj;
               }
           }
       }
       $res[$len] = $len;
   }
   $len = max($res);
   $result = (count($a) - $len) + (count($b) - $len);
    IO::line($result);
}

?>

<?php

# asdasd
# asa sd

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = str_split(IO::str());
    $res = [];
   for ($i = 0; $i < count($a); $i++) {
       $len = 0;
       $k = $i;
       $rj = 0;
       for($j = 0; $j < count($b); $j++) {
           if($a[$k] == $b[$j]) {
               $len++;
               $k++;
           } else {
               $res[$len] = $len;
               $len = 0;
               $k = $i;
           }
       }
       $res[$len] = $len;
   }
   $len = max($res);
   $result = (count($a) - $len) + (count($b) - $len);
    IO::line($result);
}

?>

<?php

# asdasd
# asa sd

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = str_split(IO::str());
    $res = [];
   for ($i = 0; $i < count($a); $i++) {
       $len = 0;
       $k = $i;
       for($j = 0; $j < count($b); $j++) {
           if($a[$k] == $b[$j]) {
               $len++;
               $k++;
           } elseif ($len > 0) {
               $res[$len] = $len;
               $len = 0;
               $k = $i;
           }
       }
       $res[$len] = $len;
   }
   $len = max($res);
   $result = (count($a) - $len) + (count($b) - $len);
    IO::line($result);

}

?>

<?php

# asdasd
# asa sd

class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $b = str_split(IO::str());
    $res = [];
   for ($i = 0; $i < count($a); $i++) {
       $len = 0;
       $k = $i;
       for($j = 0; $j < count($b); $j++) {
           if($a[$k] == $b[$j]) {
               $len++;
               $k++;
           } elseif ($len > 0) {
               break;
           }
       }
       $res[] = $len;
   }
   $len = max($res);
   $result = (count($a) - $len) + (count($b) - $len);
    IO::line($result);

}

?>


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

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

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

        $R = 1 / sin(M_PI / (2 * $n)) ;

        $angle = ($n - 1) * M_PI / $n ;
        $ans = 0.0 ;

        for($i = 2; $i < $n; $i ++)
        {
            $x =  (($i - 1) * M_PI - $angle * ($i - 1)) / 2 ;

            $x = M_PI / 4 - $x ;

            $ans = max($ans, $R * cos($x) ) ;
        }
        echo $ans . "\n" ;
    }
?>

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

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

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

        $R = 1 / sin(M_PI / (2 * $n)) ;

        $angle = ($n - 1) / $n ;
        $ans = 0.0 ;

        for($i = 2; $i < $n; $i ++)
        {
            $x =  (($i - 1) - $angle * ($i - 1)) / 2 ;

            $x = 0.25 - $x ;

            $ans = max($ans, $R * cos($x * M_PI) ) ;
        }
        echo $ans . "\n" ;
    }
?>


<?php
  //CF 892B
  fscanf(STDIN, "%d", $n);
  $l = explode(" ", fgets(STDIN));
  $ans = 0;
  $cmp = $n;
  for ($i = $n - 1; $i >= 0; $i--) {
    if ($i < $cmp) $ans++;
    $cmp = min($cmp, $i - intval($l[$i]));
  }
  fprintf(STDOUT, "" . $ans);
?>


<?php
# 1154D
$input = fopen('php://stdin', 'rb');
[$stepsCount, $batteryCharge, $accumChargeMax] = explode(' ', fgets($input));
$resultSteps = 0;
$accumCharge = (int)$accumChargeMax;
for ($i = 0; $i < $stepsCount; $i++) {
    if ($accumCharge === 0 && $batteryCharge === 0) {
        break;
    }
    $shining = fgetc($input) === '1';
    fgetc($input);
    if ($shining) {
        if ($accumCharge < $accumChargeMax && $batteryCharge > 0) {
            $accumCharge++;
            $batteryCharge--;
        } else {
            $accumCharge--;
        }
    } elseif($accumCharge > 0) {
        $accumCharge--;
    } else {
        $batteryCharge--;
    }
    $resultSteps++;
}
echo $resultSteps;

<?php
# 1154D
$input = fopen('php://stdin', 'rb');
[$stepsCount, $batteryCharge, $accumChargeMax] = explode(' ', fgets($input));
$resultSteps = 0;
$accumCharge = (int)$accumChargeMax;
for ($i = 0; $i < $stepsCount; $i++) {
    #echo "Battery: {$batteryCharge}, Accum: {$accumCharge}" . PHP_EOL;
    if ($accumCharge === 0 && $batteryCharge === 0) {
        echo $resultSteps;
        break;
    }
    $shining = (bool)fgetc($input);
    fgetc($input);
    if ($shining) {
        if ($accumCharge < $accumChargeMax && $batteryCharge > 0) {
            $accumCharge++;
            $batteryCharge--;
        } else {
            $accumCharge--;
        }
    } elseif($accumCharge > 0) {
        $accumCharge--;
    } else {
        $batteryCharge--;
    }
    $resultSteps++;
}

<?php
# 1154D
$input = fopen('php://stdin', 'rb');
[$stepsCount, $batteryCharge, $accumChargeMax] = explode(' ', fgets($input));
$resultSteps = 0;
$accumCharge = (int)$accumChargeMax;
for ($i = 0; $i < $stepsCount; $i++) {
    $shining = fgetc($input) === '1';
    fgetc($input);
    if ($shining) {
        if ($accumCharge < $accumChargeMax && $batteryCharge > 0) {
            $accumCharge++;
            $batteryCharge--;
        } else {
            $accumCharge--;
        }
    } elseif($accumCharge > 0) {
        $accumCharge--;
    } else {
        $batteryCharge--;
    }
    $resultSteps++;
    if ($accumCharge === 0 && $batteryCharge === 0) {
        echo $resultSteps;
        break;
    }
}


<?php

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$steps = $arr[1];
//$steps = '..LL...';
$left = strpos($steps, 'L');
$right = strpos($steps, 'R');

if($left && $right){
    $right++;
}

if($left == false){
    $left = strlen($steps) - strpos(strrev($steps), 'R') + 1;
    $right++;
}
if($right == false){
    $right = strlen($steps) - strpos(strrev($steps), 'L');
}
echo $right, ' ', $left;

<?php
// Is local test?
$LOCALTEST = false;

// Retrieve input
if ($LOCALTEST) {
	$stdin = fopen('test.txt', 'r');
} else {
	$stdin = fopen('php://stdin', 'r');
}
function g() {
	global $stdin;
	return explode(" ", trim(fgets($stdin)));
}

// Codeforces Contest 180 Div 2 Problem A
$raw = g();
$n = $raw[0];
$raw = g();
for ($i = 0; $i < $n; $i++) {
	$chr[$i] = substr($raw[0], $i, 1);
}

$met = false;
$start = 0;
$end = 0;
for ($i = 0; $i < $n; $i++) {
	if (($met !== false) && ($chr[$i] != $met) && (($start == 0) || ($end == 0))) {
		if ($met == "L") {$start = $i;} else {$end = $i+1;}
	}
	if (($met === false) && ($chr[$i] != ".")) {
		$met = $chr[$i];
		if ($met == "R") {$start = $i+1;} else {$end = $i;}
	}
}

echo $start . " " . $end;

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

$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$steps = $arr[1];
//$steps = '.RRRLLLLL..';
$left = strpos($steps, 'L');
$right = strpos($steps, 'R');

if($left && $right){
    $right++;
}

if($left == false){
    $left = strlen($steps) - strpos(strrev($steps), 'R') + 1;
}
if($right == false){
    $right = strlen($steps) - strpos(strrev($steps), 'L');
}
echo $right, ' ', $left;

<?php
$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$steps = $arr[1];
//$steps = '..RRLL...';
$left = strpos($steps, 'L');
$right = strpos($steps, 'R');

if($left && $right){
    $right++;
}

if($left == false){
    $left = strlen($steps) - strpos(strrev($steps), 'R') + 1;
}
if($right == false){
    $right = strlen($steps) - strpos(strrev($steps), 'L');
}
echo $right, ' ', $left;


<?php
$start = microtime(1);
$n = trim(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));
$maxV = max($a);
$maxI = array_search($maxV, $a, true);
for ($i = 0; $i < $maxI; $i++) {
    if ($a[$i] >= $a[$i + 1]) {
        die('NO');
    }
}
for ($i = $n - 1; $i > $maxI; $i--) {
    if ($a[$i] >= $a[$i - 1]) {
        die('NO');
    }
}
echo 'YES';

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
$aArray = explode(' ', trim(fgets(STDIN)));
$iMax = max($aArray);
$iMaxIndex = array_keys($aArray, max($aArray));
$bFlag = true;
for($i = $iMaxIndex[0]; $i < count($aArray) - 1; $i++){
    if($aArray[$i] < $aArray[$i + 1]){
        $bFlag = false;
    }
}
for ($i = $iMaxIndex[0]; $i >= 1; $i--){
    if($aArray[$i - 1] >= $aArray[$i]){
        $bFlag = false;
    }
}

if($bFlag){
    echo "YES"."\n";
} else {
    echo "NO" . "\n";
}

<?php
    $n = trim(fgets(STDIN));
    $m = explode(" ", trim(fgets(STDIN)));
    $max = max($m);
    $key = array_search($max, $m);
    for($i = $key; $i >= 1; $i--){
        if($m[$i] <= $m[$i - 1]){
            echo 'NO';
            exit;
        }
    }
    $key = array_search($max, $m);
    for($j = $key; $j < $n-1; $j++){
        if($m[$j] < $m[$j + 1]){
            echo 'NO';
            exit;
        }
    }
    echo 'YES';

 ?>


<?php

$n = trim(fgets(STDIN));

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

sort($arSearch);
$summ = array_sum($arSearch);

if ($summ%2 == 0)
    printf("%.0f",$summ);
else
{
    foreach ($arSearch as $val)
    {

        $asw = $summ - $val;
        if ($asw%2 == 0)
        {
            printf("%.0f",$asw);
            die();
        }
    }
    echo "0";
}

<?php
$n = (int)fgets(STDIN);
$a = explode(" ", trim(fgets(STDIN)));
sort($a);
$sum = "0";
foreach ($a as $n) {
  $sum = bcadd($sum, $n);
}
if (bcmod($sum, 2)) {
  foreach ($a as $n) {
    if ($n % 2) {
      $sum = bcsub($sum, $n);
      break;
    }
  }
}

echo "$sum\n";

<?php
$n = trim(fgets(STDIN));
$arr = explode(" ", trim(fgets(STDIN)));
sort($arr);

$k = array_sum($arr);
$i = 0;
while($k%2 != 0) {
    if($arr[$i]%2 != 0)
        $k -= $arr[$i];
    $i++;
}
echo $k;
?>

<?php
$n = trim(fgets(STDIN));
$arr = explode(" ", trim(fgets(STDIN)));
sort($arr);

$i = 0;
$k = array_sum($arr);
while($k%2 != 0) {
    $k -= $arr[$i];
    $i++;
}
echo $k;
?>

<?php

$n = trim(fgets(STDIN));

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

sort($arSearch);
$summ = array_sum($arSearch);

if ($summ%2 == 0) printf("%.0f",$summ);
else
{
    foreach ($arSearch as $val)
    {
        $asw = $summ - $val;
        if ($asw%2 == 0) printf("%.0f",$asw);
            die();
    }
    echo 0;
}

<?php

$n = trim(fgets(STDIN));

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

sort($arSearch);
$summ = array_sum($arSearch);

if ($summ%2 == 0) echo round($summ);
else
{
    foreach ($arSearch as $val)
    {
        $asw = $summ - $val;
        if ($asw%2 == 0) echo round($asw);
            die();
    }
    echo 0;
}

<?php

$n = trim(fgets(STDIN));

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

sort($arSearch);
$summ = array_sum($arSearch);

if ($summ%2 == 0) echo $summ;
else
{
    foreach ($arSearch as $val)
    {
        $asw = $summ - $val;
        if ($asw%2 == 0) echo $asw;
            die();
    }
    echo 0;
}


<?php
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
       $ans = [];
       $n = InOutPut::get();

       $n2 = round($n/3);
       $n3 = $n2 - 1;
       $n1 = $n - $n2 - $n3;

       if($n1 == $n2){
       	$n3 -= 1;
       	$n1 = $n1 + 1;
       }
       $ans = $n2 . " " . $n1 . " " . $n3;

       	InOutPut::print($ans);
}
class InOutPut {
      public static function get()
      {
          return trim(fgets(STDIN));
      }

     public static function getArr()
     {
         return explode(' ', trim(fgets(STDIN)));
     }
     public static function print($string)
     {
      echo $string . "\n";
     }
 }
 ?>

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

 $loop = true;
 $t = $loop ? IO::getInt() : 1;
 while($t--) {
      solve();
 }

 function solve()
 {
     $n = IO::getInt();

     $ans = [];
     $h1 = $h1 = $h3 = 0;

     $h2 = round($n/3);
     $h3 = $h2-1;
     $h1 = $n-$h2-$h3;

     if($h2==$h1) {
          $h3 -=1;
          $h1 +=1;
     }

      IO::pr("$h2 $h1 $h3");

 }

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

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

 class Algor {
     public static function efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}

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

 $loop = true;
 $t = $loop ? IO::getInt() : 1;
 while($t--) {
      solve();
 }

 function solve()
 {
     $n = IO::getInt();

     $ans = [];
     $h1 = $h1 = $h3 = 0;

     if(($n-1)%2 == 0) {
          $h3 = 2;
     } else {
          $h3 = 1;
     }
     $h2 = floor(($n-$h3)/2);
     if($h2 == $h3) {
          if($h3 == 2) {
               $h3 = $h3 - 1;
          }
     }
          $h1 = $n - $h3 - $h2;

      IO::pr("$h2 $h1 $h3");

 }

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

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

 class Algor {
     public static function efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}

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

 $loop = true;
 $t = $loop ? IO::getInt() : 1;
 while($t--) {
      solve();
 }

 function solve()
 {
     $n = IO::getInt();

     $ans = [];
     $h1 = $h1 = $h3 = 0;

     if(($n-1)%2 == 0) {
          $h3 = 2;
     } else {
          $h3 = 1;
     }
     $h2 = floor(($n-1)/2);
          $h1 = $n - $h3 - $h2;

      IO::pr("$h1 $h2 $h3");

 }

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

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

 class Algor {
     public static function efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
       $ans = [];
       $n = InOutPut::get();

       $n2 = floor($n/3);
       $n3 = $n2 - 1;
       $n1 = $n - $n2 - $n3;

       if($n1 == $n2){
       	$n3 = $n3 - 1;
       	$n1 = $n1 + 1;
       }
       $ans = $n2 . " " . $n1 . " " . $n3;

       	InOutPut::print($ans);
}
class InOutPut {
      public static function get()
      {
          return trim(fgets(STDIN));
      }

     public static function getArr()
     {
         return explode(' ', trim(fgets(STDIN)));
     }
     public static function print($string)
     {
      echo $string . "\n";
     }
 }
 ?>


<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = str_split(IO::str());
    $d = array_reverse($a);
    $t = $m = 0;
    $bool = true;
    foreach ($a as $v) {
        if ($v == 'T') {
            $t++;
        } else {
            $m++;
        }
        if ($m > $t) {
            $bool = false;
            break;
        }
    }
    if ($bool) {
        $t = $m = 0;
        foreach ($d as $v) {
            if ($v == 'T') {
                $t++;
            } else {
                $m++;
            }
            if ($m > $t) {
                $bool = false;
                break;
            }
        }
    }

    if ($m * 2 == $t && $bool) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>

<?php

$map = [];
fscanf(STDIN, "%d", $n);

for ($i = 0; $i < $n; ++$i) {
    fscanf(STDIN, "%d", $l);
    $s = trim(fgets(STDIN));

    $can = true;
    $m = 0;

    $left = 0;
    $len = strlen($s);

    for ($j = 0; $j < $len; ++$j) {
        if ($s[$j] === 'T') {
            $left++;
        } else {
            $left--;
            $m++;
        }

        if ($left < 0) {
            $can = false;
        }
    }

    $right = 0;
    for ($j = $len-1; $j >= 0; --$j) {
        if ($s[$j] === 'T') {
            $right++;
        } else {
            $right--;
        }

        if ($right < 0) {
            $can = false;
        }
    }

    if($m !== $len / 3){
        $can = false;
    }

    if ($can) {
        echo 'YES' . PHP_EOL;
    } else {
        echo 'NO' . PHP_EOL;
    }
}

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

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

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));

  $str = trim(fgets($file));
  $e = str_split($str);

  if ($str[0] == 'M') { echo 'NO'.PHP_EOL; }
  else {
    if ($str[$n - 1] == 'M') { echo 'NO'.PHP_EOL; }
    else {
      $g = $n / 3;
      $a = array_count_values($e);
      if ($a['M'] != $g && $a['T'] != $g * 2) { echo 'NO'.PHP_EOL; }
      else {
        $tt = 0; $mm = 0; $f = 0;
        for ($j = 0; $j < $n; $j++) {
          if ($str[$j] == 'T') { $tt++; }
          if ($str[$j] == 'M') {
            $mm++;
            if ($tt < $mm) { $f = 1; break; }
          }
        }

        if ($f != 1) {
          $str = strrev($str);
          $tt = 0; $mm = 0; $f = 0;
          for ($j = 0; $j < $n; $j++) {
            if ($str[$j] == 'T') { $tt++; }
            if ($str[$j] == 'M') {
              $mm++;
              if ($tt < $mm) { $f = 1; break; }
            }
          }

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

        } else { echo 'NO'.PHP_EOL; }
      }
    }
  }
}

?>

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

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

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));

  $str = trim(fgets($file));
  $e = str_split($str);

  if ($str[0] == 'M') { echo 'NO'.PHP_EOL; }
  else {
    if ($str[$n - 1] == 'M') { echo 'NO'.PHP_EOL; }
    else {
      $g = $n / 3;
      $a = array_count_values($e);
      if ($a['M'] != $g && $a['T'] != $g * 2) { echo 'NO'.PHP_EOL; }
      else {
        $tt = 0; $mm = 0; $f = 0;
        for ($j = 0; $j < $n; $j++) {
          if ($str[$j] == 'T') { $tt++; }
          if ($str[$j] == 'M') {
            $mm++;
            if ($tt < $mm) { $f = 1; break; }
          }
        }

        if ($f != 1) {
          $str1 = strrev($str);
          $tt = 0; $mm = 0; $f = 0;
          for ($j = 0; $j < $n; $j++) {
            if ($str[$j] == 'T') { $tt++; }
            if ($str[$j] == 'M') {
              $mm++;
              if ($tt < $mm) { $f = 1; break; }
            }
          }

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

        } else { echo 'NO'.PHP_EOL; }
      }
    }
  }
}

?>

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

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

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));

  $str = trim(fgets($file));
  $e = str_split($str);

  if ($str[0] == 'M') { echo 'NO'.PHP_EOL; }
  else {
    if ($str[$n - 1] == 'M') { echo 'NO'.PHP_EOL; }
    else {
      $g = $n / 3;
      $a = array_count_values($e);
      if ($a['M'] != $g && $a['T'] != $g * 2) { echo 'NO'.PHP_EOL; }
      else {
        $tt = 0; $mm = 0; $f = 0;
        for ($j = 0; $j < $n; $j++) {
          if ($str[$j] == 'T') { $tt++; }
          if ($str[$j] == 'M') {
            $mm++;
            if ($tt < $mm) { $f = 1; break; }
          }
        }
      if ($f != 1) { echo 'YES'.PHP_EOL; }
      else { echo 'NO'.PHP_EOL; }
      }
    }
  }
}

?>

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

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

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));

  $str = trim(fgets($file));
  $e = str_split($str);

  if ($str[0] == 'M') { echo 'NO'.PHP_EOL; }
  else {
    if ($str[$n - 1] == 'M') { echo 'NO'.PHP_EOL; }
    else {
      $g = $n / 3;
      $a = array_count_values($e);
      if ($a['M'] != $g && $a['T'] != $g * 2) { echo 'NO'.PHP_EOL; }
      else {
        echo 'YES'.PHP_EOL;
      }
    }
  }
}

?>

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

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

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));

  $str = trim(fgets($file));
  $e = str_split($str);

  if ($str[0] == 'M') { echo 'NO'.PHP_EOL; }
  else {
    if ($str[$n - 1] == 'M') { echo 'NO'.PHP_EOL; }
    else {
      $g = $n / 3;
      $a = array_count_values($e);
      if ($a['M'] != $g) { echo 'NO'.PHP_EOL; }
      else {
        for ($j = 0; $j < $g; $j++) {
          $pos = strpos('T', $str);
          $str = substr_replace($str, '', $pos, $pos + 1);

          $pos = strpos('M', $str);
          $str = substr_replace($str, '', $pos, $pos + 1);
        }

        $s = '';
        for ($j = 0; $j < $g; $j++) { $s .= 'T'; }

        if ($str == $s) { echo 'YES'.PHP_EOL; }
        else { echo 'NO'.PHP_EOL; }
      }
    }
  }
}

?>

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = str_split(IO::str());
    $t = $m = 0;
    $bool = true;
    foreach ($a as $v) {
        if ($v == 'T') {
            $t++;
        } else {
            $m++;
        }
        if ($m > $t) {
            $bool = false;
            break;
        }
    }
    if ($m * 2 == $t && $bool) {
        IO::yes();
    } else {
        IO::no();
    }

}

?>


<?PHP
$putdata = fopen("php://stdin", "r");
$data = fread($putdata, 500000);
fclose($putdata);
$tr = fopen('php://output', 'w');

$a = explode("\n",$data);
$n = intval($a[0]);
$sts = explode(' ',$a[1]);
$a[2] = explode(' ',$a[2]);
$st1 = intval($a[2][0]);
$st2 = intval($a[2][1]);
if($st1==$st2){fputs($tr,0); die();}
if($st1>$st2){$st1=intval($a[2][1]);$st2=intval($a[2][0]);}
$way=0;
$allway=0;
for($i=0;$i<$n;$i++){$allway += $sts[$i];}
for ($i=$st1-1;$i<($st2-1);$i++){
    $way+=$sts[$i];
}
$backway=$allway-$way;
if($backway>$way){$ans=$way;}else{$ans=$backway;}

fputs($tr,$ans);

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
list($c, $d) = explode(" ", trim(fgets(STDIN)));
$g = 0;
$h = 0;
if($c == $d)
{
    print "0";
}
else
{
    $e = min($c, $d) - 1;
    $f = max($c, $d) - 2;
    for($x = $e; $x <= $f; $x++)
    {
        $g += $b[$x];
    }
    $h = array_slice($b, $e, $f - $e + 1);
    $i = array_sum($h);
    $j = array_sum($b) - $i;
    print min($g, $j);
}
?>

<?
$putdata = fopen("php://stdin", "r");
$data = fread($putdata, 300000);
fclose($putdata);
$data = explode("\n",$data); //Каждая строка
$data2=explode(" ",$data[1]); //Растояние между каждой станцией
$st=explode(" ",$data[2]); //Искомы естанции st[0] - 1; st[2] - 2

$kol=(int)$data[0];

$st1=(int)$st[0];
$st2=(int)$st[1];

if((int)$st[0]==(int)$st[1]){
$otvet=0;
}else{

$st1=(int)$st[0];
$st2=(int)$st[1];

while(1){
    if($st1==$st2){ break;}//Если дошли до станции

    if($st1==$kol){
    $s=$st1;
    $st1=0;
    $sum1=$sum1+$data2[$s-1];
    }else{
    $sum1=$sum1+$data2[$st1-1];
    }

    $st1++;
}

$st1=(int)$st[0];
$st2=(int)$st[1];
$s=0;
while(1){
    if($st1==$st2){ break;}//Если дошли до станции

    if($st2==$kol){
    $s=$st2;
    $st2=0;
    $sum2=$sum2+$data2[$s-1];
    }else{
    $sum2=$sum2+$data2[$st2-1];
    }
    $st2++;
}

if($sum1<$sum2){
$otvet=$sum1;
}elseif($sum1>$sum2){
$otvet=$sum2;
}elseif($sum1==$sum2){
$otvet=$sum1;
}
}
//$otvet=$sum1." ".$sum2;
//Вывод ответа
$out = fopen('php://output', 'w');
fputs($out,$otvet);

<?php

$stationCnt = (int) trim(fgets(STDIN));
$distances = array_map(function($n) { return (int) $n; }, explode(' ', trim(fgets(STDIN))));
$targets = explode(' ', trim(fgets(STDIN)));
$s = (int) $targets[0];
$t = (int) $targets[1];

if ($s === $t) {
	echo 0;
} else {
	if ($s > $t) {
		list($s, $t) = [$t,$s];
	}

	$s--; $t--;

	$directPath = 0;
	for ($i = $s; $i < $t; $i++) {
		$directPath += $distances[$i];
	}

	$reversePath = 0;
	for ($i = $t; $i != $s; $i = ($i + 1) % $stationCnt) {
		$reversePath += $distances[$i];
	}

	echo $directPath > $reversePath ? $reversePath : $directPath;
}

<?php
fscanf(STDIN, "%d",$n);
$num = fgets(STDIN);
$b = explode(' ', $num);
$sum = 0;
for($i = 0;$i < $n;$i ++){
    $a[$i] = intval($b[$i]);
    $sum += $a[$i];
}
$num = fgets(STDIN);
$b = explode(' ', $num);
$st = intval($b[0]);
$end = intval($b[1]);
if($st > $end){
    $tmp = $st;
    $st = $end;
    $end = $tmp;
}

$sum1 = 0;

for($i = $st-1;$i < $end-1;$i ++){
    $sum1 += $a[$i];
}

if($sum1 < $sum - $sum1){
    printf("%d", $sum1 );
}else {
    printf("%d", $sum - $sum1);
}

?>

<?php
// 278A   Кольцевая
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$n = (int) $input_line;

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

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

if ($s > $t) {
    $tmp = $s;
    $s = $t;
    $t = $tmp;
}

function sumArray($from, $to, $arr)
{
    $sum  = 0;
    for ($i=$from-1; $i < $to-1 ; $i++) {
        $sum += (int) $arr[$i];
    }

    return $sum;
}

$left = sumArray(1, $s, $arrD) + sumArray($t, $n+1, $arrD);
$rigth = sumArray($s, $t, $arrD);

echo min($left, $rigth);

?>

<?// BismiLahi Rahmani Rahim ?>

<?php

fscanf(STDIN, "%d", $n);
$d = explode(" ", trim(fgets(STDIN)));

fscanf(STDIN, "%d %d", $s, $t);
$s --;
$t --;

if ($s > $t) swap($s, $t);

$dist1 = 0;
$dist2 = 0;

$start = $t;
$end = $s;

while ($start != $end) {
	$dist1 += $d[$start];
	$start = ($start + 1) % $n;
}

$start = $s;
$end = $t;

while ($start != $end) {
	$dist2 += $d[$start];
	$start = ($start + 1) % $n;
}

printf("%d", min($dist1, $dist2));

function swap(&$a, &$b) {
	$t = $a;
	$a = $b;
	$b = $t;
}

?>

<?php
error_reporting("off");
//278A: Circle Line
$n = trim(fgets(STDIN)); //$n = 3;
$d = explode(" ", trim(fgets(STDIN))); //$d = explode(" ", "31 41 59");
$tosort = explode(" ", trim(fgets(STDIN)));
sort($tosort);
list($s, $t) = $tosort; //so that s and t aren't true anymore but s <= t
//$s = 1; $t = 1;
$betweenforward = $t - $s;
$distfor = 0;
$distbac = 0;
$curindex = $s - 1;
for ($i = 0; $i < $betweenforward; $i++) {
    $distfor += $d[$curindex];
    $curindex++;
}
$distbac = array_sum($d) - $distfor;if ($distfor <= $distbac) {
    echo $distfor;
} else {
    echo $distbac;
}
?>

<?php
    $n = trim(fgets(STDIN));
    $d = explode(" ", trim(fgets(STDIN)));
    $st = explode(" ", trim(fgets(STDIN)));
    $s = ((int)$st[0])-1;
    $t = ((int)$st[1])-1;

    if ($s == $t) {fwrite(STDOUT,"0"); exit; }
    if ($s > $t){ $tmp = $s; $s = $t; $t = $tmp;}

    for ($i=0, $end = abs($t-$s); $i<$end; $i++){
        $res1 += $d[$s+$i];
    }
    for ($i=0, $end = $n-$s-2; $i<$end; $i++){
        $now = $t+$i;
        if ($now > $n) $now = $i;
        $res2 += $d[$now];
    }
    if ($res1 < $res2){
        fwrite(STDOUT,"$res1");
    }else{
        fwrite(STDOUT,"$res2");
    }
?>

<?php
    $n = trim(fgets(STDIN));
    $d = explode(" ", trim(fgets(STDIN)));
    $st = explode(" ", trim(fgets(STDIN)));
    $s = ((int)$st[0])-1;
    $t = ((int)$st[1])-1;
    $z = abs($s-$t);

    if ($s == $t) {fwrite(STDOUT,"0"); exit; }
    if ($s > $t){ $tmp = $s; $s = $t; $t = $tmp;}

    for ($i=0, $end = abs($t-$s); $i<$end; $i++){
        $res1 += $d[$s+$i];
    }
    for ($i=0, $end = $n-$t+$z; $i<$end; $i++){
        $now = $t+$i;
        if ($now > $n) $now = $i;
        $res2 += $d[$now];
    }
    if ($res1 < $res2){
        fwrite(STDOUT,"$res1");
    }else{
        fwrite(STDOUT,"$res2");
    }
?>

<?//johnbug?>

<?php
fscanf(STDIN, "%d",$n);

$sum = 0;
for($i = 0;$i < $n;$i ++){
    fscanf(STDIN, "%d",$num);
    $sum += $num;
    $a[$i] = $num;
}
fscanf(STDIN, "%d",$st);
fscanf(STDIN, "%d",$end);

if($st > $end){
    $tmp = $st;
    $st = $end;
    $end = $tmp;
}

$sum1 = 0;

for($i = $st-1;$i < $end-1;$i ++){
    $sum1 += $a[$i];
}

if($sum1 < $sum - $sum1){
    printf("%d", $sum1 );
}else {
    printf("%d", $sum - $sum1);
}

?>


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

// pow('UGH', 2)
$max = 2000000000;
$min = -2000000000;

for($i = 0; $i<$n; $i++):
	list($sym, $val, $ans) = explode(" ", trim(fgets(STDIN)));

	if( ($sym == ">" && $ans == "Y"))
	{
		// fix for super imposed rules
		$min = max($min, $val + 1);
		continue;
	}

	// split these out since a negative does not prohibit use of val
	if($sym == "<" && $ans == "N")
	{
		$min = max($min, $val);
		continue;
	}

	if( ($sym == "<" && $ans == "Y") )
	{
		$max = min($max, $val - 1);
		continue;
	}

	// non prohibit fix
	if($sym == ">" && $ans == "N")
	{
		$max = min($max, $val);
		continue;
	}

	if( ($sym == "<=" && $ans == "Y") || ($sym == ">=" && $ans == "N") )
	{
		$max = min($val, $max);
		continue;
	}

	if( ($sym == ">=" && $ans == "Y") || ($sym == "<=" && $ans == "N") )
	{
		$min = max($min, $val);
	}

endfor;

if( $max < $min )
{
	echo "Impossible";
} else {
	echo rand($min, $max);
}

echo PHP_EOL;

<?php
$a = trim(fgets(STDIN));
$e = -2000000000;
$f = 2000000000;
for($x = 1; $x <= $a; $x++)
{
    list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    if($d == "Y")
    {
        switch($b)
        {
            case ">":
            $e = max($e, $c + 1);
            break;
            case "<":
            $f = min($f, $c - 1);
            break;
            case ">=":
            $e = max($e, $c);
            break;
            case "<=":
            $f = min($f, $c);
            break;
        }
    }
    else
    {
        switch($b)
        {
            case ">":
            $f = min($f, $c);
            break;
            case "<":
            $e = max($e, $c);
            break;
            case ">=":
            $f = min($f, $c - 1);
            break;
            case "<=":
            $e = max($e, $c + 1);
            break;
        }
    }
}
if($e > $f)
{
    print "Impossible";
}
else
{
    print rand($e, $f);
}
?>

<?php
fscanf(STDIN, "%d", $n);
$min=-2000000000;
$max=2000000000;
for ($i = 0; $i<$n; $i++){
    fscanf(STDIN, '%s %d %s\n', $cmp, $x, $answer);
    if ($answer=='N'){
        switch($cmp){
            case '>=':
                $cmp='<';
                break;
            case '>':
                $cmp='<=';
                break;
            case '<=':
                $cmp='>';
                break;
            case '<':
                $cmp='>=';
                break;
        }
    }
        switch ($cmp){
            case '>=':
                $min=max($min,$x);
                break;
            case '>':
                $min=max($min,$x+1);
                break;
            case '<=':
                $max=min($max,$x);
                break;
            case '<':
                $max=min($max,$x-1);
                break;
        }
}
if ($max<$min || $max>2000000000 || $min<-2000000000)
    echo "Impossible";
else
    fprintf(STDOUT, "%0.0f",$max);

<?php
function inverse( $str ) // error no poner $
{
   $val = "";
   if($str == ">")
      $val =  "<=";
   else if($str == "<")
      $val = ">=";
   else  if($str == ">=")
      $val = "<";
   else
      $val = ">";
   return $val;
}

$min_ = -2000000000;
$max_ = 2000000000;
$n = trim(fgets(STDIN));
for($i = 0; $i < $n; ++$i)
{
   $arr = explode(" ", trim(fgets(STDIN)));
   $sign = $arr[0];
   $num = $arr[1];
   $yn = $arr[2];
   if($yn == "N")
     $sign = inverse($sign);
   if($sign == "<=")
      $max_ = min($max_, $num);
   else if($sign == "<")
      $max_ = min($max_, $num - 1);
   else  if($sign == ">=")
      $min_ = max($min_, $num);
   else
      $min_ = max($min_, $num + 1);
}
if($min_ <= $max_)
   printf("%d", $min_);
else
   print("Impossible");

?>

<?php
$a = trim(fgets(STDIN));
$e = -2000000000;
$f = 2000000000;
for($x = 1; $x <= 4; $x++)
{
    list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    if($d == "Y")
    {
        switch($b)
        {
            case ">":
            $e = max($e, $c + 1);
            break;
            case "<":
            $f = min($f, $c - 1);
            break;
            case ">=":
            $e = max($e, $c);
            break;
            case "<=":
            $f = min($f, $c);
            break;
        }
    }
    else
    {
        switch($b)
        {
            case ">":
            $f = min($f, $c);
            break;
            case "<":
            $e = max($e, $c);
            break;
            case ">=":
            $f = min($f, $c - 1);
            break;
            case "<=":
            $e = max($e, $c + 1);
            break;
        }
    }
}
if($e > $f)
{
    print "Impossible";
}
else
{
    print rand($e, $f);
}
?>

<?php
$a = trim(fgets(STDIN));
$e = -1000000000;
$f = 1000000000;
for($x = 1; $x <= 4; $x++)
{
    list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    if($d == "Y")
    {
        switch($b)
        {
            case ">":
            $e = max($e, $c + 1);
            break;
            case "<":
            $f = min($f, $c - 1);
            break;
            case ">=":
            $e = max($e, $c);
            break;
            case "<=":
            $f = min($f, $c);
            break;
        }
    }
    else
    {
        switch($b)
        {
            case ">":
            $f = min($f, $c - 1);
            break;
            case "<":
            $e = max($e, $c + 1);
            break;
            case ">=":
            $f = min($f, $c);
            break;
            case "<=":
            $e = max($e, $c);
            break;
        }
    }
}
if($e > $f)
{
    print "Impossible";
}
else
{
    print rand($e, $f);
}
?>

<?php
$a = trim(fgets(STDIN));
$e = -1000000000;
$f = 1000000000;
for($x = 1; $x <= 4; $x++)
{
    list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
    if($d == "Y")
    {
        switch($b)
        {
            case ">":
            $e = max($e, $c + 1);
            break;
            case "<":
            $f = min($f, $c - 1);
            break;
            case ">=":
            $e = max($e, $c);
            break;
            case "<=":
            $f = min($f, $c);
            break;
        }
    }
    else
    {
        switch($b)
        {
            case ">":
            $f = min($f, $c);
            break;
            case "<":
            $e = max($e, $c);
            break;
            case ">=":
            $f = min($f, $c - 1);
            break;
            case "<=":
            $e = max($e, $c + 1);
            break;
        }
    }
}
if($e > $f)
{
    print "Impossible";
}
else
{
    print rand($e, $f);
}
?>

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

$max = PHP_INT_MAX;
$min = -PHP_INT_MAX;

for($i = 0; $i<$n; $i++):
	list($sym, $val, $ans) = explode(" ", trim(fgets(STDIN)));

	if( ($sym == ">" && $ans == "Y"))
	{
		// fix for super imposed rules
		$min = max($min, $val + 1);
		continue;
	}

	// split these out since a negative does not prohibit use of val
	if($sym == "<" && $ans == "N")
	{
		$min = max($min, $val);
		continue;
	}

	if( ($sym == "<" && $ans == "Y") )
	{
		$max = min($max, $val - 1);
		continue;
	}

	// non prohibit fix
	if($sym == ">" && $ans == "N")
	{
		$max = min($max, $val);
		continue;
	}

	if( ($sym == "<=" && $ans == "Y") || ($sym == ">=" && $ans == "N") )
	{
		$max = min($val, $max);
		continue;
	}

	if( ($sym == ">=" && $ans == "Y") || ($sym == "<=" && $ans == "N") )
	{
		$min = max($min, $val);
	}

endfor;

if( $max < $min )
{
	echo "Impossible";
} else {
	echo rand($min, $max);
}

echo PHP_EOL;

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

$max = -PHP_INT_MAX;
$min = PHP_INT_MAX;

for($i = 0; $i<$n; $i++):
	list($sym, $val, $ans) = explode(" ", trim(fgets(STDIN)));

	if( ($sym == ">" && $ans == "Y"))
	{
		$min = $val + 1;
		continue;
	}

	// split these out since a negative does not prohibit use of val
	if($sym == "<" && $ans == "N")
	{
		$min = $val;
		continue;
	}

	if( ($sym == "<" && $ans == "Y") )
	{
		$max = $val - 1;
		continue;
	}

	// non prohibit fix
	if($sym == ">" && $ans == "N")
	{
		$max = $val;
		continue;
	}

	if( ($sym == "<=" && $ans == "Y") || ($sym == ">=" && $ans == "N") )
	{
		$max = $val;
		continue;
	}

	if( ($sym == ">=" && $ans == "Y") || ($sym == "<=" && $ans == "N") )
	{
		$min = $val;
	}

endfor;

if( $max < $min )
{
	echo "Impossible";
} else {
	echo rand($min, $max);
}

echo PHP_EOL;

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

// UGH
$max = 1361956;
$min = -1361956;

for($i = 0; $i<$n; $i++):
	list($sym, $val, $ans) = explode(" ", trim(fgets(STDIN)));

	if( ($sym == ">" && $ans == "Y"))
	{
		// fix for super imposed rules
		$min = max($min, $val + 1);
		continue;
	}

	// split these out since a negative does not prohibit use of val
	if($sym == "<" && $ans == "N")
	{
		$min = max($min, $val);
		continue;
	}

	if( ($sym == "<" && $ans == "Y") )
	{
		$max = min($max, $val - 1);
		continue;
	}

	// non prohibit fix
	if($sym == ">" && $ans == "N")
	{
		$max = min($max, $val);
		continue;
	}

	if( ($sym == "<=" && $ans == "Y") || ($sym == ">=" && $ans == "N") )
	{
		$max = min($val, $max);
		continue;
	}

	if( ($sym == ">=" && $ans == "Y") || ($sym == "<=" && $ans == "N") )
	{
		$min = max($min, $val);
	}

endfor;

if( $max < $min )
{
	echo "Impossible";
} else {
	echo rand($min, $max);
}

echo PHP_EOL;

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

$max = -PHP_INT_MAX;
$min = PHP_INT_MAX;

for($i = 0; $i<$n; $i++):
	list($sym, $val, $ans) = explode(" ", trim(fgets(STDIN)));

	if( ($sym == ">" && $ans == "Y") || ($sym == "<" && $ans == "N") )
	{
		$min = $val + 1;
		continue;
	}

	if( ($sym == "<" && $ans == "Y") || ($sym == ">" && $ans == "N") )
	{
		$max = $val - 1;
		continue;
	}

	if( ($sym == "<=" && $ans == "Y") || ($sym == ">=" && $ans == "N") )
	{
		$max = $val;
		continue;
	}

	if( ($sym == ">=" && $ans == "Y") || ($sym == "<=" && $ans == "N") )
	{
		$min = $val;
	}

endfor;

if( $max < $min )
{
	echo "Impossible";
} else {
	echo rand($min, $max);
}

echo PHP_EOL;

<?php
fscanf(STDIN, "%d", $n);
$min=-2000000000;
$max=2000000000;
for ($i = 0; $i<$n; $i++){
    fscanf(STDIN, '%s %d %s\n', $cmp, $x, $answer);
    if ($answer=='N'){
        switch($cmp){
            case '=>':
                $cmp='<';
                break;
            case '>':
                $cmp='<=';
                break;
            case '<=':
                $cmp='>';
                break;
            case '<':
                $cmp='>=';
                break;
        }
    }
        switch ($cmp){
            case '>=':
                $min=max($min,$x);
                break;
            case '>':
                $min=max($min,$x+1);
                break;
            case '<=':
                $max=min($max,$x);
                break;
            case '<':
                $max=min($max,$x-1);
                break;
        }
}
if ($max<$min || $max>2000000000 || $min<-2000000000)
    echo "Impossible";
else
    fprintf(STDOUT, "%0.0f",$max);

<?php
fscanf(STDIN, "%d", $n);
$min=-2000000000;
$max=2000000000;
for ($i = 0; $i<$n; $i++){
    fscanf(STDIN, '%s %d %s\n', $cmp, $x, $answer);
    if ($answer=='N'){
        switch($cmp){
            case '=>':
                $cmp='<';
                break;
            case '>':
                $cmp='<=';
                break;
            case '<=':
                $cmp='>';
                break;
            case '<':
                $cmp='>=';
                break;
        }
    }
        switch ($cmp){
            case '=>':
                $min=max($min,$x);
                break;
            case '>':
                $min=max($min,$x+1);
                break;
            case '<=':
                $max=min($max,$x);
                break;
            case '<':
                $max=min($max,$x-1);
                break;
        }
}
if ($max<$min || $max>2000000000 || $min<-2000000000)
    echo "Impossible";
else
    fprintf(STDOUT, "%0.0f",$max);

<?php
fscanf(STDIN, "%d", $n);
$min=-2000000000;
$max=2000000000;
for ($i = 0; $i<$n; $i++){
    fscanf(STDIN, '%s %d %s\n', $cmp, $x, $answer);
    if ($answer=='N'){
        switch($cmp){
            case '>=':
                $cmp='<';
                break;
            case '>':
                $cmp='<=';
                break;
            case '<=':
                $cmp='>';
                break;
            case '<':
                $cmp='>=';
                break;
        }
    }
        switch ($cmp){
            case '=>':
                $min=max($min,$x);
                break;
            case '>':
                $min=max($min,$x+1);
                break;
            case '<=':
                $max=min($max,$x);
                break;
            case '<':
                $max=min($max,$x-1);
                break;
        }
}
if ($max<$min || $max>2000000000 || $min<-2000000000)
    echo "Impossible";
else
    fprintf(STDOUT, "%0.0f",$max);