Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winning if the sum of the column numbers is strictly greater than the sum of the row numbers.For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8 + 3 + 6 + 7 = 24, sum of its row numbers equals 9 + 5 + 3 + 2 = 19, and 24 > 19.

The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.

Print the single number — the number of the winning squares.

NoteIn the first example two upper squares are winning.In the third example three left squares in the both middle rows are winning:5 7 8 49 5 3 21 6 6 49 5 7 3

<?php
error_reporting(0);

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

	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			$inp_num = $Scanner->Scan();
			$row_sum[$i] += $inp_num;
			$col_sum[$j] += $inp_num;
		}
	}

	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			//if($row_sum[$i] > $col_sum[$j]) $count++;
			if($row_sum[$i] < $col_sum[$j]) $count++;
		}
	}
	printf("%d", $count);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

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

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

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

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

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

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

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

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

<?php
error_reporting(0);

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

	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			$inp_num = $Scanner->Scan();
			$inp_row[$i][] = $inp_num;
			$row_sum[$i] += $inp_num;
			$col_sum[$j] += $inp_num;
		}
	}

	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			//if($row_sum[$i] > $col_sum[$j]) $count++;
			if($row_sum[$i] < $col_sum[$j]) $count++;
		}
	}
	printf("%d", $count);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

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

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

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

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

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

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

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

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

<?php
error_reporting(0);

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

	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			$inp_num = $Scanner->Scan();
			$inp_row[$i][] = $inp_num;
			$row_sum[$i] += $inp_num;
		}
	}
	$col_sum = array();
	for ($k = 0; $k < $inp_n; $k++) {
		for ($l = 0; $l < $inp_n; $l++) {
			$col_sum[$k] += $inp_row[$l][$k];
		}
	}

	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			//if($row_sum[$i] > $col_sum[$j]) $count++;
			if($row_sum[$i] < $col_sum[$j]) $count++;
		}
	}
	printf("%d", $count);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

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

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

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

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

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

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

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

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

<?php

function read_input_data() {
  $handle = fopen ("php://stdin","r");
  $n = intval(fgets($handle));

  $data = array();
  for ($i = 0; $i<$n; $i++) {
    $data[] = explode(' ', trim(fgets($handle)));
  }
  fclose($handle);

  return array($n, $data);
}

function read_input_data_test() {
  $n = 4;
  $data = array(
    array(5, 7, 8, 4),
    array(9, 5, 3, 2),
    array(1, 6, 6, 4),
    array(9, 5, 7, 3),
  );

  return array($n, $data);
}

function extract_v_line($arr, $j) {
  $result = array();
  foreach ($arr as $i => $line) {

    # code...
  }
}

list($n, $data) = read_input_data();
$v_sum = $h_sum = array_fill(0, $n, 0);

for ($i = 0; $i<$n; $i++) {
  $line = $data[$i];
  $h_sum[$i] = array_sum($line);
  for ($j = 0; $j<$n; $j++) {
    $v_sum[$j] += $line[$j];
  }
}

// print_r($v_sum);
// print_r($h_sum);

$result = 0;

for ($i = 0; $i<$n; $i++) {
  for ($j = 0; $j<$n; $j++) {
    if ($v_sum[$j] > $h_sum[$i]) {
      $result++;
    }
  }
}

print $result ."\n";

<?
error_reporting(0);

$fp = fopen("php://stdin",'r');
$countMatr = (int)(str_replace( "\r\n", '', fgets($fp)));

$sumRows = array();
$sumCols = array();
$i = 0;
while( $countMatr-- ){
	$points = explode(" ", trim( str_replace( "\r\n", '', fgets($fp)) ) );
	foreach( $points as $key => $value )
	{
		$sumRows[$i] += $value;
		$sumCols[$key] += $value;
	}
	$i++;
}

$res = 0;
foreach( $sumRows as $key1 => $rowsVal ){
	foreach( $sumCols as $key2 => $colsVal ){
		if( $colsVal > $rowsVal ){
			$res++;
		}
	}
}
echo $res;
fclose($fp);
?>

<?php

$str = file_get_contents('php://stdin');
//$str = file_get_contents('STDIN');

$s = explode("\n", $str);

$lines = array();

foreach ($s as $k=>$v) {
	if ($k == 0) {
		$size = $v;
	} else {
		$l = explode(" ", $v);
		$lines[] = $l;
		//$sum_x[] = array_sum($l);
	}
}

$wins = 0;
$x = $y = array();
for ($i = 0; $i < $size; $i++) {
	$sum_x = array_sum($lines[$i]);
	$sum_y = 0;
	for ($n = 0; $n < $size; $n++) {
		$sum_y += $lines[$n][$i];
	}

	$x[] = $sum_x;
	$y[] = $sum_y;

}

foreach ($x as $k=>$v) {
	for ($i = 0; $i < $size; $i++) {
		if ($v < $y[$i]) {
			$wins++;
		}
	}
}

printf('%s', $wins);

<?php
$count = 0;
$n = fgets(STDIN);
$arr = array();

function check($i0, $j0)
{
    global $arr, $n;

    $sumH = $sumV = 0;

    for($j = 0; $j < $n; $j++)
        $sumH += $arr[$i0][$j];

    for($i = 0; $i < $n; $i++)
        $sumV += $arr[$i][$j0];

    if($sumV > $sumH)
        return true;
}

for($i = 0; $i < $n; $i++)
{
    $arr[$i] = array();

    $line = fgets(STDIN);
    $exp = @explode(' ', $line);

    for($j = 0; $j < $n; $j++)
        $arr[$i][$j] = $exp[$j];
}

for($i = 0; $i < $n; $i++)
    for($j = 0; $j < $n; $j++)
        if(check($i, $j))
            $count++;

echo $count;
?>

<?php
$input='';
while($s=fgets(STDIN)){
$input.=$s;
}
$mas=preg_split('|\n|', $input);
$n=$mas[0];
array_splice($mas,0,1);
$mx=array();
$rsr=array();
$rss=array();
$mxr=0;
$mxs=0;
foreach ($mas as $id=>$st){
    $str=preg_split('| |', $st);
    foreach ($str as $idd=>$rec){
        $mx[$mxr][$mxs]=$rec;
        $mxs++;
    }
    $mxs=0;
    $mxr++;
}

$output2=0;
$asr=0;
$ass=0;
for ($r = 0; $r <=$n-1; $r++) {
    for ($s = 0; $s<=$n-1; $s++) {
        $ass=0;
        $asr=0;
        for ($ss = 0; $ss<=$n-1; $ss++) {
            $asr=$asr+$mx[$r][$ss];
            $ass=$ass+$mx[$ss][$s];
        }
        if($ass>$asr){$output2++;}
    }
}
echo $output2;
?>

<?php
$input='';
while($s=fgets(STDIN)){
$input.=$s;
}
$mas=preg_split('|\n|', $input);
$n=$mas[0];
array_splice($mas,0,1);
$mx=array();
$rsr=array();
$rss=array();
$mxr=0;
$mxs=0;
foreach ($mas as $id=>$st){
    $str=preg_split('| |', $st);
    foreach ($str as $idd=>$rec){
        $mx[$mxr][$mxs]=$rec;
        $mxs++;
    }
    $mxs=0;
    $mxr++;
}

$output=0;
$asr=0;
$ass=0;
for ($r = 0; $r <=$n-1; $r++) {
    for ($s = 0; $s<=$n-1; $s++) {
        $ass=0;
        $asr=0;
        for ($ss = 0; $ss<=$n-1; $ss++) {
            $asr=$asr+$mx[$r][$ss];
            $ass=$ass+$mx[$ss][$s];
        }
        if($ass>$asr){$output++;}
    }
}
echo $output;
?>

<?
$input='';
while($s=fgets(STDIN)){
$input.=$s;
}
$mas=preg_split('|\n|', $input);
$n=$mas[0];
array_splice($mas,0,1);
$mx=array();
$rsr=array();
$rss=array();
$mxr=0;
$mxs=0;
foreach ($mas as $id=>$st){
    $str=preg_split('| |', $st);
    foreach ($str as $idd=>$rec){
        $mx[$mxr][$mxs]=$rec;
        $mxs++;
    }
    $mxs=0;
    $mxr++;
}

$output2=0;
$asr=0;
$ass=0;
for ($r = 0; $r <=$n-1; $r++) {
    for ($s = 0; $s<=$n-1; $s++) {
        $ass=0;
        $asr=0;
        for ($ss = 0; $ss<=$n-1; $ss++) {
            $asr=$asr+$mx[$r][$ss];
            $ass=$ass+$mx[$ss][$s];
        }
        if($ass>$asr){$output2++;}
    }
}
echo $output2;
?>

<?
$stdin = fopen('php://stdin', 'r');
$lines = stream_get_contents($stdin);
$mas= explode("\n", $lines);

$n=$mas[0];
array_splice($mas,0,1);
$mx=array();
$rsr=array();
$rss=array();
$mxr=0;
$mxs=0;
foreach ($mas as $id=>$st){
    $str=preg_split('| |', $st);
    foreach ($str as $idd=>$rec){
        $mx[$mxr][$mxs]=$rec;
        $mxs++;
    }
    $mxs=0;
    $mxr++;
}

