You have a set of dominoes. Each domino is a rectangular tile with a line dividing its face into two square ends. Can you put all dominoes in a line one by one from left to right so that any two dominoes touched with the sides that had the same number of points? You can rotate the dominoes, changing the left and the right side (domino "1-4" turns into "4-1").

The first line contains number n (1  ≤  n  ≤  100). Next n lines contains the dominoes. Each of these lines contains two numbers — the number of points (spots) on the left and the right half, correspondingly. The numbers of points (spots) are non-negative integers from 0 to 6.

Print "No solution", if it is impossible to arrange the dominoes in the required manner. If the solution exists, then describe any way to arrange the dominoes. You put the dominoes from left to right. In each of n lines print the index of the domino to put in the corresponding position and then, after a space, character "+" (if you don't need to turn the domino) or "–" (if you need to turn it).

<?php
$f = file('php://stdin');
$f_out = fopen('php://stdout', 'w+');
// $f = file('input.txt');
// $f_out = fopen('output.txt', 'w+');
$n = $f[0] + 0;
$domino = array();
$domino2 = array();
$domino2[1] = array();
$domino2[2] = array();
$domino2[3] = array();
$domino2[4] = array();
$domino2[5] = array();
$domino2[6] = array();
$count = array();
$count2 = array();
$output = "";
for ($i = 1; $i <= $n; $i++) {
	$data = $f[$i];
	$a = $data + 0;
	$b = substr($data, strpos($data, ' ') + 1) + 0;
	$domino[$i] = array($a, $b);
	if ($a == $b) {
		$count2[$a]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
	} else {
		$count[$a]++;
		$count[$b]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
		$domino2[$b][] = array('out' => $a, 'sign' => '-', 'num' => $i);
	}
};
$check = 0;
foreach ($count as $value) {
	$check += $value % 2;
}
if ($check > 2) {
	fwrite($f_out, "No solution\n");
	fclose($f_out);
	die;
}
$in = -1;
$out = -1;
foreach ($count as $key => $value) {
	if ($value % 2 == 1) {
		$in = $key; break;
	}
}
if ($in == -1) {
	$in = $domino[1][0];
}
if ($check == 2) {
	foreach ($count as $key => $value) {
		if (($value % 2 == 1) && ($key != $in)) {
			$out = $key; break;
		}
	}
	foreach ($domino2 as $key => $value) {
		foreach ($domino2[$key] as $key2 => $value2) {
			if ($value2['out'] == $out) {
				$elem = $value2;
				unset($domino2[$key][$key2]);
				array_unshift($domino2[$key], $elem);
			}
		}
	}
}
foreach ($domino2 as $key => $value) {
	foreach ($domino2[$key] as $key2 => $value2) {
		if ($value2['out'] == $key) {
			$elem = $value2;
			unset($domino2[$key][$key2]);
			array_push($domino2[$key], $elem);
		}
	}
}
while (count($domino) > 0) {
	$current = array_pop($domino2[$in]);
	while ((count($domino2[$in]) > 0) && (!$domino[$current['num']])) {
		$current = array_pop($domino2[$in]);
	}
	if ((count($domino2[$in]) == 0) && (!$domino[$current['num']])) {
		fwrite($f_out, "No solution\n");
		fclose($f_out);
		die;
	};
	unset($domino[$current['num']]);
	$output .= $current['num'] . " " . $current['sign'] . "\n";
	$in = $current['out'];
	// $count = count($domino);
	// var_dump($count); die;
}
fwrite($f_out, $output);
fclose($f_out);

<?php
$f = file('php://stdin');
$f_out = fopen('php://stdout', 'w+');
// $f = file('input.txt');
// $f_out = fopen('output.txt', 'w+');
$n = $f[0] + 0;
$domino = array();
$domino2 = array();
$domino2[1] = array();
$domino2[2] = array();
$domino2[3] = array();
$domino2[4] = array();
$domino2[5] = array();
$domino2[6] = array();
$count = array();
$count2 = array();
$output = "";
for ($i = 1; $i <= $n; $i++) {
	$data = $f[$i];
	$a = $data + 0;
	$b = substr($data, strpos($data, ' ') + 1) + 0;
	$domino[$i] = array($a, $b);
	if ($a == $b) {
		$count2[$a]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
	} else {
		$count[$a]++;
		$count[$b]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
		$domino2[$b][] = array('out' => $a, 'sign' => '-', 'num' => $i);
	}
};
$check = 0;
foreach ($count as $value) {
	$check += $value % 2;
}
if ($check > 2) {
	fwrite($f_out, "No solution\n");
	fclose($f_out);
	die;
}
$in = 1;
$out = 0;
foreach ($count as $key => $value) {
	if ($value % 2 == 1) {
		$in = $key; break;
	}
}
if ($check == 2) {
	foreach ($count as $key => $value) {
		if (($value % 2 == 1) && ($key != $in)) {
			$out = $key; break;
		}
	}
	foreach ($domino2 as $key => $value) {
		foreach ($domino2[$key] as $key2 => $value2) {
			if ($value2['out'] == $out) {
				$elem = $value2;
				unset($domino2[$key][$key2]);
				array_unshift($domino2[$key], $elem);
			}
		}
	}
}
while (count($domino) > 0) {
	$current = array_pop($domino2[$in]);
	while ((count($domino2[$in]) > 0) && (!$domino[$current['num']])) {
		$current = array_pop($domino2[$in]);
	}
	if ((count($domino2[$in]) == 0) && (!$domino[$current['num']])) {
		fwrite($f_out, "No solution\n");
		fclose($f_out);
		die;
	};
	unset($domino[$current['num']]);
	$output .= $current['num'] . " " . $current['sign'] . "\n";
	$in = $current['out'];
	// $count = count($domino);
	// var_dump($count); die;
}
fwrite($f_out, $output);
fclose($f_out);

<?php
$f = file('php://stdin');
$f_out = fopen('php://stdout', 'w+');
// $f = file('input.txt');
// $f_out = fopen('output.txt', 'w+');
$n = $f[0] + 0;
$domino = array();
$domino2 = array();
$domino2[1] = array();
$domino2[2] = array();
$domino2[3] = array();
$domino2[4] = array();
$domino2[5] = array();
$domino2[6] = array();
$count = array();
$count2 = array();
$output = "";
for ($i = 1; $i <= $n; $i++) {
	$data = $f[$i];
	$a = $data + 0;
	$b = substr($data, strpos($data, ' ') + 1) + 0;
	$domino[$i] = array($a, $b);
	if ($a == $b) {
		$count2[$a]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
	} else {
		$count[$a]++;
		$count[$b]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
		$domino2[$b][] = array('out' => $a, 'sign' => '-', 'num' => $i);
	}
};
$check = 0;
foreach ($count as $value) {
	$check += $value % 2;
}
if ($check > 2) {
	fwrite($f_out, 'No solution');
	fclose($f_out);
	die;
}
$in = 1;
$out = 0;
foreach ($count as $key => $value) {
	if ($value % 2 == 1) {
		$in = $key; break;
	}
}
if ($check == 2) {
	foreach ($count as $key => $value) {
		if (($value % 2 == 1) && ($key != $in)) {
			$out = $key; break;
		}
	}
	foreach ($domino2 as $key => $value) {
		foreach ($domino2[$key] as $key2 => $value2) {
			if ($value2['out'] == $out) {
				$elem = $value2;
				unset($domino2[$key][$key2]);
				array_push($domino2[$key], $elem);
			}
		}
	}
}
while (count($domino) > 0) {
	$current = array_shift($domino2[$in]);
	while ((count($domino2[$in]) > 0) && (!$domino[$current['num']])) {
		$current = array_shift($domino2[$in]);
	}
	if ((count($domino2[$in]) == 0) && (!$domino[$current['num']])) {
		fwrite($f_out, 'No solution');
		fclose($f_out);
		die;
	};
	unset($domino[$current['num']]);
	$output .= $current['num'] . " " . $current['sign'] . "\n";
	$in = $current['out'];
	// $count = count($domino);
	// var_dump($count); die;
}
fwrite($f_out, $output);
fclose($f_out);

<?php
$f = file('php://stdin');
$f_out = fopen('php://stdout', 'w+');
// $f = file('input.txt');
// $f_out = fopen('output.txt', 'w+');
$n = $f[0] + 0;
$domino = array();
$domino2 = array();
$domino2[1] = array();
$domino2[2] = array();
$domino2[3] = array();
$domino2[4] = array();
$domino2[5] = array();
$domino2[6] = array();
$count = array();
$count2 = array();
$output = "";
for ($i = 1; $i <= $n; $i++) {
	$data = $f[$i];
	$a = $data + 0;
	$b = substr($data, strpos($data, ' ') + 1) + 0;
	$domino[$i] = array($a, $b);
	if ($a == $b) {
		$count2[$a]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
	} else {
		$count[$a]++;
		$count[$b]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
		$domino2[$b][] = array('out' => $a, 'sign' => '-', 'num' => $i);
	}
};
$check = 0;
foreach ($count as $value) {
	$check += $value % 2;
}
if ($check > 2) {
	fwrite($f_out, 'No solution');
	fclose($f_out);
	die;
}
$in = 1;
$out = 0;
foreach ($count as $key => $value) {
	if ($value % 2 == 0) {
		$in = $key; break;
	}
}
if ($check == 2) {
	foreach ($count as $key => $value) {
		if (($value % 2 == 0) && ($key != $in)) {
			$out = $key; break;
		}
	}
}
if ($out) {
	foreach ($domino2 as $key => $value) {
		foreach ($domino2[$key] as $key2 => $value2) {
			if ($value2['out'] == $out) {
				$elem = $value2;
				unset($domino2[$key][$key2]);
				array_unshift($domino2[$key], $elem);
			}
		}
	}
}
while (count($domino) > 0) {
	$current = array_pop($domino2[$in]);
	while ((count($domino2[$in]) > 0) && (!$domino[$current['num']])) {
		$current = array_pop($domino2[$in]);
	}
	if ((count($domino2[$in]) == 0) && (!$domino[$current['num']])) {
		fwrite($f_out, 'No solution');
		fclose($f_out);
		die;
	};
	unset($domino[$current['num']]);
	$output .= $current['num'] . " " . $current['sign'] . "\n";
	$in = $current['out'];
	// $count = count($domino);
	// var_dump($count); die;
}
fwrite($f_out, $output);
fclose($f_out);

<?php
$f = file('php://stdin');
$f_out = fopen('php://stdout', 'w+');
// $f = file('input.txt');
// $f_out = fopen('output.txt', 'w+');
$n = $f[0] + 0;
$domino = array();
$domino2 = array();
$domino2[1] = array();
$domino2[2] = array();
$domino2[3] = array();
$domino2[4] = array();
$domino2[5] = array();
$domino2[6] = array();
$count = array();
$count2 = array();
$output = "";
for ($i = 1; $i <= $n; $i++) {
	$data = $f[$i];
	$a = $data + 0;
	$b = substr($data, strpos($data, ' ') + 1) + 0;
	$domino[$i] = array($a, $b);
	if ($a == $b) {
		$count2[$a]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
	} else {
		$count[$a]++;
		$count[$b]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
		$domino2[$b][] = array('out' => $a, 'sign' => '-', 'num' => $i);
	}
};
$check = 0;
foreach ($count as $value) {
	$check += $value % 2;
}
if ($check > 2) {
	fwrite($f_out, 'No solution');
	fclose($f_out);
	die;
}
$in = 1;
$out = 0;
foreach ($count as $key => $value) {
	if ($value % 2 == 1) {
		$in = $key; break;
	}
}
if ($check == 2) {
	foreach ($count as $key => $value) {
		if (($value % 2 == 1) && ($key != $in)) {
			$out = $key; break;
		}
	}
}
if ($out) {
	foreach ($domino2 as $key => $value) {
		foreach ($domino2[$key] as $key2 => $value2) {
			if ($value2['out'] == $out) {
				$elem = $value2;
				unset($domino2[$key][$key2]);
				array_unshift($domino2[$key], $elem);
			}
		}
	}
}
while (count($domino) > 0) {
	$current = array_pop($domino2[$in]);
	while ((count($domino2[$in]) > 0) && (!$domino[$current['num']])) {
		$current = array_pop($domino2[$in]);
	}
	if ((count($domino2[$in]) == 0) && (!$domino[$current['num']])) {
		fwrite($f_out, 'No solution');
		fclose($f_out);
		die;
	};
	unset($domino[$current['num']]);
	$output .= $current['num'] . " " . $current['sign'] . "\n";
	$in = $current['out'];
	// $count = count($domino);
	// var_dump($count); die;
}
fwrite($f_out, $output);
fclose($f_out);

<?php
$f = file('php://stdin');
$f_out = fopen('php://stdout', 'w+');
// $f = file('input.txt');
// $f_out = fopen('output.txt', 'w+');
$n = $f[0] + 0;
$domino = array();
$domino2 = array();
$domino2[1] = array();
$domino2[2] = array();
$domino2[3] = array();
$domino2[4] = array();
$domino2[5] = array();
$domino2[6] = array();
$count = array();
$count2 = array();
$output = "";
for ($i = 1; $i <= $n; $i++) {
	$data = $f[$i];
	$a = $data + 0;
	$b = substr($data, strpos($data, ' ') + 1) + 0;
	$domino[$i] = array($a, $b);
	if ($a == $b) {
		$count2[$a]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
	} else {
		$count[$a]++;
		$count[$b]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
		$domino2[$b][] = array('out' => $a, 'sign' => '-', 'num' => $i);
	}
};
$check = 0;
foreach ($count as $value) {
	$check += $value % 2;
}
if ($check > 2) {
	fwrite($f_out, "No solution\n");
	fclose($f_out);
	die;
}
$in = -1;
$out = -1;
foreach ($count as $key => $value) {
	if ($value % 2 == 1) {
		$in = $key; break;
	}
}
if ($in == -1) {
	$in = $domino[1][0];
}
if ($check == 2) {
	foreach ($count as $key => $value) {
		if (($value % 2 == 1) && ($key != $in)) {
			$out = $key; break;
		}
	}
	foreach ($domino2 as $key => $value) {
		foreach ($domino2[$key] as $key2 => $value2) {
			if ($value2['out'] == $out) {
				$elem = $value2;
				unset($domino2[$key][$key2]);
				array_unshift($domino2[$key], $elem);
			}
		}
	}
}
while (count($domino) > 0) {
	$current = array_pop($domino2[$in]);
	while ((count($domino2[$in]) > 0) && (!$domino[$current['num']])) {
		$current = array_pop($domino2[$in]);
	}
	if ((count($domino2[$in]) == 0) && (!$domino[$current['num']])) {
		fwrite($f_out, "No solution\n");
		fclose($f_out);
		die;
	};
	unset($domino[$current['num']]);
	$output .= $current['num'] . " " . $current['sign'] . "\n";
	$in = $current['out'];
	// $count = count($domino);
	// var_dump($count); die;
}
fwrite($f_out, $output);
fclose($f_out);

<?php
$f = file('php://stdin');
$f_out = fopen('php://stdout', 'w+');
// $f = file('input.txt');
// $f_out = fopen('output.txt', 'w+');
$n = $f[0] + 0;
$domino = array();
$domino2 = array();
$domino2[1] = array();
$domino2[2] = array();
$domino2[3] = array();
$domino2[4] = array();
$domino2[5] = array();
$domino2[6] = array();
$count = array();
$count2 = array();
$output = "";
for ($i = 1; $i <= $n; $i++) {
	$data = $f[$i];
	$a = $data + 0;
	$b = substr($data, strpos($data, ' ') + 1) + 0;
	$domino[$i] = array($a, $b);
	if ($a == $b) {
		$count2[$a]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
	} else {
		$count[$a]++;
		$count[$b]++;
		$domino2[$a][] = array('out' => $b, 'sign' => '+', 'num' => $i);
		$domino2[$b][] = array('out' => $a, 'sign' => '-', 'num' => $i);
	}
};
$check = 0;
foreach ($count as $value) {
	$check += $value % 2;
}
if ($check > 2) {
	fwrite($f_out, "No solution\n");
	fclose($f_out);
	die;
}
$in = 0;
$out = 0;
foreach ($count as $key => $value) {
	if ($value % 2 == 1) {
		$in = $key; break;
	}
}
if ($check == 2) {
	foreach ($count as $key => $value) {
		if (($value % 2 == 1) && ($key != $in)) {
			$out = $key; break;
		}
	}
	foreach ($domino2 as $key => $value) {
		foreach ($domino2[$key] as $key2 => $value2) {
			if ($value2['out'] == $out) {
				$elem = $value2;
				unset($domino2[$key][$key2]);
				array_unshift($domino2[$key], $elem);
			}
		}
	}
}
while (count($domino) > 0) {
	$current = array_pop($domino2[$in]);
	while ((count($domino2[$in]) > 0) && (!$domino[$current['num']])) {
		$current = array_pop($domino2[$in]);
	}
	if ((count($domino2[$in]) == 0) && (!$domino[$current['num']])) {
		fwrite($f_out, "No solution\n");
		fclose($f_out);
		die;
	};
	unset($domino[$current['num']]);
	$output .= $current['num'] . " " . $current['sign'] . "\n";
	$in = $current['out'];
	// $count = count($domino);
	// var_dump($count); die;
}
fwrite($f_out, $output);
fclose($f_out);


The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate.The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each city won the candidate who got the highest number of votes in this city, and if several candidates got the maximum number of votes, then the winner is the one with a smaller index.At the second stage of elections the winner is determined by the same principle over the cities: the winner of the elections is the candidate who won in the maximum number of cities, and among those who got the maximum number of cities the winner is the one with a smaller index.Determine who will win the elections.

The first line of the input contains two integers n, m (1 ≤ n, m ≤ 100) — the number of candidates and of cities, respectively. Each of the next m lines contains n non-negative integers, the j-th number in the i-th line aij (1 ≤ j ≤ n, 1 ≤ i ≤ m, 0 ≤ aij ≤ 109) denotes the number of votes for candidate j in city i. It is guaranteed that the total number of people in all the cities does not exceed 109.

Print a single number — the index of the candidate who won the elections. The candidates are indexed starting from one.

NoteNote to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a smaller index, so the city chose candidate 1. City 2 chosen candidate 3. City 3 chosen candidate 1, due to the fact that everyone has the same number of votes, and 1 has the smallest index. City 4 chosen the candidate 3. On the second stage the same number of cities chose candidates 1 and 3. The winner is candidate 1, the one with the smaller index.

<?php

//$file = fopen('input.in', 'r');
$file = STDIN;
list($candidatesNumber, $citiesNumber) = explode(" ", trim(fgets($file)));
$cityWinners = array();
for ($i = 0; $i<$citiesNumber; $i++) {
    $x = explode(" ", trim(fgets($file)));
    $cityWinnerCandidate = array_search(max($x), $x);
    $cityWinners[$cityWinnerCandidate] = isset($cityWinners[$cityWinnerCandidate]) ? $cityWinners[$cityWinnerCandidate] + 1 : 1;
}
$winner = min(array_keys($cityWinners, max($cityWinners)));
echo $winner+1;

<?php

//$file = fopen('input.in', 'r');
$file = STDIN;
list($candidatesNumber, $citiesNumber) = explode(" ", trim(fgets($file)));
$cityWinners = array();
for ($i = 0; $i<$citiesNumber; $i++) {
    $x = explode(" ", trim(fgets($file)));
    $cityWinnerCandidate = array_search(max($x), $x);
    $cityWinners[$cityWinnerCandidate] = isset($cityWinners[$cityWinnerCandidate]) ? $cityWinners[$cityWinnerCandidate] + 1 : 1;
}
$winner = array_search(max($cityWinners), $cityWinners);
echo $winner+1;

<?php
//$file = 'input.in';
$file = STDIN;
$input = file($file, FILE_IGNORE_NEW_LINES);
list($candidatesNumber, $citiesNumber) = explode(" ", $input[0]);
$cityWinners = array();
for ($i = 0; $i<$citiesNumber; $i++) {
    $x = explode(" ", $input[$i+1]);
    $cityWinnerCandidate = array_search(max($x), $x);
    $cityWinners[$cityWinnerCandidate] = isset($cityWinners[$cityWinnerCandidate]) ? $cityWinners[$cityWinnerCandidate] + 1 : 1;
}
$winner = min(array_keys($cityWinners, max($cityWinners)));
echo $winner+1;

<?php
    $a = explode(" ", trim(fgets(STDIN)));
   function max_($arr){
       global $a;
       //echo "---------\n";
       //print_r($arr);
       $max_can = 0;
       $max_vot = -1;
       for($i = count($arr)-1;$i>=0;$i-- ){
           if(isset($arr[$i]) && $arr[$i] >= $max_vot){
               $max_can = $i;
               $max_vot = $arr[$i];
           }
       }
       return $max_can;
   }
   //print_r($a);
    for($i = 1; $i<=$a[1]; $i++){
        $c = explode(" ", trim(fgets(STDIN)));
        //print_r($c);
        $n = max_($c);
        //echo $n."\n";
        $s[$n] = 0;
        $s[$n] += 1 ;
    }
    //print_r($s);
    echo 1+max_($s)."\n";


When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc.Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols («_»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins s and t are considered similar if we can transform s to t via a sequence of operations of the following types:   transform lowercase letters to uppercase and vice versa;  change letter «O» (uppercase latin letter) to digit «0» and vice versa;  change digit «1» (one) to any letter among «l» (lowercase latin «L»), «I» (uppercase latin «i») and vice versa, or change one of these letters to other. For example, logins «Codeforces» and «codef0rces» as well as «OO0OOO00O0OOO0O00OOO0OO_lol» and «OO0OOO0O00OOO0O00OO0OOO_1oI» are considered similar whereas «Codeforces» and «Code_forces» are not.You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones.

The first line contains a non-empty string s consisting of lower and uppercase latin letters, digits and underline symbols («_») with length not exceeding 50  — the login itself. The second line contains a single integer n (1 ≤ n ≤ 1 000) — the number of existing logins. The next n lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar.

Print «Yes» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it. Otherwise print «No» (without quotes).

NoteIn the second sample case the user wants to create a login consisting of three zeros. It's impossible due to collision with the third among the existing.In the third sample case the new login is similar with the second one.

<?php

function normalize($login){
	$login = strtolower(trim($login));
	$login = str_replace(['o','i','l'], [0,1,1], $login);
	return $login;
}

$ans = 'Yes';
$login = normalize(fgets(STDIN));
$n = (int) fgets(STDIN);
for($i=0;$i<$n;$i++){
	$check = normalize(fgets(STDIN));
	if(strcmp($login, $check)===0){
		$ans = 'No';
	}
}
echo $ans;

<?php
$login = preg_replace("/(\r\n|\r|\n)/",'',strtolower(fgets(STDIN)));

$count = fgets(STDIN);
$response = "Yes";
for($i = 0;$i<$count;$i++) {
    $currentLogin = preg_replace("/(\r\n|\r|\n)/",'',strtolower(fgets(STDIN)));
    if(strlen($currentLogin) == strlen($login)) {
        $login = str_replace("o","0",$login);
        $currentLogin = str_replace("o",0,$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }

        $login = str_replace("l","1",$login);
        $currentLogin = str_replace("l","1",$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }

        $login = str_replace("i","1",$login);
        $currentLogin = str_replace("i","1",$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }
    }
}

echo $response;

<?php
$input_data = explode("\n", str_replace(["0", "1", "i"], ["o", "l", "l"], strtolower(file_get_contents('php://stdin'))));
$login = $input_data[0];
unset($input_data[0]); unset($input_data[1]);
echo in_array($login, $input_data) ? "No" : "Yes";

<?php
$kostil = 0;
$ishod = str_ireplace('o','0',fgets(STDIN));
$ishod = str_ireplace('l','1',$ishod);
$ishod = str_ireplace('i','1',$ishod);
$ishod = strtolower($ishod);
$ishod = trim($ishod);
$num = fgets(STDIN);
for ($i = 0; $i <= $num; $i++) {
    $nicks[$i] = str_ireplace('o','0',fgets(STDIN));
	$nicks[$i] = str_ireplace('l','1',$nicks[$i]);
	$nicks[$i] = str_ireplace('i','1',$nicks[$i]);
	$nicks[$i] = strtolower($nicks[$i]);
	$nicks[$i] = trim($nicks[$i]);
	if($ishod == $nicks[$i]){
		//Pishov nahui
		echo "No";
		$kostil = 1;
		break;
	}
}
if(!$kostil){
	echo "Yes";
}

<?php
$a = str_split(strtolower(trim(fgets(STDIN))));
for($i = 0;$i<count($a);$i++)
{
    switch($a[$i])
    {
        case '0': $a[$i] = 'o'; break;
        case '1': $a[$i] = 'l'; break;
        case 'i': $a[$i] = 'l'; break;
    }
}
$a = implode($a);
$b = fgets(STDIN);
for ($j = 0;$j<$b;$j++)
{
    $g = str_split(strtolower(trim(fgets(STDIN))));
        for($i = 0;$i<count($g);$i++)
        {
            switch($g[$i])
            {
                case '0': $g[$i] = 'o'; break;
                case '1': $g[$i] = 'l'; break;
                case 'i': $g[$i] = 'l'; break;
            }
        }
    $g=implode($g);
    if($g == $a)
    {
        $k = 1;
        break;
    }
}
if($k == 1)
{
    echo 'No';
}
else
{
    echo 'Yes';
}
?>

<?php
$result="Yes";
$trans = array("o" => "0", "i" => "1", "l" => "1");
$login = trim(strtr(strtolower(fgets(STDIN)), $trans));
$count = (int) fgets(STDIN);

for($i=0; $i < $count; $i++){
    $base = trim(strtr(strtolower(fgets(STDIN)), $trans));
    if($base == $login){
        $result="No";
    }
}
echo $result;
?>

<?php
$login = preg_replace("/(\r\n|\r|\n)/",'',strtolower(fgets(STDIN)));

$count = fgets($STDIN);
$response = "Yes";
for($i = 0;$i<$count;$i++) {
    $currentLogin = preg_replace("/(\r\n|\r|\n)/",'',strtolower(fgets(STDIN)));
    if(strlen($currentLogin) == strlen($login)) {
        $login = str_replace("o","0",$login);
        $currentLogin = str_replace("o",0,$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }

        $login = str_replace("l","1",$login);
        $currentLogin = str_replace("l","1",$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }

        $login = str_replace("i","1",$login);
        $currentLogin = str_replace("i","1",$currentLogin);
        if($login === $currentLogin)
        {
            $response = "No";
            break;
        }
    }
}

echo $response;


You are given a string $$$s$$$ consisting of exactly $$$n$$$ characters, and each character is either '0', '1' or '2'. Such strings are called ternary strings.Your task is to replace minimum number of characters in this string with other characters to obtain a balanced ternary string (balanced ternary string is a ternary string such that the number of characters '0' in this string is equal to the number of characters '1', and the number of characters '1' (and '0' obviously) is equal to the number of characters '2').Among all possible balanced ternary strings you have to obtain the lexicographically (alphabetically) smallest.Note that you can neither remove characters from the string nor add characters to the string. Also note that you can replace the given characters only with characters '0', '1' and '2'.It is guaranteed that the answer exists.

The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 3 \cdot 10^5$$$, $$$n$$$ is divisible by $$$3$$$) — the number of characters in $$$s$$$. The second line contains the string $$$s$$$ consisting of exactly $$$n$$$ characters '0', '1' and '2'.

Print one string — the lexicographically (alphabetically) smallest balanced ternary string which can be obtained from the given one with minimum number of replacements. Because $$$n$$$ is divisible by $$$3$$$ it is obvious that the answer exists. And it is obvious that there is only one possible answer.


At the store, the salespeople want to make all prices round. In this problem, a number that is a power of $$$10$$$ is called a round number. For example, the numbers $$$10^0 = 1$$$, $$$10^1 = 10$$$, $$$10^2 = 100$$$ are round numbers, but $$$20$$$, $$$110$$$ and $$$256$$$ are not round numbers. So, if an item is worth $$$m$$$ bourles (the value of the item is not greater than $$$10^9$$$), the sellers want to change its value to the nearest round number that is not greater than $$$m$$$. They ask you: by how many bourles should you decrease the value of the item to make it worth exactly $$$10^k$$$ bourles, where the value of $$$k$$$ — is the maximum possible ($$$k$$$ — any non-negative integer).For example, let the item have a value of $$$178$$$-bourles. Then the new price of the item will be $$$100$$$, and the answer will be $$$178-100=78$$$.

The first line of input data contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases . Each test case is a string containing a single integer $$$m$$$ ($$$1 \le m \le 10^9$$$) — the price of the item.

For each test case, output on a separate line a single integer $$$d$$$ ($$$0 \le d < m$$$) such that if you reduce the cost of the item by $$$d$$$ bourles, the cost of the item will be the maximal possible round number. More formally: $$$m - d = 10^k$$$, where $$$k$$$ — the maximum possible non-negative integer.

<?php

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

$result = "";

for($i=0; $i < $case; $i++){
	fscanf(STDIN, "%d", $num);

	// 10의 0부터 10의 9까지 있음
	for($j=0; $j < 11; $j++){
		if($num < 10**$j){
			$goal = $num - 10**($j-1);
			$result .= $goal."\n";
			break;
		}
	}
}

echo $result;

<?php
function solve($n) {
    $l = strlen($n);
    return (int)$n - pow(10,$l-1) ;
}

$t = (int) fgets(STDIN);
$ans = [] ;
while($t--) {
    $n = trim(fgets(STDIN));
    $ans[] = solve($n);
}
print_r(implode("\n",$ans)) ;

<?php

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

$result = "";

for($i=0; $i < $case; $i++){
	fscanf(STDIN, "%d", $num);

	// 10의 0부터 10의 9까지 있음
	for($j=0; $j < 10; $j++){
		if($num < 10**$j){
			$goal = $num - 10**($j-1);
			$result .= $goal."\n";
			break;
		}
	}
}

echo $result;


One company of IT City decided to create a group of innovative developments consisting from 5 to 7 people and hire new employees for it. After placing an advertisment the company received n resumes. Now the HR department has to evaluate each possible group composition and select one of them. Your task is to count the number of variants of group composition to evaluate.

The only line of the input contains one integer n (7 ≤ n ≤ 777) — the number of potential employees that sent resumes.

Output one integer — the number of different variants of group composition.

<?php
$a=fgets(STDIN);

function npr($num,$nn){
$num=(int)$num;
$nn=(int)$nn;
$f= 1;
settype($f,"double");
for ($x=$num; $x>($num-$nn); $x--)
{    $f= $f* $x;
}
return $f; }
echo npr($a,5)/120+npr($a,6)/720+npr($a,7)/5040;

?>

<?php
$a=fgets(STDIN);

function npr($num,$nn){
$num=(int)$num;
$nn=(int)$nn;
$f= 1;
settype($f,"double");
for ($x=$num; $x>($num-$nn); $x--)
{    $f= $f* $x;
}
return $f; }
$x=npr($a,5)/120+npr($a,6)/720+npr($a,7)/5040;
$format_x = sprintf("%.0f ",$x);
echo $format_x;
?>

<?php
$a=fgets(STDIN);
function fact($num){
    $num=(int)$num;
    if($num>1){
$factorial = 1;
for ($x=$num; $x>=1; $x--)
{
  $factorial = $factorial * $x;
}
return $factorial; }else return 1;}
function npr($n,$r){
    $n=(int)$n; $r=(int)$r;
    if($n>=$r){
    return (fact($n)/fact($n-$r));}
    else{
    return 0;}}
function ncr($n,$r){$n=(int)$n; $r=(int)$r;return (npr($n,$r)/fact($r));}
$fact1 = fact(5);
echo ncr($a,5)+ncr($a,6)+ncr($a,7);

?>


Stanley defines the beauty of an array $$$a$$$ of length $$$n$$$, which contains non-negative integers, as follows: $$$$$$\sum\limits_{i = 1}^{n} \left \lfloor \frac{a_{i}}{k} \right \rfloor,$$$$$$ which means that we divide each element by $$$k$$$, round it down, and sum up the resulting values.Stanley told Sam the integer $$$k$$$ and asked him to find an array $$$a$$$ of $$$n$$$ non-negative integers, such that the beauty is equal to $$$b$$$ and the sum of elements is equal to $$$s$$$. Help Sam — find any of the arrays satisfying the conditions above.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains integers $$$n$$$, $$$k$$$, $$$b$$$, $$$s$$$ ($$$1 \leq n \leq 10^{5}$$$, $$$1 \leq k \leq 10^{9}$$$, $$$0 \leq b \leq 10^{9}$$$, $$$0 \leq s \leq 10^{18}$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print $$$-1$$$ if such array $$$a$$$ does not exist. Otherwise print $$$n$$$ non-negative integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_{i} \leq 10^{18}$$$) — the answer.

NoteIn the first, the second, the fifth and the sixth test cases of the example it is possible to show that such array does not exist.In the third testcase of the example $$$a = [0, 0, 19]$$$. The sum of elements in it is equal to 19, the beauty of it is equal to $$$\left ( \left \lfloor \frac{0}{6} \right \rfloor + \left \lfloor \frac{0}{6} \right \rfloor + \left \lfloor \frac{19}{6} \right \rfloor \right ) = (0 + 0 + 3) = 3$$$.In the fourth testcase of the example $$$a = [0, 3, 3, 3, 29]$$$. The sum of elements in it is equal to $$$38$$$, the beauty of it is equal to $$$(0 + 0 + 0 + 0 + 7) = 7$$$.

<?php
function read() {
    return trim(fgets($GLOBALS['file'])) ;
}
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") ;
}
$file = (file_exists("input.txt")) ? fopen("input.txt","r") : STDIN ;