$output2=0;
$asr=0;
$ass=0;
for ($r = 0; $r <=$n-1; $r++) {
    for ($s = 0; $s<=$n-1; $s++) {
        $ass=0;
        $asr=0;
        for ($ss = 0; $ss<=$n-1; $ss++) {
            $asr=$asr+$mx[$r][$ss];
            $ass=$ass+$mx[$ss][$s];
        }
        if($ass>$asr){$output2++;}
    }
}
echo $output2;
?>

<?
$stdin = fopen('php://stdin', 'r');
$lines = stream_get_contents($stdin);

$lines=explode("\n", $lines);

$n=$lines[0];

for ($l=1; $l<=$n; $l++)
{
    $line=trim($lines[$l]);
    $numbers_in_line=explode(" ", $line);
    //Сумма в линии $l
    $sum_line[$l-1]=array_sum($numbers_in_line);
    for ($c=0; $c<$n; $c++)
        $sum_col[$c]+=$numbers_in_line[$c];
}
$good=0;
for ($l=1; $l<=$n; $l++)
{
    for ($c=0; $c<$n; $c++)
        if ($sum_col[$c]>$sum_line[$l-1])
            $good++;
}

echo $good;
?>

<?php
error_reporting(0);

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

	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			$inp_num = $Scanner->Scan();
			$inp_row[$i][] = $inp_num;
			$row_sum[$i] += $inp_num;
			$col_sum[$j] += $inp_num;
		}
	}

	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			//if($row_sum[$i] > $col_sum[$j]) $count++;
			if($row_sum[$i] < $col_sum[$j]) $count++;
		}
	}
	printf("%d", $count);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

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

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

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

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

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

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

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

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

<?php
error_reporting(0);

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

	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			$inp_num = $Scanner->Scan();
			$inp_row[$i][] = $inp_num;
			$row_sum[$i] += $inp_num;
		}
	}
	$col_sum = array();
	for ($k = 0; $k < $inp_n; $k++) {
		for ($l = 0; $l < $inp_n; $l++) {
			$col_sum[$k] += $inp_row[$l][$k];
		}
	}

	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			if($row_sum[$i] > $col_sum[$j]) $count++;
		}
	}
	printf("%d", $count);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

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

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

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

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

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

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

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

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

<?php
error_reporting(0);

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

	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			$inp_num = $Scanner->Scan();
			$inp_row[$i][] = $inp_num;
			$row_sum[$i] += $inp_num;
		}
	}
	$col_sum = array();
	for ($k = 0; $k < $inp_n; $k++) {
		for ($l = 0; $l < $inp_n; $l++) {
			$col_sum[$k] += $inp_row[$l][$k];
		}
	}

	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			//if($row_sum[$i] > $col_sum[$j]) $count++;
			if($row_sum[$i] < $col_sum[$j]) $count++;
		}
	}
	printf("%d", $count);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

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

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

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

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

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

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

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

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

<?php
error_reporting(0);

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

	$inp_n = $Scanner->Scan();
	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			$inp_num = $Scanner->Scan();
			$inp_row[$i][] = $inp_num;
			$row_sum[$i] += $inp_num;
		}
	}
	$col_sum = array();
	for ($k = 0; $k < $inp_n; $k++) {
		for ($l = 0; $l < $inp_n; $l++) {
			$col_sum[$k] += $inp_row[$l][$k];
		}
	}

	for ($i = 0; $i < $inp_n; $i++) {
		for ($j = 0; $j < $inp_n; $j++) {
			if($row_sum[$i] > $col_sum[$j]) $count++;
		}
	}
	printf("%d", $count);

	$Scanner->close();

}

function run(){
	solve();
}

ob_end_clean();
run();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	function close(){
		fclose($this->Stream);
	}
}
*/
/*
class Token{
	private $token;
	private $tok;

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

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

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

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

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

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
/*
function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}
*/

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

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

<?
error_reporting(0);

$fp = fopen("php://stdin",'r');
$countMatr = (int)(str_replace( "\r\n", '', fgets($fp)));

$sumRows = array();
$sumCols = array();
$i = 0;
while( $countMatr-- ){
	$points = explode(" ", trim( str_replace( "\r\n", '', fgets($fp)) ) );
	foreach( $points as $key => $value )
	{
		$sumRows[$i] += $value;
		$sumCols[$key] += $value;
	}
	$i++;
}

$res = 0;
foreach( $sumRows as $rowsVal ){
	foreach( $sumCols as $colsVal ){
		if( $rowsVal > $colsVal ){
			$res++;
		}
	}
}
echo $res;
fclose($fp);
?>

<?
error_reporting(0);

$fp = fopen("php://stdin",'r');
$countMatr = (int)(str_replace( "\r\n", '', fgets($fp)));

$sumRows = array();
$sumCols = array();
$i = 0;
while( $countMatr-- ){
	$points = explode(" ", trim( str_replace( "\r\n", '', fgets($fp)) ) );
	foreach( $points as $key => $value )
	{
		$sumRows[$i] += $value;
		$sumCols[$key] += $value;
	}
	$i++;
}

$res = 0;
foreach( $sumRows as $key1 => $rowsVal ){
	foreach( $sumCols as $key2 => $colsVal ){
		if( $colsVal > $rowsVal ){
			echo $key1 . ' ' . $key2 . "\n";
			$res++;
		}
	}
}
echo $res;
fclose($fp);
?>

<?php

$str = file_get_contents('php://stdin');
//$str = file_get_contents('STDIN');

$s = explode("\n", $str);

$lines = array();

foreach ($s as $k=>$v) {
	if ($k == 0) {
		$size = $v;
	} else {
		$l = explode(" ", $v);
		$lines[] = $l;
		//$sum_x[] = array_sum($l);
	}
}

echo '<pre>';

$wins = 0;
$x = $y = array();
for ($i = 0; $i < $size; $i++) {
	$sum_x = array_sum($lines[$i]);
	$sum_y = 0;
	for ($n = 0; $n < $size; $n++) {
		$sum_y += $lines[$n][$i];
	}

	$x[] = $sum_x;
	$y[] = $sum_y;

}

foreach ($x as $k=>$v) {
	for ($i = 0; $i < $size; $i++) {
		if ($v < $y[$i]) {
			$wins++;
		}
	}
}

printf('%s', $wins);

<?php
$input='';
$mas=preg_split('|\n|', $input);
$n=$mas[1];
array_splice($mas,0,2);
array_splice($mas,count($mas)-1,1);
$mx=array();
$rsr=array();
$rss=array();
$mxr=0;
$mxs=0;
foreach ($mas as $id=>$st){
    $str=preg_split('| |', $st);
    foreach ($str as $idd=>$rec){
        $mx[$mxr][$mxs]=$rec;
        $mxs++;
    }
    $mxs=0;
    $mxr++;
}

$output=0;
$asr=0;
$ass=0;
for ($r = 0; $r <=$n-1; $r++) {
    for ($s = 0; $s<=$n-1; $s++) {
        $ass=0;
        $asr=0;
        for ($ss = 0; $ss<=$n-1; $ss++) {
            $asr=$asr+$mx[$r][$ss];
            $ass=$ass+$mx[$ss][$s];
        }
        if($ass>$asr){$output++;}
    }
}
echo $output;
?>

<?
$stdin = fopen('php://stdin', 'r');
$lines = stream_get_contents($stdin);

$lines=explode("\n", $lines);

$n=$lines[0];

for ($l=1; $l<=$n; $l++)
{
    $line=trim($lines[$l]);
    $numbers_in_line=explode(" ", $line);
    //Сумма в линии $l
    $sum_line[$l-1]=array_sum($numbers_in_line);
    for ($c=0; $c<$n; $c++)
        $sum_col[$c]+=$numbers_in_line[$c];
}

for ($l=1; $l<=$n; $l++)
{
    for ($c=0; $c<$n; $c++)
        if ($sum_col[$c]>$sum_line[$l-1])
            $good++;
}

echo $good;
?>