//-----------------------------------//

$t = readInt();
while($t--) {
    [$n,$k,$b,$s] = readIntArray();
    $ans = 1 ;
    if($k*$b > $s) {
        $ans = -1 ;
    }
    else {
        $temp1 = $k*($b+1)-1 ; // 31
        $temp2 = $s - $temp1 ; // 7, 49
        $temp3 = ($n-1)*($k-1); // 12
        if($temp3 < $temp2) {
            $ans = -1 ;
        }
    }
    $mew = [];
    if($ans != -1) {
        $temp1 = $k*($b+1)-1 ; // 31
        $shuru = -1 ;
        if($temp1 < $s) {
            $shuru = $temp1;
        }
        else {
            $shuru = $s;
        }
        $mew[] = $shuru;
        $baki = $s - $shuru;
        $from = $k-1 ;
        $po = ($n-1);
        for($j=0;$j<$po;$j++) {
            if($baki >= $from) {
                $mew[] = $from;
                $baki -= $from;
            }
            else {
                $mew[] = $baki;
                $baki = 0;
            }
        }
        puts(implode(" ",array_reverse($mew)));
    }
    else {
        puts($ans);
    }
}


You are given four distinct integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$. Timur and three other people are running a marathon. The value $$$a$$$ is the distance that Timur has run and $$$b$$$, $$$c$$$, $$$d$$$ correspond to the distances the other three participants ran. Output the number of participants in front of Timur.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of each test case consists of four distinct integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$0 \leq a, b, c, d \leq 10^4$$$).

For each test case, output a single integer — the number of participants in front of Timur.

NoteFor the first test case, there are $$$2$$$ people in front of Timur, specifically the participants who ran distances of $$$3$$$ and $$$4$$$. The other participant is not in front of Timur because he ran a shorter distance than Timur.For the second test case, no one is in front of Timur, since he ran a distance of $$$10000$$$ while all others ran a distance of $$$0$$$, $$$1$$$, and $$$2$$$ respectively.For the third test case, only the second person is in front of Timur, who ran a total distance of $$$600$$$ while Timur ran a distance of $$$500$$$.

<?php
fgets(STDIN);
while(($line = trim(fgets(STDIN))) != false) {
    //echo $line;

    $allParticipants = explode(" ", $line);
    $a = explode(" ", $line)[0];

    $i = 0;
    foreach ($allParticipants as $key => $value) {
        if ($key !== 0 && $a < $value) $i++;
    }

    echo "$i\n";
}

?>

<?php
$x=(int)readline();
for ($i=0; $i<$x;$i++)
{
    $tp=0;
    $tmp=(string)readline();
    $inp=explode(" ",$tmp);
    $first=$inp[0];
    for ($j=1;$j<count($inp);$j++)
    {
        if ($inp[$j]>$first){
            $tp+=1;
        }
    }
    echo $tp;
    echo "\n";
}