There are $$$n$$$ candies in a row, they are numbered from left to right from $$$1$$$ to $$$n$$$. The size of the $$$i$$$-th candy is $$$a_i$$$.Alice and Bob play an interesting and tasty game: they eat candy. Alice will eat candy from left to right, and Bob — from right to left. The game ends if all the candies are eaten.The process consists of moves. During a move, the player eats one or more sweets from her/his side (Alice eats from the left, Bob — from the right).Alice makes the first move. During the first move, she will eat $$$1$$$ candy (its size is $$$a_1$$$). Then, each successive move the players alternate — that is, Bob makes the second move, then Alice, then again Bob and so on.On each move, a player counts the total size of candies eaten during the current move. Once this number becomes strictly greater than the total size of candies eaten by the other player on their previous move, the current player stops eating and the move ends. In other words, on a move, a player eats the smallest possible number of candies such that the sum of the sizes of candies eaten on this move is strictly greater than the sum of the sizes of candies that the other player ate on the previous move. If there are not enough candies to make a move this way, then the player eats up all the remaining candies and the game ends.For example, if $$$n=11$$$ and $$$a=[3,1,4,1,5,9,2,6,5,3,5]$$$, then:  move 1: Alice eats one candy of size $$$3$$$ and the sequence of candies becomes $$$[1,4,1,5,9,2,6,5,3,5]$$$.  move 2: Alice ate $$$3$$$ on the previous move, which means Bob must eat $$$4$$$ or more. Bob eats one candy of size $$$5$$$ and the sequence of candies becomes $$$[1,4,1,5,9,2,6,5,3]$$$.  move 3: Bob ate $$$5$$$ on the previous move, which means Alice must eat $$$6$$$ or more. Alice eats three candies with the total size of $$$1+4+1=6$$$ and the sequence of candies becomes $$$[5,9,2,6,5,3]$$$.  move 4: Alice ate $$$6$$$ on the previous move, which means Bob must eat $$$7$$$ or more. Bob eats two candies with the total size of $$$3+5=8$$$ and the sequence of candies becomes $$$[5,9,2,6]$$$.  move 5: Bob ate $$$8$$$ on the previous move, which means Alice must eat $$$9$$$ or more. Alice eats two candies with the total size of $$$5+9=14$$$ and the sequence of candies becomes $$$[2,6]$$$.  move 6 (the last): Alice ate $$$14$$$ on the previous move, which means Bob must eat $$$15$$$ or more. It is impossible, so Bob eats the two remaining candies and the game ends. Print the number of moves in the game and two numbers:  $$$a$$$ — the total size of all sweets eaten by Alice during the game;  $$$b$$$ — the total size of all sweets eaten by Bob during the game.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases in the input. The following are descriptions of the $$$t$$$ test cases. Each test case consists of two lines. The first line contains an integer $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of candies. The second line contains a sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$) — the sizes of candies in the order they are arranged from left to right. It is guaranteed that the sum of the values of $$$n$$$ for all sets of input data in a test does not exceed $$$2\cdot10^5$$$.

For each set of input data print three integers — the number of moves in the game and the required values $$$a$$$ and $$$b$$$.

<?php
    define("MAXN", 1024) ;

    function solve($n, $k)
    {
    }

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

        $candy = explode(" ", fgets(STDIN)) ;

        for($i = 0; $i < $n; $i ++) $candy[$i] = intval($candy[$i]) ;

        $step = 0 ;
        $a_eat = 0 ;
        $b_eat = 0 ;

        $l = 0;
        $r = $n - 1 ;
        $now_eat = 0 ;
        $now_u = 0 ;

        while($l <= $r)
        {
            $step ++ ;

            if($now_u == 0)
            {
                // Alice
                $eat = 0 ;
                for($i = $l; $i <= $r; $i ++)
                {
                    $eat += $candy[$i] ;

                    if($eat > $now_eat)
                    {

                        $l = $i + 1 ;
                        $now_eat = $eat ;
                        $a_eat += $eat ;
                        $now_u = 1 ;
                        break ;
                    }
                }

                if($i > $r)
                {
                    $l = $r + 1 ;
                    $now_eat = $eat ;
                    $a_eat += $eat ;
                    $now_u = 1 ;
                }
            }
            else
            {
                // Bob
                $eat = 0 ;
                for($i = $r; $i >= $l; $i --)
                {
                    $eat += $candy[$i] ;

                    if($eat > $now_eat)
                    {

                        $r = $i - 1 ;
                        $now_eat = $eat ;
                        $b_eat += $eat ;
                        $now_u = 0 ;
                        break ;
                    }
                }

                if($i < $l)
                {
                    $r = $l - 1 ;
                    $now_eat = $eat ;
                    $b_eat += $eat ;
                    $now_u = 0 ;
                }
            }
        }

        echo $step . " " . $a_eat . " " . $b_eat . "\n" ;
    }
?>


Valera takes part in the Berland Marathon. The marathon race starts at the stadium that can be represented on the plane as a square whose lower left corner is located at point with coordinates (0, 0) and the length of the side equals a meters. The sides of the square are parallel to coordinate axes.As the length of the marathon race is very long, Valera needs to have extra drink during the race. The coach gives Valera a bottle of drink each d meters of the path. We know that Valera starts at the point with coordinates (0, 0) and runs counter-clockwise. That is, when Valera covers a meters, he reaches the point with coordinates (a, 0). We also know that the length of the marathon race equals nd + 0.5 meters. Help Valera's coach determine where he should be located to help Valera. Specifically, determine the coordinates of Valera's positions when he covers d, 2·d, ..., n·d meters.

The first line contains two space-separated real numbers a and d (1 ≤ a, d ≤ 105), given with precision till 4 decimal digits after the decimal point. Number a denotes the length of the square's side that describes the stadium. Number d shows that after each d meters Valera gets an extra drink. The second line contains integer n (1 ≤ n ≤ 105) showing that Valera needs an extra drink n times.

Print n lines, each line should contain two real numbers xi and yi, separated by a space. Numbers xi and yi in the i-th line mean that Valera is at point with coordinates (xi, yi) after he covers i·d meters. Your solution will be considered correct if the absolute or relative error doesn't exceed 10 - 4. Note, that this problem have huge amount of output data. Please, do not use cout stream for output in this problem.

<?php
define('LOCAL_ENV', false);
if (LOCAL_ENV) {
    error_reporting(E_ALL & !E_NOTICE);
//    $test = <<<INPUT
//4.147 2.8819
//6
//INPUT;
    $test = <<<INPUT
97591.0354 49021.4126
2000

INPUT;
    $stdin = fopen('php://temp/in', 'rw');
    fwrite($stdin, $test);
    rewind($stdin);
} else {
    error_reporting(0);
    $stdin = STDIN;
}
define('MY_STDIN', $stdin);
define('BASE', 10000);

list($a,$d) = explode(' ', trim(fgets(MY_STDIN)));
$pa = $a; $pd = $d;
$n = (int) trim(fgets(MY_STDIN));
$a = (int) ($a * BASE + 0.5); $d = (int) ($d * BASE + 0.5);
$a4 = $a * 4;
$cur = 0;
for ($i = 0; $i < $n; $i++) {
    $cur = bcadd($cur, $d); $cur = bcmod($cur, $a4);
    $o = bcdiv($cur, $a, 0); $m = bcmod($cur, $a);
    if ( ($m == 0) && ($o > 0)) {
        $o--;
        $m = $a;
    }
    switch ($o) {
        case 0:
            $ret .= bcdiv($m, BASE, 5) . " 0.0\n";
            break;
        case 1:
            $ret .= $pa . ' ' . bcdiv($m, BASE, 5) . "\n";
            break;
        case 2:
            $ret .= bcdiv(bcsub($a, $m), BASE, 5) . ' ' . $pa . "\n";
            break;
        case 3:
            $ret .= '0.0 ' . bcdiv(bcsub($a,$m), BASE, 5) . "\n";
            break;
    }
}
echo $ret;

<?php
function move($val, $d){

}
$f = fopen( 'php://stdin', 'r' );
$ar = explode(' ',fgets($f));
$a = $ar[0];
$d = $ar[1];
$n = fgets($f);
$i = 1;
$x = 0;
$y = 0;
$direct = 1;
while($i <= $n){
    $length=$i*$d;
    $mod = floor($length / $a) - floor(floor($length / $a) / 4) * 4;
    $add = $length - floor($length / $a) * $a;
    switch ($mod) {
        case 0:
            echo "\n".number_format($add,'4','.','').' '.number_format(0,'4','.','');
            break;
        case 1:
            echo "\n".number_format($a,'4','.','').' '.number_format($add,'4','.','');
            break;
        case 2:
            echo "\n".number_format($a-$add,'4','.','').' '.number_format($a,'4','.','');
            break;
        case 3:
            echo "\n".number_format(0,'4','.','').' '.number_format($a-$add,'4','.','');
            break;
    }
   $i++;
}

<?php
define('LOCAL_ENV', false);
if (LOCAL_ENV) {
    error_reporting(E_ALL & !E_NOTICE);
//    $test = <<<INPUT
//4.147 2.8819
//6
//INPUT;
    $test = <<<INPUT
4.147 2.8819
6
INPUT;
    $stdin = fopen('php://temp/in', 'rw');
    fwrite($stdin, $test);
    rewind($stdin);
} else {
    error_reporting(0);
    $stdin = STDIN;
}
define('MY_STDIN', $stdin);
define('BASE', 10000);

list($a,$d) = explode(' ', trim(fgets(MY_STDIN)));
$n = (int) trim(fgets(MY_STDIN));
$a = (int) ($a * BASE); $d = (int) ($d * BASE);
$a4 = $a * 4;