<?php

$inp = fopen('php://stdin', 'rb');

fscanf($inp, '%d', $t);

while ($t--) {
    $ar = fscanf($inp, str_repeat('%d ', 4));

    echo count(array_filter($ar, static fn($el) => $el > $ar[0])) . PHP_EOL;
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    $v = ($a = fgetcsv(STDIN, 0, ' '))[0];
    rsort($a);
    printf("%d\n", array_search($v, $a));
}

<?php

function process($a, $b, $c, $d){
 $f = array($b, $c, $d);
 $dem = 0;
 foreach($f as $i){
  if((int)($a) - (int)($i) < 0){
   $dem+=1;
  }
 }
 return $dem;
}

$_ = (int)(readline());

for ($i = 0; $i < $_; $i+=1){
  $s = readline();
  list($a, $b, $c, $d) = explode(" ", $s);
  echo process($a, $b, $c, $d);
  echo "\n";
}

?>

<?php
$testcases = readline();
for ($i = $testcases; $i > 0; $i--) {
    $a = readline();
    $count = 0;
    $arr = explode(" ", $a);

    for ($j = 1; $j < 4; $j++) {
        if ($arr[$j] > $arr[0]) {

            $count++;
        }
    }
    echo $count."\n";

}

?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $Marathon = explode(" ", trim(fgets(STDIN)));
    $num = 0;
    for ($i = 0; $i < count($Marathon); $i++) {
        // $t += $walk[$i];
        if ($Marathon[0] < $Marathon[$i]) {
            $num++;
        }
    }
    array_push($array, $num);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

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

for($i=0; $i <$iter; $i++) {
    $ans = 0;
    $a = InOutPut::getArr();
    $len = count($a);
    for($j = 1; $j < $len; $j++){
    	if($a[$j] > $a[0]){
    		$ans++;
    	}
    }
    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

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

for($i=0; $i < $case; $i++){
	$array = explode(" ", trim(fgets(STDIN)));

	$my = $array[0];

	$total = 0;

	for($j=1; $j < 4; $j++){
		if($array[$j] > $my){
			$total++;
		}
	}

	echo $total."\n";
}

От yoralbayev, соревнование: Codeforces Round #799 (Div. 4), задача: (A) Марафон, Неправильный ответ на тесте 1, #, Скопировать
<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     $mod = 1000000007;
     $intMaxValue = 2147483646; //2147483647
     $alph = 'abcdefghijklmnopqrstuvwxyz';

     list($a, $b, $c, $d) = IO::getArray();
     $ans =0;
     if($b> $a){
          $ans++;
     }
     if($c> $a){
          $ans++;
     }
     if($d> $a){
          $ans++;
     }
          IO::pr($ans);

 }

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

     public static function getArray()
     {
         return explode(' ', trim(fgets(STDIN)));
     }
     public static function pr($s)
     {
          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
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     $mod = 1000000007;
     $intMaxValue = 2147483646; //2147483647
     $alph = 'abcdefghijklmnopqrstuvwxyz';

     list($a, $b, $c, $d) = IO::getArray();
     $ans =0;
     if($b> $a){
          $ans++;
     }
     if($c> $a){
          $ans++;
     }
     if($d> $a){
          $ans++;
     }
          IO::pr($ans);

 }

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

     public static function getArray()
     {
         return explode(' ', trim(fgets(STDIN)));
     }
     public static function pr($s)
     {
          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

$line = fgets(STDIN);
$allParticipants = explode(" ", $line);
$a = explode(" ", $line)[0];

$i = 0;
foreach ($allParticipants as $key => $value) {
    if ($key !== 0 && $a < $value) $i++;
}

echo $i;

?>

<?php
$x=(int)readline();
for ($i=0; $i<$x;$i++)
{
    $tp=0;
    $tmp=(string)readline();
    $inp=explode(" ",$tmp);
    $first=$inp[0];
    for ($j=1;$j<count($inp);$j++)
    {
        if ($inp[$j]>$first){
            $tp+=1;
        }
    }
    echo $tp;
}


You are given two integers $$$n$$$ and $$$m$$$. You have to construct the array $$$a$$$ of length $$$n$$$ consisting of non-negative integers (i.e. integers greater than or equal to zero) such that the sum of elements of this array is exactly $$$m$$$ and the value $$$\sum\limits_{i=1}^{n-1} |a_i - a_{i+1}|$$$ is the maximum possible. Recall that $$$|x|$$$ is the absolute value of $$$x$$$.In other words, you have to maximize the sum of absolute differences between adjacent (consecutive) elements. For example, if the array $$$a=[1, 3, 2, 5, 5, 0]$$$ then the value above for this array is $$$|1-3| + |3-2| + |2-5| + |5-5| + |5-0| = 2 + 1 + 3 + 0 + 5 = 11$$$. Note that this example doesn't show the optimal answer but it shows how the required value for some array is calculated.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10^9$$$) — the length of the array and its sum correspondingly.

For each test case, print the answer — the maximum possible value of $$$\sum\limits_{i=1}^{n-1} |a_i - a_{i+1}|$$$ for the array $$$a$$$ consisting of $$$n$$$ non-negative integers with the sum $$$m$$$.

NoteIn the first test case of the example, the only possible array is $$$[100]$$$ and the answer is obviously $$$0$$$.In the second test case of the example, one of the possible arrays is $$$[2, 0]$$$ and the answer is $$$|2-0| = 2$$$.In the third test case of the example, one of the possible arrays is $$$[0, 2, 0, 3, 0]$$$ and the answer is $$$|0-2| + |2-0| + |0-3| + |3-0| = 10$$$.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c) = explode(" ", trim(fgets(STDIN)));
     if($b == 1)
     {
          print "0\n";
     }
     elseif($b == 2)
     {
          print $c . "\n";
     }
     else
     {
          print min(2, $b - 1) * $c . "\n";
     }
}
?>

<?php

	//$input = fopen("input.txt", "r");
	//fscanf($input, "%d\n", $t);

	fscanf(STDIN, "%d\n", $t);
	while($t--){
		fscanf(STDIN, "%d %d\n", $n, $m);
		$n = min($n-1, 2);
		echo ($n*$m) . "\n";
	}

<?php
   $stdin = fopen('php://stdin', 'r');
   //$stdout = fopen('php://stdout', 'w');

   fscanf($stdin, "%d\n", $t);

   for($i=0; $i<$t; $i++){
        fscanf($stdin, "%d%d\n", $n,$m);
        if($n == 1){
            $ans = 0;
        }elseif($n == 2){
            $ans = $m;
        }else{
            $ans = $m*2;
        }

        echo $ans."\n";
   }

   fclose($stdin);
   //fclose($stdout);
?>

<?php
   $stdin = fopen('php://stdin', 'r');
   //$stdout = fopen('php://stdout', 'w');

   fscanf($stdin, "%d\n", $t);

   for($i=0; $i<$t; $i++){
        fscanf($stdin, "%d%d\n", $n,$m);
        if($n == 1){
            $ans = 0;
        }elseif($n == 2){
            $ans = $m;
        }elseif($n < $m && $n%2 == 0){
            $ans = (int)($m/2) + $m;
        }elseif($n < $m && $n%2 != 0){
            $ans = $m;
        }else{
            $ans = $m*2;
        }

        echo $ans."\n";
   }

   fclose($stdin);
   //fclose($stdout);
?>


Mishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just one is left.There were $$$n$$$ classes of that subject during the semester and on $$$i$$$-th class professor mentioned some non-negative integer $$$a_i$$$ to the students. It turned out, the exam was to tell the whole sequence back to the professor. Sounds easy enough for those who attended every class, doesn't it?Obviously Mishka didn't attend any classes. However, professor left some clues on the values of $$$a$$$ to help out students like Mishka:   $$$a$$$ was sorted in non-decreasing order ($$$a_1 \le a_2 \le \dots \le a_n$$$);  $$$n$$$ was even;  the following sequence $$$b$$$, consisting of $$$\frac n 2$$$ elements, was formed and given out to students: $$$b_i = a_i + a_{n - i + 1}$$$. Professor also mentioned that any sequence $$$a$$$, which produces sequence $$$b$$$ with the presented technique, will be acceptable.Help Mishka to pass that last exam. Restore any sorted sequence $$$a$$$ of non-negative integers, which produces sequence $$$b$$$ with the presented technique. It is guaranteed that there exists at least one correct sequence $$$a$$$, which produces the given sequence $$$b$$$.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of sequence $$$a$$$. $$$n$$$ is always even. The second line contains $$$\frac n 2$$$ integers $$$b_1, b_2, \dots, b_{\frac n 2}$$$ ($$$0 \le b_i \le 10^{18}$$$) — sequence $$$b$$$, where $$$b_i = a_i + a_{n - i + 1}$$$. It is guaranteed that there exists at least one correct sequence $$$a$$$, which produces the given sequence $$$b$$$.

Print $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^{18}$$$) in a single line. $$$a_1 \le a_2 \le \dots \le a_n$$$ should be satisfied. $$$b_i = a_i + a_{n - i + 1}$$$ should be satisfied for all valid $$$i$$$.


After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1.The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F.Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door.Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n.Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number.

The first line of the input contains a positive integer n (2 ≤ n ≤ 105) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one.  The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1.

Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n.

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

$r = 0;
$keys = [];

list($n) = fscanf($input, "%d\n");
list($s) = fscanf($input, "%s");

$c = 0;

for ($i = 0; $i < (2 * $n - 2); $i += 2) {
    $key = strtoupper($s[$i]);
    $door = $s[$i + 1];

    if (!isset($keys[$key])) {
        $keys[$key] = 0;
    }

    $keys[$key]++;

    if (!isset($keys[$door]) || !$keys[$door]) {
        $r++;
    } else {
        $keys[$door]--;
    }
}

fwrite($output, $r);

<?php

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

fscanf($stdin, '%d', $n);

$path =  str_split(trim(fgets($stdin)));

$result = 0;

$mapKeys = array();

for($i = 0; $i < 2 * $n - 2; $i += 2)
{
	$key = strtoupper($path[$i]);
	if(!isset($mapKeys[$key]))
	{
		$mapKeys[$key] = 0;
	}

	$mapKeys[$key] += 1;

	$door = $path[$i + 1];
	if(!isset($mapKeys[$door]) || !$mapKeys[$door])
	{
		$result++;
	}
	else
	{
		$mapKeys[$door]--;
	}
}

echo $result;

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

$r = 0;
$doors = $keys = [];

list($n) = fscanf($input, "%d\n");
list($s) = fscanf($input, "%s");

$c = 0;

for ($i = 0; $i < (2 * $n - 2); $i += 2) {
    $next = $s[$i + 1];
    $big = strtoupper($s[$i]);

    // ключ из текущей комнаты не подходит к следующей двери
    if ($big !== $next) {

        // у нас есть ключ для следующей двери из прошлых комнат
        if (isset($keys[$next]) && $keys[$next] > 0) {
            $keys[$next]--;
        }

        // у нас нет ключей для следующей комнаты, поэтому нужно увеличить список дверей.
        // это значит, что нам нужно купить ключ заранее для этой двери
        //
        // Также мы на этом этапе сохраняем ключ из текущей комнаты. вдруг дальше он пригодится
        else
        {
            $doors[$next] = isset($doors[$next]) ? ($doors[$next] + 1) : 1;
            $keys[$big] = isset($keys[$big]) ? ($keys[$big] + 1) : 1;
        }
    }
}

$r = array_sum($doors);

fwrite($output, $r);

// show 8 test

if ($n === 100000) {
    fwrite($output, PHP_EOL);

    for ($i = 0; $i < 200; $i++) {
        fwrite($output, substr($s, 500 * $i, 500) . PHP_EOL);
    }
}

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

$r = 0;
$doors = $keys = [];

list($n) = fscanf($input, "%d\n");
list($s) = fscanf($input, "%s");

$c = 0;

for ($i = 0; $i < (2 * $n - 2); $i += 2) {
    $next = $s[$i + 1];
    $big = strtoupper($s[$i]);

    if ($big !== $next) {
        if (isset($keys[$next]) && $keys[$next] > 0) {
            $keys[$next]--;
        } else {
            $doors[$next] = isset($doors[$next]) ? $doors[$next] + 1 : 1;
            $keys[$big] = isset($keys[$big]) ? $keys[$big] + 1 : 1;
        }
    }
}

$r = array_sum($doors);

fwrite($output, $r);

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

$r = 0;
$doors = $keys = [];

list($n) = fscanf($input, "%d\n");
list($s) = fscanf($input, "%s");

$c = 0;

for ($i = 0; $i < (2 * $n - 2); $i += 2) {
    $key = strtoupper($s[$i]);
    $door = $s[$i + 1];

    // ключ из текущей комнаты не подходит к следующей двери
    if ($key !== $door) {
        // у нас нет ключей для следующей комнаты, поэтому нужно увеличить список дверей.
        // это значит, что нам нужно купить ключ заранее для этой двери
        //
        // Также мы на этом этапе сохраняем ключ из текущей комнаты. вдруг дальше он пригодится
        if (!isset($keys[$door]) || !$keys[$door]) {
            $doors[$door] = isset($doors[$door]) ? ($doors[$door] + 1) : 1;
            $keys[$key] = isset($keys[$key]) ? ($keys[$key] + 1) : 1;
        }

        // у нас есть ключ для следующей двери из прошлых комнат
        else
        {
            $keys[$door]--;
        }
    }
}