$cur = 0;
for ($i = 0; $i < $n; $i++) {
    $cur += $d; $cur %= $a4;
    $o = floor($cur / $a); $m = $cur % $a;
    if ( ($m == 0) && ($o > 0)) {
        $o--;
        $m = $a;
    }
    switch ($o) {
        case 0:
            $ret .= sprintf("%0.5f", ($m / BASE)) . " 0.0\n";
            break;
        case 1:
            $ret .= sprintf("%0.5f", ($a / BASE)) . ' ' . sprintf("%0.5f", ($m / BASE)) . "\n";
            break;
        case 2:
            $ret .= sprintf("%0.5f", ($a - $m) / BASE) . ' ' . sprintf("%0.5f", ($a / BASE)) . "\n";
            break;
        case 3:
            $ret .= '0.0 ' . sprintf("%0.5f", ($a - $m) / BASE) . "\n";
            break;
    }
}
echo $ret;

<?php
define('LOCAL_ENV', false);
if (LOCAL_ENV) {
    error_reporting(E_ALL & !E_NOTICE);
//    $test = <<<INPUT
//4.147 2.8819
//6
//INPUT;
    $test = <<<INPUT
3 3
20
INPUT;
    $stdin = fopen('php://temp/in', 'rw');
    fwrite($stdin, $test);
    rewind($stdin);
} else {
    error_reporting(0);
    $stdin = STDIN;
}
define('MY_STDIN', $stdin);
define('BASE', 100000);

list($a,$d) = explode(' ', trim(fgets(MY_STDIN)));
$n = (int) trim(fgets(MY_STDIN));
$a = (int) ($a * BASE); $d = (int) ($d * BASE);
$a4 = $a * 4;

$cur = 0;
for ($i = 0; $i < $n; $i++) {
    $cur += $d; $cur %= $a4;
    $o = floor($cur / $a); $m = $cur % $a;
    if ( ($m == 0) && ($o > 0)) {
        $o--;
        $m = $a;
    }
    switch ($o) {
        case 0:
            $ret .= ($m / BASE) . " 0.0\n";
            break;
        case 1:
            $ret .= ($a / BASE) . ' ' . ($m / BASE) . "\n";
            break;
        case 2:
            $ret .= ( ($a - $m) / BASE) . ' ' . ($a / BASE) . "\n";
            break;
        case 3:
            $ret .= '0.0 ' . ( ($a - $m) / BASE) . "\n";
            break;
    }
}
echo $ret;

<?php
define('LOCAL_ENV', false);
if (LOCAL_ENV) {
    error_reporting(E_ALL & !E_NOTICE);
//    $test = <<<INPUT
//4.147 2.8819
//6
//INPUT;
    $test = <<<INPUT
40356.3702 72886.7142
100
INPUT;
    $stdin = fopen('php://temp/in', 'rw');
    fwrite($stdin, $test);
    rewind($stdin);
} else {
    error_reporting(0);
    $stdin = STDIN;
}
define('MY_STDIN', $stdin);
define('BASE', 10000);

list($a,$d) = explode(' ', trim(fgets(MY_STDIN)));
$pa = $a; $pd = $d;
$n = (int) trim(fgets(MY_STDIN));
$a = (int) ($a * BASE); $d = (int) ($d * BASE);
$a4 = $a * 4;
$cur = 0;
for ($i = 0; $i < $n; $i++) {
    $cur = bcadd($cur, $d); $cur = bcmod($cur, $a4);
    $o = bcdiv($cur, $a, 0); $m = bcmod($cur, $a);
    if ( ($m == 0) && ($o > 0)) {
        $o--;
        $m = $a;
    }
    switch ($o) {
        case 0:
            $ret .= bcdiv($m, BASE, 5) . " 0.0\n";
            break;
        case 1:
            $ret .= $pa . ' ' . bcdiv($m, BASE, 5) . "\n";
            break;
        case 2:
            $ret .= bcdiv(bcsub($a, $m), BASE, 5) . ' ' . $pa . "\n";
            break;
        case 3:
            $ret .= '0.0 ' . bcdiv(bcsub($a,$m), BASE, 5) . "\n";
            break;
    }
}
echo $ret;

<?php
define('LOCAL_ENV', false);
if (LOCAL_ENV) {
    error_reporting(E_ALL & !E_NOTICE);
//    $test = <<<INPUT
//4.147 2.8819
//6
//INPUT;
    $test = <<<INPUT
4.147 2.8819
6
INPUT;
    $stdin = fopen('php://temp/in', 'rw');
    fwrite($stdin, $test);
    rewind($stdin);
} else {
    error_reporting(0);
    $stdin = STDIN;
}
define('MY_STDIN', $stdin);
define('BASE', 20000);

list($a,$d) = explode(' ', trim(fgets(MY_STDIN)));
$n = (int) trim(fgets(MY_STDIN));
$a = (int) ($a * BASE); $d = (int) ($d * BASE);
$a4 = $a * 4;

$cur = 0;
for ($i = 0; $i < $n; $i++) {
    $cur += $d; $cur %= $a4;
    $o = floor($cur / $a); $m = $cur % $a;
    if ( ($m == 0) && ($o > 0)) {
        $o--;
        $m = $a;
    }
    switch ($o) {
        case 0:
            $ret .= sprintf("%0.4f", ($m / BASE)) . " 0.0\n";
            break;
        case 1:
            $ret .= sprintf("%0.4f", ($a / BASE)) . ' ' . sprintf("%0.4f", ($m / BASE)) . "\n";
            break;
        case 2:
            $ret .= sprintf("%0.4f", ($a - $m) / BASE) . ' ' . sprintf("%0.4f", ($a / BASE)) . "\n";
            break;
        case 3:
            $ret .= '0.0 ' . sprintf("%0.4f", ($a - $m) / BASE) . "\n";
            break;
    }
}
echo $ret;

<?php
define('LOCAL_ENV', false);
if (LOCAL_ENV) {
    error_reporting(E_ALL & !E_NOTICE);
//    $test = <<<INPUT
//4.147 2.8819
//6
//INPUT;
    $test = <<<INPUT
3 5
100
INPUT;
    $stdin = fopen('php://temp/in', 'rw');
    fwrite($stdin, $test);
    rewind($stdin);
} else {
    error_reporting(0);
    $stdin = STDIN;
}
define('MY_STDIN', $stdin);
define('BASE', 10000);

list($a,$d) = explode(' ', trim(fgets(MY_STDIN)));
$n = (int) trim(fgets(MY_STDIN));
$a = (int) ($a * BASE); $d = (int) ($d * BASE);
$a4 = $a * 4;

$cur = 0;
for ($i = 0; $i < $n; $i++) {
    $cur += $d; $cur %= $a4;
    $o = floor($cur / $a + 0.01); $m = $cur % $a;
    if ( ($m == 0) && ($o > 0)) {
        $o--;
        $m = $a;
    }
    switch ($o) {
        case 0:
            $ret .= sprintf("%0.5f", ($m / BASE)) . " 0.0\n";
            break;
        case 1:
            $ret .= sprintf("%0.5f", ($a / BASE)) . ' ' . sprintf("%0.5f", ($m / BASE)) . "\n";
            break;
        case 2:
            $ret .= sprintf("%0.5f", ($a - $m) / BASE) . ' ' . sprintf("%0.5f", ($a / BASE)) . "\n";
            break;
        case 3:
            $ret .= '0.0 ' . sprintf("%0.5f", ($a - $m) / BASE) . "\n";
            break;
    }
}
echo $ret;

<?php
define('LOCAL_ENV', false);
if (LOCAL_ENV) {
    error_reporting(E_ALL & !E_NOTICE);
//    $test = <<<INPUT
//4.147 2.8819
//6
//INPUT;
    $test = <<<INPUT
3 5
100
INPUT;
    $stdin = fopen('php://temp/in', 'rw');
    fwrite($stdin, $test);
    rewind($stdin);
} else {
    error_reporting(0);
    $stdin = STDIN;
}
define('MY_STDIN', $stdin);
define('BASE', 10000);

list($a,$d) = explode(' ', trim(fgets(MY_STDIN)));
$n = (int) trim(fgets(MY_STDIN));
$a = (int) ($a * BASE + 0.5); $d = (int) ($d * BASE + 0.5);
$a4 = $a * 4;

$cur = 0;
for ($i = 0; $i < $n; $i++) {
    $cur += $d; $cur %= $a4;
    $o = floor($cur / $a + 0.05); $m = $cur % $a;
    if ( ($m == 0) && ($o > 0)) {
        $o--;
        $m = $a;
    }
    switch ($o) {
        case 0:
            $ret .= sprintf("%0.5f", ($m / BASE)) . " 0.0\n";
            break;
        case 1:
            $ret .= sprintf("%0.5f", ($a / BASE)) . ' ' . sprintf("%0.5f", ($m / BASE)) . "\n";
            break;
        case 2:
            $ret .= sprintf("%0.5f", ($a - $m) / BASE) . ' ' . sprintf("%0.5f", ($a / BASE)) . "\n";
            break;
        case 3:
            $ret .= '0.0 ' . sprintf("%0.5f", ($a - $m) / BASE) . "\n";
            break;
    }
}
echo $ret;