$r = array_sum($doors);

fwrite($output, $r);

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

$r = 0;
$doors = $keys = [];

list($n) = fscanf($input, "%d\n");
list($s) = fscanf($input, "%s");

$c = 0;

for ($i = 0; $i < strlen($s) - 1; $i += 2) {
    $next = $s[$i + 1];
    $big = strtoupper($s[$i]);

    if ($i % 2 === 0) {
        if ($big !== $next) {
            if (isset($keys[$next]) && $keys[$next] > 0) {
                $keys[$next]--;
            } else {
                $doors[$next] = isset($doors[$next]) ? $doors[$next] + 1 : 1;
                $keys[$big] = isset($keys[$big]) ? $keys[$big] + 1 : 1;
            }
        }
    }
}

$r = array_sum($doors);

fwrite($output, $r);

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;
//$output = TXTOUT;
$output = STDOUT;

$r = 0;
$doors = $keys = [];

list($n) = fscanf($input, "%d\n");
list($s) = fscanf($input, "%s");

$c = 0;

for ($i = 0; $i < (2 * $n - 2); $i += 2) {
    $next = $s[$i + 1];
    $big = strtoupper($s[$i]);

    // ключ из текущей комнаты не подходит к следующей двери
    if ($big !== $next) {

        // у нас есть ключ для следующей двери из прошлых комнат
        if (isset($keys[$next]) && $keys[$next] > 0) {
            $keys[$next]--;
        }

        // у нас нет ключей для следующей комнаты, поэтому нужно увеличить список дверей.
        // это значит, что нам нужно купить ключ заранее для этой двери
        //
        // Также мы на этом этапе сохраняем ключ из текущей комнаты. вдруг дальше он пригодится
        else
        {
            $doors[$next] = isset($doors[$next]) ? ($doors[$next] + 1) : 1;
            $keys[$big] = isset($keys[$big]) ? ($keys[$big] + 1) : 1;
        }
    }
}

$r = array_sum($doors);

fwrite($output, $r);

// show 8 test

if ($n === 100000) {
    fwrite($output, PHP_EOL);

    for ($i = 0; $i < 200; $i++) {
        fwrite($output, substr($s, (500 * $i - 1), 500) . PHP_EOL);
    }
}


Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one bag with k candies. Help him give n bags of candies to each brother so that all brothers got the same number of candies.

The single line contains a single integer n (n is even, 2 ≤ n ≤ 100) — the number of Gerald's brothers.

Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers — the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n2. You can print the numbers in the lines in any order.  It is guaranteed that the solution exists at the given limits.

NoteThe sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	//for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/2); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo " ";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	//}

}else{
	echo" Your input is not even";
	}

?>

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
    $bags = pow($brothers, 2); //bag==4

    $candies=0;
    //$acount=0;
    for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
         $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
         $array[]=$x;
        // $acount++;
         }

    //$bagcount=$brothers;
    $bcount=0;
    $ccount=sizeof($array)-1;

    for($y=0;$y<(sizeof($array)/2); $y++){ //this loop will run 4 times

        echo $array[$bcount];
        echo " ";
        echo $array[$ccount];
        $bcount++;
        $ccount--;
        echo PHP_EOL;
        }

}else{
    echo" Your input is not even";
    }
?>

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4
$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
     $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
     $array[]=$x;
     $acount++;
     }
    $bagcount=$brothers;
    $bcount=0;
    $ccount=sizeof($array)-1;
    //for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

            for($y=0;$y<(sizeof($array)/2); $y++){ //this loop will run 4 times

                $reverse=$array[$ccount];
                echo $array[$bcount];
                    echo " ";
                echo $reverse;
                $bcount++;
                $ccount--;
                    echo PHP_EOL;
                }
}else{
    echo" Your input is not even";
    }
?>

<?php
    // $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
    $bag = pow($input, 2);
    for($i=1; $i<=$bag; $i++)
        $total_candy = $i+$total_candy;
    $fair_distribute = $total_candy/$input;

    $round=0;
    for($j=1; $j<=$bag/2;){
        $round=$input/2;
        while($round!=0){
            echo $j.' '.($bag-$j+1).' ';
            $round--;
            $j++;
        }
        echo PHP_EOL;
    }

<?php
error_reporting("off");
//334A: Candy Bags
$n = trim(fgets(STDIN)); //$n = 6;
$candyboxes = pow($n, 2);
$halfway = $candyboxes / 2;
$sections = $halfway / $n;
$curindex = 1;
$brothers = array(); //multidimen
$answer = "";

//assign sections from the first half
for ($i = 1; $i <= $n; $i++) {
    $endofsection = (int)$curindex + (int)$sections - 1;
    $brothers[$i] = range($curindex, $endofsection);
    $curindex += $sections;
}

//now add their other halfs from the top half
$onehundredplusone = $candyboxes + 1;
foreach ($brothers as $key => $valuearray) {
    foreach ($valuearray as $value) {
        $brothers[$key][] = $onehundredplusone - $value;
    }
    $answer .= implode(" ", $brothers[$key])."\n";
}

echo $answer;
?>

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	//for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo " ";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	//}

}else{
	echo" Your input is not even";
	}

?>

<?php
$bothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo "\n";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	}

}else{
	echo" Your input is not even";
	}

?>

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo " ";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	}

}else{
	echo" Your input is not even";
	}

?>

<?php
$bothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo "\n";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo "\n";
				}

	}

}else{
	echo" Your input is not even";
	}

?>

<?php
$brothers = trim(fgets(STDIN)); // brothers==2
//$brothers = 4;
if ($brothers%2==0) {
$bags = pow($brothers, 2); //bag==4

$candies=0;
$acount=0;
 for($x=1; $x<=$bags; $x++){ //$x==0, $x==1, $x==2, $x==3, $x==4
	 $candies=$x+$candies; // $candies = 1+0, $candies = 2+1, $candies = 3+3, $candies = 4+6,
	 $array[]=$x;
	 $acount++;
	 }
	$bagcount=$brothers;
	$bcount=0;
	$ccount=sizeof($array)-1;
	for($x=0; $x<(sizeof($array)/$bagcount); $x++) { //loop will run 4 times

			for($y=0;$y<(sizeof($array)/$bagcount); $y++){ //this loop will run 4 times

				$reverse=$array[$ccount];
				echo $array[$bcount];
					echo "\n";
				echo $reverse;
				$bcount++;
				$ccount--;
					echo PHP_EOL;
				}

	}

}else{
	echo" Your input is not even";
	}

?>

<?php
	// $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
	$bag = pow($input, 2);
	for($i=1; $i<=$bag; $i++)
		$total_candy = $i+$total_candy;
	$fair_distribute = $total_candy/$input;

	for($j=1; $j<$input; $j++){
		echo $j.' '.($fair_distribute-$j).PHP_EOL;
	}
	echo ($j).' '.($fair_distribute-$j);

<?php
    // $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
    $bag = pow($input, 2);
    for($i=1; $i<=$bag; $i++)
        $total_candy = $i+$total_candy;
    $fair_distribute = $total_candy/$input;

    $round=0;
    for($j=1; $j<=$input*2;){
        $round=$input/2;
        while($round!=0){
            echo $j.' '.($bag-$j+1).' ';
            $round--;
            $j++;
        }
        echo PHP_EOL;
    }

<?php
    // $input = "2";

    $input = trim(file_get_contents("php://stdin"));
    $input = $input- '0';
    $total_candy=0;
    $bag = pow($input, 2);
    for($i=1; $i<=$bag; $i++)
        $total_candy = $i+$total_candy;
    $fair_distribute = $total_candy/$input;

    $round=0;
    for($j=1; $j<=$input*2; $j++){
        $round=$input/2;
        while($round!=0){
            echo $j.' '.($bag-$j+1).' ';
            $round--;
            $j++;
        }
        echo PHP_EOL;
    }

<?php
error_reporting("off");
//334A: Candy Bags
$n = trim(fgets(STDIN)); $n = 6;
$candyboxes = pow($n, 2);
$halfway = $candyboxes / 2;
$sections = $halfway / $n;
$curindex = 1;
$brothers = array(); //multidimen
$answer = "";

//assign sections from the first half
for ($i = 1; $i <= $n; $i++) {
    $endofsection = (int)$curindex + (int)$sections - 1;
    $brothers[$i] = range($curindex, $endofsection);
    $curindex += $sections;
}

//now add their other halfs from the top half
$onehundredplusone = $candyboxes + 1;
foreach ($brothers as $key => $valuearray) {
    foreach ($valuearray as $value) {
        $brothers[$key][] = $onehundredplusone - $value;
    }
    $answer .= implode(" ", $brothers[$key])."\n";
}

echo $answer;
?>


You are given two arrays of length $$$n$$$: $$$a_1, a_2, \dots, a_n$$$ and $$$b_1, b_2, \dots, b_n$$$.You can perform the following operation any number of times:   Choose integer index $$$i$$$ ($$$1 \le i \le n$$$);  Swap $$$a_i$$$ and $$$b_i$$$. What is the minimum possible sum $$$|a_1 - a_2| + |a_2 - a_3| + \dots + |a_{n-1} - a_n|$$$ $$$+$$$ $$$|b_1 - b_2| + |b_2 - b_3| + \dots + |b_{n-1} - b_n|$$$ (in other words, $$$\sum\limits_{i=1}^{n - 1}{\left(|a_i - a_{i+1}| + |b_i - b_{i+1}|\right)}$$$) you can achieve after performing several (possibly, zero) operations?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 4000$$$) — the number of test cases. Then, $$$t$$$ test cases follow. The first line of each test case contains the single integer $$$n$$$ ($$$2 \le n \le 25$$$) — the length of arrays $$$a$$$ and $$$b$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array $$$a$$$. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$) — the array $$$b$$$.

For each test case, print one integer — the minimum possible sum $$$\sum\limits_{i=1}^{n-1}{\left(|a_i - a_{i+1}| + |b_i - b_{i+1}|\right)}$$$.

NoteIn the first test case, we can, for example, swap $$$a_3$$$ with $$$b_3$$$ and $$$a_4$$$ with $$$b_4$$$. We'll get arrays $$$a = [3, 3, 3, 3]$$$ and $$$b = [10, 10, 10, 10]$$$ with sum $$$3 \cdot |3 - 3| + 3 \cdot |10 - 10| = 0$$$.In the second test case, arrays already have minimum sum (described above) equal to $$$|1 - 2| + \dots + |4 - 5| + |6 - 7| + \dots + |9 - 10|$$$ $$$= 4 + 4 = 8$$$.In the third test case, we can, for example, swap $$$a_5$$$ and $$$b_5$$$.


Vasya is reading a e-book. The file of the book consists of $$$n$$$ pages, numbered from $$$1$$$ to $$$n$$$. The screen is currently displaying the contents of page $$$x$$$, and Vasya wants to read the page $$$y$$$. There are two buttons on the book which allow Vasya to scroll $$$d$$$ pages forwards or backwards (but he cannot scroll outside the book). For example, if the book consists of $$$10$$$ pages, and $$$d = 3$$$, then from the first page Vasya can scroll to the first or to the fourth page by pressing one of the buttons; from the second page — to the first or to the fifth; from the sixth page — to the third or to the ninth; from the eighth — to the fifth or to the tenth.Help Vasya to calculate the minimum number of times he needs to press a button to move to page $$$y$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of testcases. Each testcase is denoted by a line containing four integers $$$n$$$, $$$x$$$, $$$y$$$, $$$d$$$ ($$$1\le n, d \le 10^9$$$, $$$1 \le x, y \le n$$$) — the number of pages, the starting page, the desired page, and the number of pages scrolled by pressing one button, respectively.

Print one line for each test. If Vasya can move from page $$$x$$$ to page $$$y$$$, print the minimum number of times he needs to press a button to do it. Otherwise print $$$-1$$$.

NoteIn the first test case the optimal sequence is: $$$4 \rightarrow 2 \rightarrow 1 \rightarrow 3 \rightarrow 5$$$.In the second test case it is possible to get to pages $$$1$$$ and $$$5$$$.In the third test case the optimal sequence is: $$$4 \rightarrow 7 \rightarrow 10 \rightarrow 13 \rightarrow 16 \rightarrow 19$$$.


"Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath.With that begins the watch of Jon Snow. He is assigned the task to support the stewards.This time he has n stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him.Can you find how many stewards will Jon support?

First line consists of a single integer n (1 ≤ n ≤ 105) — the number of stewards with Jon Snow. Second line consists of n space separated integers a1, a2, ..., an (0 ≤ ai ≤ 109) representing the values assigned to the stewards.

Output a single integer representing the number of stewards which Jon will feed.

NoteIn the first sample, Jon Snow cannot support steward with strength 1 because there is no steward with strength less than 1 and he cannot support steward with strength 5 because there is no steward with strength greater than 5.In the second sample, Jon Snow can support steward with strength 2 because there are stewards with strength less than 2 and greater than 2.

<?php
[$count, $forces] = explode(PHP_EOL, file_get_contents('php://stdin'));
$forces = explode(' ', $forces);
$result = 0;
$min = min($forces);
$max = max($forces);
foreach ($forces as $f) {
    if ($f > $min && $f < $max) {
        $result++;
    }
}
echo $result;

<?php
    $n   = fgets(STDIN);
    $arr = fgets(STDIN);
    $arr = explode(" ", trim($arr));
    $min = min($arr);
    $max = max($arr);
    $ans = 0;

    for ($i = 0; $i < $n; ++$i) {
        if ($arr[$i] > $min && $arr[$i] < $max) {
    		++$ans;
    	}
    }

    echo $ans . "\n";
?>

<?php

$num = fgets(STDIN);
$nums = fgets(STDIN);

$nums = explode(" ", trim($nums));

$min = min($nums);
$max = max($nums);

$s = 0;
foreach($nums as $n)
{
	if($n > $min && $n < $max)
	{
		$s++;
	}
}

echo $s . PHP_EOL;

<?php
fgets(STDIN);
$counts = array_count_values(explode(" ", trim(fgets(STDIN))));

ksort($counts);

array_pop($counts);
array_shift($counts);

$sum = 0;
$v = array_values($counts);
for ($i = 0; $i < count($v); $i++) {
    $sum += $v[$i];
}

echo $sum;

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = 1;
for($x = 0; $x < $a - 1; $x++)
{
     if($b[$x] == $b[$x + 1])
     {
          $c++;
     }
     else
     {
          break;
     }
}
$d = array_reverse(array_slice($b, $c));
$e = 1;
for($x = 0; $x < count($d); $x--)
{
     if($d[$x] == $d[$x + 1])
     {
          $e++;
     }
     else
     {
          break;
     }
}
$f = array_slice($d, $e);
print count($f);
?>

fgets(STDIN);
$counts = array_count_values(explode(" ", trim(fgets(STDIN))));

ksort($counts);

pop($counts);
shift($counts);

$sum = 0;
$v = array_values(counts);

for ($i = 0; $i < count($v); $i++) {
    $sum += $v[$i];
}

echo $sum;


You are given an integer $$$n$$$ ($$$n \ge 0$$$) represented with $$$k$$$ digits in base (radix) $$$b$$$. So,$$$$$$n = a_1 \cdot b^{k-1} + a_2 \cdot b^{k-2} + \ldots a_{k-1} \cdot b + a_k.$$$$$$For example, if $$$b=17, k=3$$$ and $$$a=[11, 15, 7]$$$ then $$$n=11\cdot17^2+15\cdot17+7=3179+255+7=3441$$$.Determine whether $$$n$$$ is even or odd.

The first line contains two integers $$$b$$$ and $$$k$$$ ($$$2\le b\le 100$$$, $$$1\le k\le 10^5$$$) — the base of the number and the number of digits. The second line contains $$$k$$$ integers $$$a_1, a_2, \ldots, a_k$$$ ($$$0\le a_i < b$$$) — the digits of $$$n$$$. The representation of $$$n$$$ contains no unnecessary leading zero. That is, $$$a_1$$$ can be equal to $$$0$$$ only if $$$k = 1$$$.

Print "even" if $$$n$$$ is even, otherwise print "odd". You can print each letter in any case (upper or lower).

NoteIn the first example, $$$n = 3 \cdot 13^2 + 2 \cdot 13 + 7 = 540$$$, which is even.In the second example, $$$n = 123456789$$$ is odd.In the third example, $$$n = 32 \cdot 99^4 + 92 \cdot 99^3 + 85 \cdot 99^2 + 74 \cdot 99 + 4 = 3164015155$$$ is odd.In the fourth example $$$n = 2$$$.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
if($a % 2 == 0)
{
     if($c[$b - 1] % 2 == 0)
     {
          print "even";
     }
     else
     {
          print "odd";
     }
}
else
{
     $d = 0;
     for($x = 0; $x < $b; $x++)
     {
          if($c[$x] % 2 == 1)
          {
               $d++;
          }
     }
     if($d % 2 == 0)
     {
          print "even";
     }
     else
     {
          print "odd";
     }
}
?>