<?php
define('LOCAL_ENV', false);
if (LOCAL_ENV) {
    error_reporting(E_ALL & !E_NOTICE);
//    $test = <<<INPUT
//4.147 2.8819
//6
//INPUT;
    $test = <<<INPUT
4.147 2.8819
6
INPUT;
    $stdin = fopen('php://temp/in', 'rw');
    fwrite($stdin, $test);
    rewind($stdin);
} else {
    error_reporting(0);
    $stdin = STDIN;
}
define('MY_STDIN', $stdin);
define('BASE', 20000);

list($a,$d) = explode(' ', trim(fgets(MY_STDIN)));
$n = (int) trim(fgets(MY_STDIN));
$a = (int) ($a * BASE); $d = (int) ($d * BASE);
$a4 = $a * 4;

$cur = 0;
for ($i = 0; $i < $n; $i++) {
    $cur += $d; $cur %= $a4;
    $o = floor($cur / $a); $m = $cur % $a;
    if ( ($m == 0) && ($o > 0)) {
        $o--;
        $m = $a;
    }
    switch ($o) {
        case 0:
            $ret .= ($m / BASE) . " 0.0\n";
            break;
        case 1:
            $ret .= ($a / BASE) . ' ' . ($m / BASE) . "\n";
            break;
        case 2:
            $ret .= ( ($a - $m) / BASE) . ' ' . ($a / BASE) . "\n";
            break;
        case 3:
            $ret .= '0.0 ' . ( ($a - $m) / BASE) . "\n";
            break;
    }
}
echo $ret;


The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively.Polycarpus has found a job, he is a system administrator. One day he came across n IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separated by dots. For example, the record 0.255.1.123 shows a correct IP address and records 0.256.1.123 and 0.255.1.01 do not. In this problem an arbitrary group of four 8-bit numbers is a correct IP address.Having worked as an administrator for some time, Polycarpus learned that if you know the IP address, you can use the subnet mask to get the address of the network that has this IP addess.The subnet mask is an IP address that has the following property: if we write this IP address as a 32 bit string, that it is representable as "11...11000..000". In other words, the subnet mask first has one or more one bits, and then one or more zero bits (overall there are 32 bits). For example, the IP address 2.0.0.0 is not a correct subnet mask as its 32-bit record looks as 00000010000000000000000000000000.To get the network address of the IP address, you need to perform the operation of the bitwise "and" of the IP address and the subnet mask. For example, if the subnet mask is 255.192.0.0, and the IP address is 192.168.1.2, then the network address equals 192.128.0.0. In the bitwise "and" the result has a bit that equals 1 if and only if both operands have corresponding bits equal to one.Now Polycarpus wants to find all networks to which his IP addresses belong. Unfortunately, Polycarpus lost subnet mask. Fortunately, Polycarpus remembers that his IP addresses belonged to exactly k distinct networks. Help Polycarpus find the subnet mask, such that his IP addresses will belong to exactly k distinct networks. If there are several such subnet masks, find the one whose bit record contains the least number of ones. If such subnet mask do not exist, say so.

The first line contains two integers, n and k (1 ≤ k ≤ n ≤ 105) — the number of IP addresses and networks. The next n lines contain the IP addresses. It is guaranteed that all IP addresses are distinct.

In a single line print the IP address of the subnet mask in the format that is described in the statement, if the required subnet mask exists. Otherwise, print -1.

<?

list($n, $k) = explode(" ", fgets(STDIN));

$masks = array();
$i = 0;
while($i++ < 32) {
    $masks[] = str_repeat(1, $i) . str_repeat(0, 32 - $i);
}

$ips = array();
while($n--) {
    $ip = fgets(STDIN);
    $tmp = explode(".", $ip);
    $ips[] = sprintf("%08b%08b%08b%08b", $tmp[0], $tmp[1], $tmp[2], $tmp[3]);
}

foreach($masks as $mask) {
    $res = array();
    foreach($ips as $ip) {
        $network = $mask & $ip;
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(sprintf("%d.%d.%d.%d", bindec(substr($mask, 0, 8)), bindec(substr($mask, 8, 8)), bindec(substr($mask, 16, 8)), bindec(substr($mask, 24, 8))));
    }
}
die("-1");

<?

list($n, $k) = explode(" ", fgets(STDIN));

$masks_tmp = array(128, 192, 224, 240, 248, 252, 254, 255);

$masks = array();
foreach($masks_tmp as $mask)
    $masks[] = array($mask, 0, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, $mask, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, $mask, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, 255, $mask);

$ips = array();
while($n--) {
    $ips[] = explode(".",  fgets(STDIN));
}

$start = floor(sqrt($k)) - 1;
for($i = $start; $i < count($masks); $i++) {
    $mask = $masks[$i];
    $res = array();
    foreach($ips as $ip) {
        $network = ($mask[0] & (int)$ip[0]);
        $network .= "." . ($mask[1] & (int)$ip[1]);
        $network .= "." . ($mask[2] & (int)$ip[2]);
        $network .= "." . ($mask[3] & (int)$ip[3]);
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(implode(".", $mask));
    }
}
die("-1");

<?

list($n, $k) = explode(" ", fgets(STDIN));

$masks_tmp = array(128, 192, 224, 240, 248, 252, 254, 255);

$masks = array();
foreach($masks_tmp as $mask)
    $masks[] = array($mask, 0, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, $mask, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, $mask, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, 255, $mask);

$ips = array();
while($n--) {
    //$ips[] = explode(".",  fgets(STDIN));
    $ips[] = mt_rand(0, 255) . "." . mt_rand(0, 255) . "." . mt_rand(0, 255) . "." . mt_rand(0, 255);
}

$start = floor(sqrt($k));
for($i = $start; $i < count($masks); $i++) {
    $mask = $masks[$i];
    $res = array();
    foreach($ips as $ip) {
        $network = ($mask[0] & (int)$ip[0]);
        $network .= "." . ($mask[1] & (int)$ip[1]);
        $network .= "." . ($mask[2] & (int)$ip[2]);
        $network .= "." . ($mask[3] & (int)$ip[3]);
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(implode(".", $mask));
    }
}
die("-1");

<?

list($n, $k) = explode(" ", fgets(STDIN));

$masks_tmp = array(128, 192, 224, 240, 248, 252, 254, 255);

$masks = array();
foreach($masks_tmp as $mask)
    $masks[] = array($mask, 0, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, $mask, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, $mask, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, 255, $mask);

$ips = array();
while($n--) {
    $ips[] = explode(".",  fgets(STDIN));
}

$start = ceil(sqrt($k));
for($i = $start; $i < count($masks); $i++) {
    $mask = $masks[$i];
    $res = array();
    foreach($ips as $ip) {
        $network = ($mask[0] & (int)$ip[0]);
        $network .= "." . ($mask[1] & (int)$ip[1]);
        $network .= "." . ($mask[2] & (int)$ip[2]);
        $network .= "." . ($mask[3] & (int)$ip[3]);
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(implode(".", $mask));
    }
}
die("-1");

<?

list($n, $k) = explode(" ", fgets(STDIN));

$masks_tmp = array(128, 192, 224, 240, 248, 252, 254, 255);

$masks = array();
foreach($masks_tmp as $mask)
    $masks[] = array($mask, 0, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, $mask, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, $mask, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, 255, $mask);

$ips = array();
while($n--) {
    $ips[] = explode(".",  fgets(STDIN));
}

$start = ceil(sqrt($k)) - 1;
for($i = $start; $i < count($masks); $i++) {
    $mask = $masks[$i];
    $res = array();
    foreach($ips as $ip) {
        $network = ($mask[0] & (int)$ip[0]);
        $network .= "." . ($mask[1] & (int)$ip[1]);
        $network .= "." . ($mask[2] & (int)$ip[2]);
        $network .= "." . ($mask[3] & (int)$ip[3]);
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(implode(".", $mask));
    }
}
die("-1");

<?

list($n, $k) = explode(" ", fgets(STDIN));

$masks_tmp = array(128, 192, 224, 240, 248, 252, 254, 255);

$masks = array();
foreach($masks_tmp as $mask)
    $masks[] = array($mask, 0, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, $mask, 0, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, $mask, 0);

foreach($masks_tmp as $mask)
    $masks[] = array(255, 255, 255, $mask);

$ips = array();
while($n--) {
    $ips[] = explode(".",  fgets(STDIN));
}

$start = floor(sqrt($k));
for($i = $start; $i < count($masks); $i++) {
    $mask = $masks[$i];
    $res = array();
    foreach($ips as $ip) {
        $network = ($mask[0] & (int)$ip[0]);
        $network .= "." . ($mask[1] & (int)$ip[1]);
        $network .= "." . ($mask[2] & (int)$ip[2]);
        $network .= "." . ($mask[3] & (int)$ip[3]);
        $res[$network]++;
    }

    if(count($res) == $k) {
        die(implode(".", $mask));
    }
}
die("-1");


Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem:You are given an array $$$a$$$ of $$$n$$$ integers. You are also given an integer $$$k$$$. Lord Omkar wants you to do $$$k$$$ operations with this array.Define one operation as the following:   Set $$$d$$$ to be the maximum value of your array.  For every $$$i$$$ from $$$1$$$ to $$$n$$$, replace $$$a_{i}$$$ with $$$d-a_{i}$$$. The goal is to predict the contents in the array after $$$k$$$ operations. Please help Ray determine what the final sequence will look like!

Each test contains multiple test cases. The first line contains the number of cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 2 \cdot 10^5, 1 \leq k \leq 10^{18}$$$) – the length of your array and the number of operations to perform. The second line of each test case contains $$$n$$$ integers $$$a_{1},a_{2},...,a_{n}$$$ $$$(-10^9 \leq a_{i} \leq 10^9)$$$ – the initial contents of your array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each case, print the final version of array $$$a$$$ after $$$k$$$ operations described above.

NoteIn the first test case the array changes as follows:Initially, the array is $$$[-199, 192]$$$. $$$d = 192$$$.After the operation, the array becomes $$$[d-(-199), d-192] = [391, 0]$$$.


In a galaxy far, far away Lesha the student has just got to know that he has an exam in two days. As always, he hasn't attended any single class during the previous year, so he decided to spend the remaining time wisely.Lesha knows that today he can study for at most $$$a$$$ hours, and he will have $$$b$$$ hours to study tomorrow. Note that it is possible that on his planet there are more hours in a day than on Earth. Lesha knows that the quality of his knowledge will only depend on the number of lecture notes he will read. He has access to an infinite number of notes that are enumerated with positive integers, but he knows that he can read the first note in one hour, the second note in two hours and so on. In other words, Lesha can read the note with number $$$k$$$ in $$$k$$$ hours. Lesha can read the notes in arbitrary order, however, he can't start reading a note in the first day and finish its reading in the second day.Thus, the student has to fully read several lecture notes today, spending at most $$$a$$$ hours in total, and fully read several lecture notes tomorrow, spending at most $$$b$$$ hours in total. What is the maximum number of notes Lesha can read in the remaining time? Which notes should he read in the first day, and which — in the second?

The only line of input contains two integers $$$a$$$ and $$$b$$$ ($$$0 \leq a, b \leq 10^{9}$$$) — the number of hours Lesha has today and the number of hours Lesha has tomorrow.

In the first line print a single integer $$$n$$$ ($$$0 \leq n \leq a$$$) — the number of lecture notes Lesha has to read in the first day. In the second line print $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq a$$$), the sum of all $$$p_i$$$ should not exceed $$$a$$$. In the third line print a single integer $$$m$$$ ($$$0 \leq m \leq b$$$) — the number of lecture notes Lesha has to read in the second day. In the fourth line print $$$m$$$ distinct integers $$$q_1, q_2, \ldots, q_m$$$ ($$$1 \leq q_i \leq b$$$), the sum of all $$$q_i$$$ should not exceed $$$b$$$. All integers $$$p_i$$$ and $$$q_i$$$ should be distinct. The sum $$$n + m$$$ should be largest possible.

NoteIn the first example Lesha can read the third note in $$$3$$$ hours in the first day, and the first and the second notes in one and two hours correspondingly in the second day, spending $$$3$$$ hours as well. Note that Lesha can make it the other way round, reading the first and the second notes in the first day and the third note in the second day.In the second example Lesha should read the third and the sixth notes in the first day, spending $$$9$$$ hours in total. In the second day Lesha should read the first, second fourth and fifth notes, spending $$$12$$$ hours in total.

<?php
$line = trim(fgets(STDIN));
$pieces = explode(" ", $line);
$a = $pieces[0];
$b = $pieces[1];

$first = array();
$second = array();

$hours = $a+$b;

function eq_roots($a, $b, $c) {
    if ($a==0) return false;

    if ($b==0) {
        if ($c<0) {
            $x1 = sqrt(abs($c/$a));
            $x2 = sqrt(abs($c/$a));
        } elseif ($c==0) {
            $x1 = $x2 = 0;
        } else {
            $x1 = sqrt($c/$a).'i';
            $x2 = -sqrt($c/$a).'i';
        }
    } else {
        $d = $b*$b-4*$a*$c;
        if ($d>0) {
            $x1 = (-$b+sqrt($d))/2*$a;
            $x2 = (-$b-sqrt($d))/2*$a;
        } elseif ($d==0) {
            $x1 = $x2 = (-$b)/2*$a;
        } else {
            $x1 = -$b . '+' . sqrt(abs($d)) . 'i';
            $x2 = -$b . '-' . sqrt(abs($d)) . 'i';
        }
    }
    return floor($x1);
}

$n = eq_roots(1, 1, -2*$hours);

if($b == 0) {

} else {
    $second = range(1, $n);
}

$abstract_balance = $a;
for($i=$n;$i>=1;$i--) {
	// 5, 4, 3, 2, 1
	if(($abstract_balance - $i) >= 0) {
		array_push($first, $i);
		$abstract_balance = $abstract_balance - $i;
	}
	if($abstract_balance == 0) {
		break;
	}
}

$second_2 = array_diff($second, $first);

$r1 = count($first);
$r2 = count($second_2);
$arr1 = implode(" ", $first);
$arr2 = implode(" ", $second_2);

echo $r1.PHP_EOL;
echo $arr1.PHP_EOL;
echo $r2.PHP_EOL;
echo $arr2.PHP_EOL;

?>

<?php
$line = trim(fgets(STDIN));
$pieces = explode(" ", $line);
$a = $pieces[0];
$b = $pieces[1];

$first = array();
$second = array();

$hours = $a+$b;

function eq_roots($a, $b, $c) {
    if ($a==0) return false;

    if ($b==0) {
        if ($c<0) {
            $x1 = sqrt(abs($c/$a));
            $x2 = sqrt(abs($c/$a));
        } elseif ($c==0) {
            $x1 = $x2 = 0;
        } else {
            $x1 = sqrt($c/$a).'i';
            $x2 = -sqrt($c/$a).'i';
        }
    } else {
        $d = $b*$b-4*$a*$c;
        if ($d>0) {
            $x1 = (-$b+sqrt($d))/2*$a;
        } elseif ($d==0) {
            $x1 = $x2 = (-$b)/2*$a;
        } else {
            $x1 = -$b . '+' . sqrt(abs($d)) . 'i';
        }
    }
    return floor($x1);
}

$n = eq_roots(1, 1, -2*$hours);

$second = range(1, $n);

$abstract_balance = $a;
for($i=$n;$i>=1;$i--) {
	// 5, 4, 3, 2, 1
	if(($abstract_balance - $i) >= 0) {
		array_push($first, $i);
		$abstract_balance = $abstract_balance - $i;
	}
	if($abstract_balance == 0) {
		break;
	}
}

$second_2 = array_diff($second, $first);

$r1 = count($first);
$r2 = count($second_2);
$arr1 = implode(" ", $first);
$arr2 = implode(" ", $second_2);

echo $r1.PHP_EOL;
echo $arr1.PHP_EOL;
echo $r2.PHP_EOL;
echo $arr2.PHP_EOL;

?>


Positive integer $$$x$$$ is called divisor of positive integer $$$y$$$, if $$$y$$$ is divisible by $$$x$$$ without remainder. For example, $$$1$$$ is a divisor of $$$7$$$ and $$$3$$$ is not divisor of $$$8$$$.We gave you an integer $$$d$$$ and asked you to find the smallest positive integer $$$a$$$, such that  $$$a$$$ has at least $$$4$$$ divisors;  difference between any two divisors of $$$a$$$ is at least $$$d$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 3000$$$) — the number of test cases. The first line of each test case contains a single integer $$$d$$$ ($$$1 \leq d \leq 10000$$$).

For each test case print one integer $$$a$$$ — the answer for this test case.

NoteIn the first test case, integer $$$6$$$ have following divisors: $$$[1, 2, 3, 6]$$$. There are $$$4$$$ of them and the difference between any two of them is at least $$$1$$$. There is no smaller integer with at least $$$4$$$ divisors.In the second test case, integer $$$15$$$ have following divisors: $$$[1, 3, 5, 15]$$$. There are $$$4$$$ of them and the difference between any two of them is at least $$$2$$$.The answer $$$12$$$ is INVALID because divisors are $$$[1, 2, 3, 4, 6, 12]$$$. And the difference between, for example, divisors $$$2$$$ and $$$3$$$ is less than $$$d=2$$$.

<?php

$times = (int) trim(fgets(STDIN));
for ($i = 0; $i < $times; ++$i) {
    $di[] = (int) trim(fgets(STDIN));
}
for ($i = 0; $i < $times; ++$i) {
    $d = &$di[$i];
    for ($j = $d + 1;; ++$j) {
        if (is_prime($j)) {
            $p1 = $j;
            break;
        }
    }
    for ($j = $p1 + $d;; ++$j) {
        if (is_prime($j)) {
            $p2 = $j;
            break;
        }
    }
    echo $p1 * $p2.PHP_EOL;
}
function is_prime($num)
{
    if (2 == $num) {
        return 1;
    }
    if (0 == $num % 2 || $num < 2) {
        return 0;
    }
    for ($i = 3; $i * $i <= $num; $i += 2) {
        if (0 == $num % $i) {
            return 0;
        }
    }

    return 1;
}