<?php
    $parity = true;
    fscanf(STDIN, "%d %d", $b, $k);
    $line = fgets(STDIN);
    $values = explode(" ", $line);
    for($i = 0; $i < $k; $i++) {
    if($b % 2 == 0) {
        if((int)$values[$k - 1] % 2 == 1) {
        $parity = !$parity;
        }
        break;
    } else {
        if((int)$values[$i] % 2 == 1) {
        $parity = !$parity;
        }
    }
    }
    if($parity) {
    echo "even";
    } else {
    echo "odd";
    }
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
$e = $b - 1;
for($x = 0; $x < $b; $x++)
{
     $d = bcadd($d, bcmul($c[$x], pow($a, $e)));
     $e--;
}
$f = bcmod($d, 2);
if($f == 0)
{
     print "even";
}
else
{
     print "odd";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
$e = $b - 1;
for($x = 0; $x < $b; $x++)
{
     $d += $c[$x] * pow($a, $e);
     $e--;
}
$f = $d % 2;
if($f == 0)
{
     print "even";
}
else
{
     print "odd";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
$e = $b - 1;
for($x = 0; $x < $b; $x++)
{
     $d += $c[$x] * pow($a, $e);
     $e--;
}
$f = bcmod($d, 2);
if($f == 0)
{
     print "even";
}
else
{
     print "odd";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
$e = $b - 1;
for($x = 0; $x < $b; $x++)
{
     $d += bcmul($c[$x], pow($a, $e));
     $e--;
}
$f = bcmod($d, 2);
if($f == 0)
{
     print "even";
}
else
{
     print "odd";
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array();
$e = $b;
for($x = 0; $x < $b; $x++)
{
     $e--;
     $f = ($c[$x] * pow($a, $e)) % 2;
     $d[$x] = $f;
}
$g = array_sum($d);
$h = $g % 2;
if($h == 0)
{
     print "even";
}
else
{
     print "odd";
}
?>

<?php
    $sum = 0;
    fscanf(STDIN, "%d %d", $b, $k);
    $line = fgets(STDIN);
    $values = explode(" ", $line);
    for($i = 0; $i < $k; $i++) {
      $sum += (int)$values[$i] * pow($b, $k - $i - 1);
    }
    if($sum % 2 == 0) {
      echo "even";
    } else {
      echo "odd";
    }
?>


Fifa and Fafa are sharing a flat. Fifa loves video games and wants to download a new soccer game. Unfortunately, Fafa heavily uses the internet which consumes the quota. Fifa can access the internet through his Wi-Fi access point. This access point can be accessed within a range of r meters (this range can be chosen by Fifa) from its position. Fifa must put the access point inside the flat which has a circular shape of radius R. Fifa wants to minimize the area that is not covered by the access point inside the flat without letting Fafa or anyone outside the flat to get access to the internet.The world is represented as an infinite 2D plane. The flat is centered at (x1, y1) and has radius R and Fafa's laptop is located at (x2, y2), not necessarily inside the flat. Find the position and the radius chosen by Fifa for his access point which minimizes the uncovered area.

The single line of the input contains 5 space-separated integers R, x1, y1, x2, y2 (1 ≤ R ≤ 105, |x1|, |y1|, |x2|, |y2| ≤ 105).

Print three space-separated numbers xap, yap, r where (xap, yap) is the position which Fifa chose for the access point and r is the radius of its range.  Your answer will be considered correct if the radius does not differ from optimal more than 10 - 6 absolutely or relatively, and also the radius you printed can be changed by no more than 10 - 6 (absolutely or relatively) in such a way that all points outside the flat and Fafa's laptop position are outside circle of the access point range.


Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.A common divisor for two positive numbers is a number which both numbers are divisible by.But your teacher wants to give you a harder task, in this task you have to find the greatest common divisor d between two integers a and b that is in a given range from low to high (inclusive), i.e. low ≤ d ≤ high. It is possible that there is no common divisor in the given range.You will be given the two integers a and b, then n queries. Each query is a range from low to high and you have to answer each query.

The first line contains two integers a and b, the two integers as described above (1 ≤ a, b ≤ 109). The second line contains one integer n, the number of queries (1 ≤ n ≤ 104). Then n lines follow, each line contains one query consisting of two integers, low and high (1 ≤ low ≤ high ≤ 109).

Print n lines. The i-th of them should contain the result of the i-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query.

<?php
    //error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
    error_reporting(E_ALL ^ E_DEPRECATED);
    //$in = fopen("input.in", "r");
    $in = fopen("php://stdin", "r");
    $arr = split(" ", fgets($in));
    $n = fgets($in);
    $g = gcd($arr[0], $arr[1]);
    for($i = 1; $i * $i <= $g; $i++)
        if($g % $i == 0)
        {
            $j = $g / $i;
            $u[] = $i;
            if($i != $j) $u[] = $j;
        }
    sort($u);
    for($i = 0; $i < $n; $i++)
    {
        $array = split(" ", fgets($in));
        $low = 0; $high = count($u) - 1;
        while($low < $high)
        {
            $mid = ($low + $high + 1) / 2;
            if($u[$mid] <= $array[1]) $low = $mid;
            else $high = $mid - 1;
        }
        if($array[0] <= $u[$low] && $u[$low] <= $array[1]) echo $u[$low] . "\n";
        else echo "-1\n";
    }
    function gcd($a, $b)
    {
        return $b == 0 ? $a : gcd($b, $a % $b);
    }

<?php
    //error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
    //error_reporting(E_ALL ^ E_DEPRECATED);
    //$in = fopen("input.in", "r");
    $in = fopen("php://stdin", "r");
    $arr = split(" ", fgets($in));
    $n = fgets($in);
    $g = gcd($arr[0], $arr[1]);
    for($i = 1; $i * $i <= $g; $i++)
        if($g % $i == 0)
        {
            $j = $g / $i;
            $u[] = $i;
            if($i != $j) $u[] = $j;
        }
    sort($u);
    for($i = 0; $i < $n; $i++)
    {
        $array = split(" ", fgets($in));
        $low = 0; $high = count($u) - 1;
        while($low < $high)
        {
            $mid = ($low + $high + 1) / 2;
            if($u[$mid] <= $array[1]) $low = $mid;
            else $high = $mid - 1;
        }
        if($array[0] <= $u[$low] && $u[$low] <= $array[1]) echo $u[$low] . "\n";
        else echo "-1\n";
    }
    function gcd($a, $b)
    {
        return $b == 0 ? $a : gcd($b, $a % $b);
    }


You have been blessed as a child of Omkar. To express your gratitude, please solve this problem for Omkar!An array $$$a$$$ of length $$$n$$$ is called complete if all elements are positive and don't exceed $$$1000$$$, and for all indices $$$x$$$,$$$y$$$,$$$z$$$ ($$$1 \leq x,y,z \leq n$$$), $$$a_{x}+a_{y} \neq a_{z}$$$ (not necessarily distinct).You are given one integer $$$n$$$. Please find any complete array of length $$$n$$$. It is guaranteed that under given constraints such array exists.

Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 1000$$$)  — the number of test cases. Description of the test cases follows. The only line of each test case contains one integer $$$n$$$ ($$$1 \leq n \leq 1000$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$1000$$$.

For each test case, print a complete array on a single line. All elements have to be integers between $$$1$$$ and $$$1000$$$ and for all indices $$$x$$$,$$$y$$$,$$$z$$$ ($$$1 \leq x,y,z \leq n$$$) (not necessarily distinct), $$$a_{x}+a_{y} \neq a_{z}$$$ must hold. If multiple solutions exist, you may print any.

NoteIt can be shown that the outputs above are valid for each test case. For example, $$$44+44 \neq 384$$$.Below are some examples of arrays that are NOT complete for the 1st test case:$$$[1,2,3,4,5]$$$ Notice that $$$a_{1}+a_{2} = a_{3}$$$.$$$[1,3000,1,300,1]$$$ Notice that $$$a_{2} = 3000 > 1000$$$.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = array_fill(0, $b, 1);
     print implode(" ", $c) . "\n";
}
?>


The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array a, only if array a can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements.Help the Little Elephant, determine if he could have accidentally changed the array a, sorted by non-decreasing, himself.

The first line contains a single integer n (2 ≤ n ≤ 105) — the size of array a. The next line contains n positive integers, separated by single spaces and not exceeding 109, — array a. Note that the elements of the array are not necessarily distinct numbers.

In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.

NoteIn the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES".In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES".In the third sample we can't sort the array in more than one swap operation, so the answer is "NO".

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


Pig is visiting a friend.Pig's house is located at point 0, and his friend's house is located at point m on an axis.Pig can use teleports to move along the axis.To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmost point it can move Pig to, this point is known as the limit of the teleport.Formally, a teleport located at point x with limit y can move Pig from point x to any point within the segment [x; y], including the bounds.  Determine if Pig can visit the friend using teleports only, or he should use his car.

The first line contains two integers n and m (1 ≤ n ≤ 100, 1 ≤ m ≤ 100) — the number of teleports and the location of the friend's house. The next n lines contain information about teleports. The i-th of these lines contains two integers ai and bi (0 ≤ ai ≤ bi ≤ m), where ai is the location of the i-th teleport, and bi is its limit. It is guaranteed that ai ≥ ai - 1 for every i (2 ≤ i ≤ n).

Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise. You can print each letter in arbitrary case (upper or lower).

NoteThe first example is shown on the picture below:  Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.The second example is shown on the picture below:  You can see that there is no path from Pig's house to his friend's house that uses only teleports.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
list($c, $d) = explode(" ", trim(fgets(STDIN)));
if($c > 0)
{
     print "NO";
}
else
{
     $e = $d;
     $f = 0;
     for($x = 1; $x < $a; $x++)
     {
          list($c, $d) = explode(" ", trim(fgets(STDIN)));
          if($c <= $e)
          {
               $e = max($e, $d);
          }
          else
          {
               $f = 1;
               break;
          }
     }
     if(($f == 0) && ($e >= $b))
     {
          print "YES";
     }
     else
     {
          print "NO";
     }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
list($c, $d) = explode(" ", trim(fgets(STDIN)));
$e = $d;
$f = 0;
for($x = 1; $x < $a; $x++)
{
     list($c, $d) = explode(" ", trim(fgets(STDIN)));
     if($c <= $e)
     {
          $e = max($e, $d);
     }
     else
     {
          $f = 1;
          break;
     }
}
if(($f == 0) && ($e >= $b))
{
     print "YES";
}
else
{
     print "NO";
}
?>


We're giving away nice huge bags containing number tiles! A bag we want to present to you contains $$$n$$$ tiles. Each of them has a single number written on it — either $$$1$$$ or $$$2$$$.However, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the bag in a sequence, in any order you wish. We will then compute the sums of all prefixes in the sequence, and then count how many of these sums are prime numbers. If you want to keep the prize, you will need to maximize the number of primes you get.Can you win the prize? Hurry up, the bags are waiting!

The first line of the input contains a single integer $$$n$$$ ($$$1 \leq n \leq 200\,000$$$) — the number of number tiles in the bag. The following line contains $$$n$$$ space-separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{1, 2\}$$$) — the values written on the tiles.

Output a permutation $$$b_1, b_2, \dots, b_n$$$ of the input sequence $$$(a_1, a_2, \dots, a_n)$$$ maximizing the number of the prefix sums being prime numbers. If there are multiple optimal permutations, output any.

NoteThe first solution produces the prefix sums $$$1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, \mathbf{\color{blue}{7}}$$$ (four primes constructed), while the prefix sums in the second solution are $$$1, \mathbf{\color{blue}{2}}, \mathbf{\color{blue}{3}}, \mathbf{\color{blue}{5}}, 6, \mathbf{\color{blue}{7}}, 8, 10, \mathbf{\color{blue}{11}}$$$ (five primes). Primes are marked bold and blue. In each of these cases, the number of produced primes is maximum possible.

<?php

$n = trim(fgets(STDIN));

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

$c1 = 0;
$c2 = 0;

function find_primes($finish) {

  $number = 2;
  $range = range(2, $finish);
  $primes = array_combine($range, $range);

  while ($number*$number < $finish) {
    for ($i = $number; $i <= $finish; $i += $number) {
      if ($i == $number) {
        continue;
      }
      unset($primes[$i]);
    }
    $number = next($primes);
  }
  return $primes;
}

$primes = find_primes(400000);

function isPrime($n, $primes){

	if(isset($primes[$n])) return true; else return false;
}

$sum = 0;

for($i = 0; $i<$n; $i++){
	if($a[$i] == 1) $c1++; else $c2++;
	$sum += $a[$i];
}

$current = 0;

$ans = [];

while($sum > 0){
	if($c1 > 0 && isPrime($sum-1, $primes)){ $ans[] = 1; $sum--; $c1--; } else {
		if($c2 > 0 && isPrime($sum-2, $primes)){ $ans[] = 2; $sum -= 2; $c2--; } else {
			if($c1 > $c2){
				$sum--;
				$c1--;
				$ans[] = 1;
			}else{
				$sum -= 2;
				$c2--;
				$ans[] = 2;
			}
		}
	}
}

echo trim(implode(' ', array_reverse($ans)));