<?php

$cap = 20011;

$prime = [];
$realPrime = [];

for ($i = 2; $i <= $cap; ++$i) {
    $prime[$i] = true;
}

for ($i = 2; $i <= $cap; ++$i) {
    if (!$prime[$i]) {
        continue;
    }

    $realPrime[] = $i;

    for ($j = 2; $i * $j < $cap; ++$j) {
        $prime[$i * $j] = false;
    }
}

unset($prime);

$stdin = fopen('php://stdin', 'r');
fscanf(STDIN, "%d\n", $tests);

function binSearch($item, $realPrime){
    $l = 0; $r = count($realPrime) - 1;

    while ($l <= $r){
        $m = floor(($l + $r) / 2);
        if ($realPrime[$m] < $item) {
            $l = $m + 1;
        } elseif ($realPrime[$m] > $item) {
            $r = $m - 1;
        } else {
            return $realPrime[$m];
        }
    }

    return $realPrime[$l];
}

for ($i = 0; $i < $tests; ++$i) {
    fscanf(STDIN, "%d\n", $d);

    $firstPrime = binSearch(1 + $d, $realPrime);
    $secondPrime = binSearch($firstPrime + $d, $realPrime);
    echo $firstPrime * $secondPrime . PHP_EOL;
}

<?php

$times = (int) trim(fgets(STDIN));
for ($i = 0; $i < $times; ++$i) {
    $di[] = (int) trim(fgets(STDIN));
}
for ($i = 0; $i < $times; ++$i) {
    $d = &$di[$i];
    for ($j = $d + 1;; ++$j) {
        if (is_prime($j)) {
            $p1 = $j;
            break;
        }
    }
    for ($j = $p1 + 1;; ++$j) {
        if (is_prime($j)) {
            $p2 = $j;
            break;
        }
    }
    echo $p1 * $p2.PHP_EOL;
}
function is_prime($num)
{
    if (2 == $num) {
        return 1;
    }
    if (0 == $num % 2 || $num < 2) {
        return 0;
    }
    for ($i = 3; $i * $i <= $num; $i += 2) {
        if (0 == $num % $i) {
            return 0;
        }
    }

    return 1;
}

<?php

$times = (int) trim(fgets(STDIN));
for ($i = 0; $i < $times; ++$i) {
    $di[] = (int) trim(fgets(STDIN));
}
for ($i = 0; $i < $times; ++$i) {
    $d = &$di[$i];
    for ($j = $d + 2;; ++$j) {
        if (is_prime($j)) {
            echo ($d + 1) * $j.PHP_EOL;
            break;
        }
    }
}
function is_prime($num)
{
    if (0 == $num % 2 || $num < 2) {
        return 0;
    }
    for ($i = 3; $i * $i <= $num; $i += 2) {
        if (0 == $num % $i) {
            return 0;
        }
    }

    return 1;
}


Arkady is playing Battleship. The rules of this game aren't really important.There is a field of $$$n \times n$$$ cells. There should be exactly one $$$k$$$-decker on the field, i. e. a ship that is $$$k$$$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 100$$$) — the size of the field and the size of the ship. The next $$$n$$$ lines contain the field. Each line contains $$$n$$$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).

Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship. If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.

NoteThe picture below shows the three possible locations of the ship that contain the cell $$$(3, 2)$$$ in the first sample.


Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has $$$n$$$ rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix dollar bills and euro bills in whatever way he wants. The price of one dollar is $$$d$$$ rubles, and one euro costs $$$e$$$ rubles.Recall that there exist the following dollar bills: $$$1$$$, $$$2$$$, $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, and the following euro bills — $$$5$$$, $$$10$$$, $$$20$$$, $$$50$$$, $$$100$$$, $$$200$$$ (note that, in this problem we do not consider the $$$500$$$ euro bill, it is hard to find such bills in the currency exchange points). Andrew can buy any combination of bills, and his goal is to minimize the total number of rubles he will have after the exchange.Help him — write a program that given integers $$$n$$$, $$$e$$$ and $$$d$$$, finds the minimum number of rubles Andrew can get after buying dollar and euro bills.

The first line of the input contains one integer $$$n$$$ ($$$1 \leq n \leq 10^8$$$) — the initial sum in rubles Andrew has.  The second line of the input contains one integer $$$d$$$ ($$$30 \leq d \leq 100$$$) — the price of one dollar in rubles.  The third line of the input contains integer $$$e$$$ ($$$30 \leq e \leq 100$$$) — the price of one euro in rubles.

Output one integer — the minimum number of rubles Andrew can have after buying dollar and euro bills optimally.

NoteIn the first example, we can buy just $$$1$$$ dollar because there is no $$$1$$$ euro bill.In the second example, optimal exchange is to buy $$$5$$$ euro and $$$1$$$ dollar.In the third example, optimal exchange is to buy $$$10$$$ dollars in one bill.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
if($a % $b == 0)
{
     print "0";
}
elseif($a % ($c * 5) == 0)
{
     print "0";
}
elseif($c * 5 < $a)
{
     $d = $a % ($c * 5);
     $e = $d % $b;
     $f = $a % $b;
     print min($e, $f);
}
elseif($c * 5 > $a)
{
     print $a % $b;
}
?>


Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the temple and read the string aloud. However, nothing happened. Then Asterix supposed that a password is some substring t of the string s.Prefix supposed that the substring t is the beginning of the string s; Suffix supposed that the substring t should be the end of the string s; and Obelix supposed that t should be located somewhere inside the string s, that is, t is neither its beginning, nor its end.Asterix chose the substring t so as to please all his companions. Besides, from all acceptable variants Asterix chose the longest one (as Asterix loves long strings). When Asterix read the substring t aloud, the temple doors opened. You know the string s. Find the substring t or determine that such substring does not exist and all that's been written above is just a nice legend.

You are given the string s whose length can vary from 1 to 106 (inclusive), consisting of small Latin letters.

Print the string t. If a suitable t string does not exist, then print "Just a legend" without the quotes.

<?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;

function KMP($s, &$p)
{
    $p[0] = 0;

    for ($i = 1; $i < strlen($s); $i++) {
        $j = $p[$i - 1];

        while ($j && $s[$i] != $s[$j]) {
            $j = $p[$j - 1];
        }

        if ($s[$i] === $s[$j]) {
            $p[$i] = $j + 1;
        } else {
            $p[$i] = $j;
        }
    }
}

function foo($s, &$p)
{
    $l = strlen($s);
    $a = $p[$l - 1];

    while ($a) {
        for ($i = $l - 2; $i >= 0; --$i) {
            if ($p[$i] === $a) {
                break;
            }
        }

        if ($i >= 0) {
            break;
        }

        $a = $p[$a - 1];
    }

    return $a;
}

$r = 0;
$p = [];

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

KMP($s, $p);

$r = foo($s, $p);
$r = $r ? substr($s, 0, $r) : 'Just a legend';

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;

function foo($s)
{
    $result = null;
    $n = strlen($s);
    $sl = (int) ($n / 3) + 1;

    for ($i = 1; $i <= $sl; $i++) {
        $prefix = substr($s, 0, $i);
        $suffix = substr($s, -$i);
        $middle = substr($s, $i, $n - 2 * $i);

        if ($prefix !== $suffix) continue;

        if (substr_count($middle, $prefix) > 0) {
            $result = $prefix;
        }
    }

    return $result;
}

$r = 0;
$keys = [];

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

$r = foo($s) ?: 'Just a legend';

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;

function foo($s)
{
    $result = null;
    $n = strlen($s);
    $sl = (int) ($n / 2) + 1;
    $middle = substr($s, 1, $n - 2);

    for ($i = 1; $i <= $sl; $i++) {
        $prefix = substr($s, 0, $i);
        $suffix = substr($s, -$i);

        if ($prefix !== $suffix) continue;

        if (substr_count($middle, $prefix) > 0) {
            $result = $prefix;
        }
    }

    return $result;
}

$r = 0;
$keys = [];

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

$r = foo($s) ?: 'Just a legend';

fwrite($output, $r);


Polycarp has $$$3$$$ positive integers $$$a$$$, $$$b$$$ and $$$c$$$. He can perform the following operation exactly once.  Choose a positive integer $$$m$$$ and multiply exactly one of the integers $$$a$$$, $$$b$$$ or $$$c$$$ by $$$m$$$. Can Polycarp make it so that after performing the operation, the sequence of three numbers $$$a$$$, $$$b$$$, $$$c$$$ (in this order) forms an arithmetic progression? Note that you cannot change the order of $$$a$$$, $$$b$$$ and $$$c$$$.Formally, a sequence $$$x_1, x_2, \dots, x_n$$$ is called an arithmetic progression (AP) if there exists a number $$$d$$$ (called "common difference") such that $$$x_{i+1}=x_i+d$$$ for all $$$i$$$ from $$$1$$$ to $$$n-1$$$. In this problem, $$$n=3$$$.For example, the following sequences are AP: $$$[5, 10, 15]$$$, $$$[3, 2, 1]$$$, $$$[1, 1, 1]$$$, and $$$[13, 10, 7]$$$. The following sequences are not AP: $$$[1, 2, 4]$$$, $$$[0, 1, 0]$$$ and $$$[1, 3, 2]$$$.You need to answer $$$t$$$ independent test cases.

The first line contains the number $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each of the following $$$t$$$ lines contains $$$3$$$ integers $$$a$$$, $$$b$$$, $$$c$$$ ($$$1 \le a, b, c \le 10^8$$$).

For each test case print "YES" (without quotes) if Polycarp can choose a positive integer $$$m$$$ and multiply exactly one of the integers $$$a$$$, $$$b$$$ or $$$c$$$ by $$$m$$$ to make $$$[a, b, c]$$$ be an arithmetic progression. Print "NO" (without quotes) otherwise. You can print YES and NO in any (upper or lower) case (for example, the strings yEs, yes, Yes and YES will be recognized as a positive answer).

YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES

NoteIn the first and second test cases, you can choose the number $$$m=4$$$ and multiply the second number ($$$b=5$$$) by $$$4$$$.In the first test case the resulting sequence will be $$$[10, 20, 30]$$$. This is an AP with a difference $$$d=10$$$.In the second test case the resulting sequence will be $$$[30, 20, 10]$$$. This is an AP with a difference $$$d=-10$$$.In the third test case, you can choose $$$m=1$$$ and multiply any number by $$$1$$$. The resulting sequence will be $$$[1, 2, 3]$$$. This is an AP with a difference $$$d=1$$$.In the fourth test case, you can choose $$$m=9$$$ and multiply the first number ($$$a=1$$$) by $$$9$$$. The resulting sequence will be $$$[9, 6, 3]$$$. This is an AP with a difference $$$d=-3$$$.In the fifth test case, it is impossible to make an AP.

<?php
// $stdin = fopen('input.txt', 'r');

$solve = function ($a) {

	$aa = 2 * $a[1];
	$c = $aa - $a[2];
	if($c > 0 && $c % $a[0] == 0) return 1;

	$c = $aa - $a[0];
	if($c > 0 && $c % $a[2] == 0) return 3;

	$c = $a[0] + $a[2];
	if($c % $aa == 0) return 2;

	return false;
};

$t = intval(fgets(STDIN));

for (; $t > 0; $t--) {

	$a = array_map('intval', explode(' ', fgets(STDIN)));

	echo $solve($a) ? 'YES':'NO';
	echo "\n";

}

<?php
// $stdin = fopen('input.txt', 'r');

$solve = function ($a) {

	$aa = 2 * $a[1];
	$c = $aa - $a[2];
	if($c > 0 && $c % $a[0] == 0) return 1;

	$c = $aa - $a[0];
	if($c > 0 && $c % $a[2] == 0) return 3;

	$c = $a[0] + $a[2];
	echo $c . ' - ' . $aa. ' - ';
	if($c % $aa == 0) return 2;

	return false;
};

$t = intval(fgets(STDIN));

for (; $t > 0; $t--) {

	$a = array_map('intval', explode(' ', fgets(STDIN)));

	echo $solve($a) ? 'YES':'NO';
	echo "\n";

}

<?php
// $stdin = fopen('input.txt', 'r');

$solve = function ($a) {

	$aa = 2 * $a[1];
	$c = $aa - $a[2];
	if($c > 0 && $c % $a[0] == 0) return 1;

	$c = $aa - $a[0];
	if($c > 0 && $c % $a[2] == 0) return 3;

	$c = $a[0] - $a[2];
	if($c % $aa == 0) return 2;

	return false;
};

$t = intval(fgets(STDIN));

for (; $t > 0; $t--) {

	$a = array_map('intval', explode(' ', fgets(STDIN)));

	echo $solve($a) ? 'YES':'NO';
	echo "\n";

}


Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of the drink and, having come home, he went to bed at once.DravDe dreamt about managing a successful farm. He dreamt that every day one animal came to him and asked him to let it settle there. However, DravDe, being unimaginably kind, could send the animal away and it went, rejected. There were exactly n days in DravDe’s dream and the animal that came on the i-th day, ate exactly ci tons of food daily starting from day i. But if one day the animal could not get the food it needed, it got really sad. At the very beginning of the dream there were exactly X tons of food on the farm.DravDe woke up terrified...When he retold the dream to you, he couldn’t remember how many animals were on the farm by the end of the n-th day any more, but he did remember that nobody got sad (as it was a happy farm) and that there was the maximum possible amount of the animals. That’s the number he wants you to find out. It should be noticed that the animals arrived in the morning and DravDe only started to feed them in the afternoon, so that if an animal willing to join them is rejected, it can’t eat any farm food. But if the animal does join the farm, it eats daily from that day to the n-th.

The first input line contains integers n and X (1 ≤ n ≤ 100, 1 ≤ X ≤ 104) — amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers ci (1 ≤ ci ≤ 300). Numbers in the second line are divided by a space.

Output the only number — the maximum possible amount of animals on the farm by the end of the n-th day given that the food was enough for everybody.

NoteNote to the first example: DravDe leaves the second and the third animal on the farm. The second animal will eat one ton of food on the second day and one ton on the third day. The third animal will eat one ton of food on the third day.

<?php
$input = @fopen("input.txt", "r");
$output = @fopen("output.txt", "w");
list($n, $x) = explode(' ', trim(fgets($input)));
$c = explode(' ', trim(fgets($input)));
for ($i = 0; $i < $n; $i++) {
    $a[$i] = $c[$i] * ($n - $i);
}
sort($a);
$k = 0;
$t = 0;
for ($i = 0; $i < $n; $i++) {
    $t += $a[$i];
    if ($t > $x) {
        $k = $i;
        break;
    }
}
if ($t <= $x) {
    $k = $n;
}
fwrite($output, "$k\n");
fclose($output);


Omkar has received a message from Anton saying "Your story for problem A is confusing. Just make a formal statement." Because of this, Omkar gives you an array $$$a = [a_1, a_2, \ldots, a_n]$$$ of $$$n$$$ distinct integers. An array $$$b = [b_1, b_2, \ldots, b_k]$$$ is called nice if for any two distinct elements $$$b_i, b_j$$$ of $$$b$$$, $$$|b_i-b_j|$$$ appears in $$$b$$$ at least once. In addition, all elements in $$$b$$$ must be distinct. Can you add several (maybe, $$$0$$$) integers to $$$a$$$ to create a nice array $$$b$$$ of size at most $$$300$$$? If $$$a$$$ is already nice, you don't have to add any elements.For example, array $$$[3, 6, 9]$$$ is nice, as $$$|6-3|=|9-6| = 3$$$, which appears in the array, and $$$|9-3| = 6$$$, which appears in the array, while array $$$[4, 2, 0, 6, 9]$$$ is not nice, as $$$|9-4| = 5$$$ is not present in the array.For integers $$$x$$$ and $$$y$$$, $$$|x-y| = x-y$$$ if $$$x > y$$$ and $$$|x-y| = y-x$$$ otherwise.

Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \leq t \leq 50$$$), the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 100$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ distinct integers $$$a_1, a_2, \cdots, a_n$$$ ($$$-100 \leq a_i \leq 100$$$) — the elements of the array $$$a$$$.

For each test case, output one line containing YES if Omkar can create a nice array $$$b$$$ by adding elements to $$$a$$$ and NO otherwise. The case of each letter does not matter, so yEs and nO will also be accepted. If the first line is YES, output a second line containing a single integer $$$k$$$ ($$$n \leq k \leq 300$$$).  Then output one line containing $$$k$$$ distinct integers $$$b_1, b_2, \cdots, b_k$$$ ($$$-10^9 \leq b_i \leq 10^9$$$), the elements of the nice array $$$b$$$. $$$b_1, b_2, \cdots, b_k$$$ can be in any order. For each $$$a_i$$$ in $$$a$$$, $$$a_i$$$ must appear at least once in $$$b$$$. It can be proved that if Omkar can create such an array $$$b$$$, then he can also do so in a way that satisfies the above constraints. If multiple solutions exist, you can print any.

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

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

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

  for ($k = 0; $k < count($a); $k++) {
    for ($j = 0; $j < count($a); $j++) {
      if ($k == $j) { $j++; }
      $m = abs($a[$k] - $a[$j]);
      $key = array_search($m, $a);
      if ($key === false) { array_push($a, $m); }
      if (count($a) > 300) { break; }
    }
    if (count($a) > 300) { break; }
  }

  if (count($a) > 300) { echo 'NO'.PHP_EOL; }
  else {
    echo 'YES'.PHP_EOL;
    echo count($a).PHP_EOL;
    for ($j = 0; $j < count($a); $j++) {
      echo $a[$j].' ';
    }
    echo PHP_EOL;
  }
}
?>