<?php
error_reporting(0);

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

	$inp_N = $Scanner->Scan();
	$inp_K = (int)$Scanner->Scan();

	$start = $inp_N - (int)($inp_N / $inp_K);
	//for ($i = 1; $i <= $inp_N; $i++) {
	for ($i = $start; $i <= $inp_N; $i++) {
		$temp = $i;
		$sum = 0;
		while ($temp !== 0) {
			$sum += $temp;
			//$temp = $temp / $inp_K;
			$temp = (int)($temp / $inp_K);
		}
		//if ($sum > $inp_N) {
		if ($sum >= $inp_N) {
			$V = $i;
			break;
		}
	}
	printf("%d", $V);
	$Scanner->close();
}

ob_end_clean();
solve();

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

class Token{
	private $token;
	private $tok;

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

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

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

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

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

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

=== function begin ===

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

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

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

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

?>


<?php
$s = explode(' ',trim(fgets(STDIN)));
$n = $s[0];
$k = $s[1];
$st = $n - (int)($n/$k);
    for ($i = $st; $i <= $n; $i++)
     {
        $sum = 0;
        $temp = $i;

        while ($temp != 0) {
            $sum += $temp;
            $temp = (int)($temp / $k);
        }
        if ($sum >= $n ) break;
     }
 echo $i;


<?php
while($s = fgets(STDIN)){
    $input .= $s;
}
$input = explode("\r\n", $input);
$digits = explode(" ", $input[0]);
$n = $digits[0];
$k = $digits[1];
$ll = 1;
$rr = round(1e18);

while ($ll < $rr) {
    $mid=floor(($ll+$rr)/2);
    $x = 0; $y = $mid;

    while  ($y > 0 ) {
      $x = $x+$y;
      $y = floor($y/$k);

    }
    if ($x >= $n) {
        $rr = $mid;

    }

    else {
        $ll = $mid + 1;

    }
}
echo $ll;
?>


<?php
$fi=@fopen('test.inp',"r");
$s=trim(fgets(STDIN));
$a=explode(" ",$s);
$c=min($a[1],$a[0]);
if ($c%2==0){
	echo "Malvika";
}
else{
	echo "Akshat";
}
?>


<?php
    $finame = "in.txt";
    $finame1 = "php://stdin";
    $foname = "out.txt";
    $foname1 = "php://stdout";

    function swap(&$n, &$m){
        $tmp = $n;
        $n = $m;
        $m = $tmp;
    }

    $fi = fopen($finame1, "r");
    $fo = fopen($foname1, "w");
    fscanf($fi, "%d%d", $n, $m);

    if ($n > $m)
        swap($n, $m);

    if ($n & 1)
        fprintf($fo, "Akshat");
    else
        fprintf($fo, "Malvika");

    fclose($fi);
    fclose($fo);
?>


<?php
    fscanf(STDIN,"%d %d",$n,$m);
    $max=min($n,$m);
    $max%2==1?printf("Akshat"):printf("Malvika");


<?php
$n = explode(" ",trim(fgets(STDIN)));
sort($n);
if ($n[0]%2!=0)echo "Akshat";
else echo "Malvika";


<?php

$input = fgets(STDIN);

$n = (int) explode(' ', $input)[0];
$m = (int) explode(' ', $input)[1];

echo min($n,$m) % 2 === 1 ? 'Akshat' : 'Malvika';


<?php

list($n, $m) = explode(' ', fgets(STDIN));

$n = (int)$n;
$m = (int)$m;

$player = array(0 => 'Akshat', 1 => 'Malvika');
$index = 1;

while ($n > 0 && $m > 0) {
	$index ^= 1;
	$n --;
	$m --;
}

print $player[$index];


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = min($a, $b);
$d = $c % 2;
if($d == 0)
{
    print "Malvika";
}
else
{
    print "Akshat";
}
?>


<?php
    $arr = explode(" ", trim(fgets(STDIN)));
    $v = min($arr);
        if ($v % 2 == 0){
            echo 'Malvika';
        }
        else echo 'Akshat';


<?php

list($n, $m) = explode(' ', fgets(STDIN));

$k = min((int)$n, (int)$m);

print $k&1 ? 'Akshat' : 'Malvika';


<?php

function ropewalkers($str = '')
{
    $arr = explode(' ', $str);
    $d = $arr[count($arr)-1];
    unset($arr[count($arr)-1]);

    $result = 0;
    sort($arr);
    for ($i = 0; $i < count($arr); $i++) {
        if (isset($arr[$i+1]) && abs($arr[$i] - $arr[$i+1]) < $d) {
            $result += $d - abs(($arr[$i] - $arr[$i+1]));
        }
    }
    return $result;
}
$dir = fopen("php://stdin", 'r');
echo ropewalkers(stream_get_contents($dir));

?>


<?php
function s($str = '') {
  $arr = explode(' ', $str);
  $d = $arr[count($arr) - 1];
  unset($arr[count($arr) - 1]);

  sort($arr);
  return max(0, $d - ($arr[1] - $arr[0])) + max(0, $d - ($arr[2] - $arr[1]));
}
$dir = fopen("php://stdin", 'r');
echo s(stream_get_contents($dir));
?>


<?php echo strlen(decbin(fgets(STDIN))); ?>


<?php
$a = trim(fgets(STDIN));
$b = (int) log($a, 2);
print $b + 1;
?>


<?php

$flag = 1; //must be not zero for STDIN
$in = 'php://stdin';
if (!$flag)
{
    $in = "in.data";
}
$fd = fopen($in, "r");
fscanf($fd, "%d %d %d\n", $a, $b, $s);
$a = abs($a);
$b = abs($b);
$ab = $a + $b;

if ($ab <= $s)
{
    $answer="Yes";
}
else
{

    $answer="No";
}
/* for "Yes" a+b and s must both be odd or even*/
if (($ab+$s)&1)
{
    $answer="No";
}
print $answer."\n";
?>


<?php
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$dum= explode("\n",$n);
$argv=explode(" ", $dum[0]);

$iA = abs((int)$argv[0]);
$iB = abs((int)$argv[1]);
$iS = (int)$argv[2];

$iS = $iS - $iA - $iB;

echo $iS > -1 && $iS % 2 == 0 ? 'Yes' : 'No';


<?php
list($a, $b, $s) = explode(" ", trim(fgets(STDIN)));
$s -= abs($a);
$s -= abs($b);
if($s <0 || $s %2 == 1) echo "No"; else echo "Yes";
?>


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = abs($a) + abs($b);
$e = $c - $d;
$f = $e % 2;
if(($f != 0) || ($c < $d))
{
    print "No";
}
else
{
    print "Yes";
}
?>


<?php

list($a, $b, $s) = readInput();
if ($s < abs($a) + abs($b)) {
	echo "No";
} else {
	if (($s - abs($a) - abs($b)) % 2 == 0) {
		echo "Yes";
	} else {
		echo "No";
	}
}

function readInput() {
	$row = explode(" ", trim(fgets(STDIN)));
	$a = $row[0];
	$b = $row[1];
	$s = $row[2];
	return array($a, $b, $s);
}

?>


<?php
// Example for test php input output

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

$a = abs($a);
$b = abs($b);
$r = $a+$b;
$resultOk = "Yes";
$resultNo = "No";
//fprintf(STDOUT, "%1.0f\n", $resultOk);
if ((($a+$b) == $s) || ((($a+$b) < $s) && ((($s-$r) % 2) == 0)) )  {
    echo $resultOk;
} else {
    echo $resultNo;
}


<?php
$in = explode(" ", trim(fgets(STDIN)));
$a = $in[0];
$b = $in[1];
$s = $in[2];
$min = abs($a)+abs($b);
if ($s<$min) {
    echo "No";
} else {
    $s -= $min;
    if ($s%2 == 0) {
        echo "Yes";
    } else {
        echo "No";
    }
}
?>


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
if($a == $d)
{
     if(($a == 0) && ($d == 0))
     {
          if($c == 0)
          {
               print "1";
          }
          else
          {
               print "0";
          }
     }
     else
     {
          print "1";
     }
}
else
{
     print "0";
}
?>


<?php

$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));

if($a == $d && $a > 0){
	fwrite(STDOUT, 1);
}else{
	if($a == 0 && $c == 0 && $d == 0){
		fwrite(STDOUT, 1);
	}else{
		fwrite(STDOUT, 0);
	}
}

?>


<?php
$f = fopen ("php://stdin", 'r' ) ;
$a_win =0;
$b_win =0;
$draw =0;

$lines = file("php://stdin");
function parseint($n){
    return(intval($n));
}

$a_b = array_map("parseint", explode(" ",(strval($lines[0]))));

 for($i=1 ; $i<=6 ; $i++){

     if(abs($a_b[0] - $i ) < abs($a_b[1] - $i )){
         $a_win++;

     }
     elseif(abs($a_b[0] - $i ) > abs($a_b[1] - $i )){
         $b_win++;

     }
     else{
         $draw++;
         }

 }

 print $a_win . " " . $draw . " " .$b_win ;

?>


<?php

list($a, $b) = explode(' ', getline());

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

$winf = 0;
$draw = 0;
$wins = 0;

for ($i = 1; $i <= 6; $i ++) {
  $diffa = abs($i - $a);
  $diffb = abs($i - $b);
  if ($diffa < $diffb) {
    $winf ++;
  } elseif ($diffa > $diffb) {
    $wins ++;
  } else {
    $draw ++;
  }
}

print $winf . ' ' . $draw . ' ' . $wins;

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


<?php

$f = fopen("php://stdin", 'r');
list($a, $b) = fscanf($f, "%d %d");
fclose($f);

$result = array(0, 0, 0);

for ($j = 1; $j <= 6; $j++) {
	if (abs($a - $j) < abs($b - $j)) {
		$result[0]++;
	}
	elseif (abs($a - $j) > abs($b - $j)) {
		$result[2]++;
	}
	elseif (abs($a - $j) == abs($b - $j)) {
		$result[1]++;
	}

}

print implode(' ', $result);


<?php

$line = trim(fgets(STDIN)); // reads one line from STDIN

$array=explode(" ",$line);

$a = $array[0];
$b = $array[1];

if($a==0&&$b==0) {
echo "NO";
die();
}

if(abs($a-$b)<=1) {
echo "YES";
}

else
echo "NO";

?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = abs($a - $b);
if(($a == 0) && ($b == 0))
{
     print "NO";
}
else
{
     if($c <= 1)
     {
          print "YES";
     }
     else
     {
          print "NO";
     }
}
?>


<?php
// keep this function call here
$file = fopen('php://stdin', 'r');
// $file = fopen('input.txt', 'r');
$line = fgets($file);
$str = (int) $line;
// $arr = explode(' ', $line);
$s = 0;
for ($i = 1; $i < $str/2 + 1; $i++) {
        if(($str - $i) % $i == 0){
            $s++;
        }
}
echo $s;
// echo search((int)$line, 0);
?>


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

echo solution($n);

// End of interface

function solution($n){
	$res = 0;
	for ($i=1; $i<$n; $i++){
		if ($n % $i === 0){
			$res++;
		}
	}
	return $res;
};

?>


<?php

$main = new MainClass;

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

echo $main->solution($n);

class MainClass {
	public $problemLink = 'https://codeforces.com/problemset/problem/935/A';
	public $submissionLink = '';

	public function solution($n){
		$res = 0;
		for ($i=1; $i<$n; $i++){
			if ($n % $i === 0){
				$res++;
			}
		}
	return $res;
	}
}


<?php

// "-თიყვაა!! გამოდი და დამილიე ეს ღვინოო!"

//  ( : )

$in = fgets(STDIN);

$mid = floor($in/2);

$dataTutashkhia = 0;

for( $i = 1; $i <= $mid; $i++)
    if(($in-$i) % $i == 0)
        $dataTutashkhia++;

echo $dataTutashkhia;

?>


<?php
fscanf(STDIN,"%d",$n);
$count=0;
$divide=(int)($n/2);
$sub=1;
$i=1;
while ($divide--) {
$res=$n-($sub++);
if(($res)%($i++)==0)
$count++;
//echo "$res\n";
}
echo "$count";


<?php
$num=trim(fgets(STDIN));
if ($num == 0) {
    echo 1;
}elseif ($num % 4 == 0) {
    echo 6;
}elseif($num %4 == 1) {
    echo 8;
}elseif ($num % 4 == 2) {
    echo 4;
}elseif ($num % 4 == 3) {
    echo 2;
}
?>


<?php
fscanf(STDIN,"%d",$n);
$root=sqrt($n);
if($root==floor($root))
	echo "$root $root";
else
{
		$j=0;
		$quotient=array();
		for ($i=1; $i <=ceil($n/2); $i++)
		 {
			$factor=$n/$i;
			if($factor==floor($factor))
			{
				$quotient[$j++]=$factor;
			}
		 }

		 $quotient[count($quotient)]=1;
		 //print_r($quotient);
		 if(count($quotient)==2)
		 	echo "$quotient[1] $quotient[0]\n";
		 else
		 {
		   $maxDif=10000000;

		 	for ($i=0; $i <count($quotient) ; $i++)
		 	{
		 		 for ($j=0; $j <count($quotient) ; $j++)
		 		  {
		 		 	  if($quotient[$i]*$quotient[$j]==$n)
		 		 	  {
		 		 	  	$dif=abs($quotient[$i]-$quotient[$j]);
		 		 	  	  if($dif<$maxDif)
		 		 	  	  {
		 		 	  	  	$maxDif=$dif;
		 		 	  	  	 $targetValue="$quotient[$j] $quotient[$i]";
		 		 	  	  }
		 		 	  }
		 		 }
		 	}
		 	echo "$targetValue\n";
		 }
}


<?php
$a = trim(fgets(STDIN));
$b = floor(sqrt($a));
while(TRUE)
{
     $c = $a % $b;
     if($c == 0)
     {
          break;
     }
     else
     {
          $b--;
     }
}
print $b . " " . ($a / $b);
?>


<?php
/*	$input = "2 2
..
..";*/
	$input = file_get_contents("php://stdin");

	$split_text = explode("\n",$input);
	$row_col = explode(" ",$split_text[0]); //index 0 store r, index 1 store c
	$max_eat = 0;
	$prev_trap="";
	$row_crash_hit=0;
	$col_crash_hit=0;

	array_splice($split_text, 0, 1);

	for ($r=0; $r < $row_col[0]; $r++) {
		$row[$r]=$row_col[1];
	}

	for ($c=0; $c < $row_col[1]; $c++) {
		$col[$c]=$row_col[0];
	}

	for ($r=0; $r < $row_col[0] ; $r++) {
		for ($c=0; $c < $row_col[1]; $c++) {
			if($split_text[$r][$c]=='S'){
				$row[$r]=0;
				$col[$c]=0;
			}
		}
	}

	for ($r=0; $r < $row_col[0]; $r++) {
		if($row[$r]!=0){
			$row_crash_hit+=1;
			$max_eat+=$row[$r];
		}
	}

	for ($c=0; $c < $row_col[1]; $c++) {
		if($col[$c]!=0){
			$col_crash_hit+=1;
			$max_eat+=$col[$c];
		}
	}

	$crash_hit=$row_crash_hit*$col_crash_hit;
	$max_eat=$max_eat-$crash_hit;

	echo $max_eat;


<?php
$h = fopen("php://stdin", "r");

$line=trim(fgets($h));
$line_arr=explode(' ', $line);
$a=intval(trim($line_arr[0]));
$b=intval(trim($line_arr[1]));
$c=intval(trim($line_arr[2]));

$diff=$b-$a;

$appears=false;

if($c>0) {
    if($diff>=0 && $diff%$c==0) {
        $appears=true;
    }
} elseif ($c==0) {
    if($b==$a)
        $appears=true;
} else {
    if($diff<=0 && $diff%$c==0) {
        $appears=true;
    }
}

if($appears)
    echo 'YES';
else
    echo 'NO';


<?php
$s = explode(" ", trim(fgets(STDIN)));
$a = $s[0];
$b = $s[1];
$c = $s[2];
$p = false;
if ($a == $b) {
    $p = true;
    print "YES";
} else if (($b < $a) and ($c > 0)) {
    $p = true;
    print "NO";
} else if (($b > $a) and ($c < 0)) {
    $p = true;
    print "NO";
} else if (($a != $b) and ($c == 0)) {
    $p = true;
    print "NO";
}
if (!$p) {
    $i = ($b - $a) % $c;
    if ($i == 0) {
        print "YES";
    } else {
        print "NO";
    }
}
?>


<?php

$i = 0;
$str = '0';
do {
$i++;
$str .= $i;
} while(strlen($str) < 10000);

$d = trim(file_get_contents('php://stdin'));

echo $str[$d];


<?php
# 1177b
$stdin = STDIN;

$k = trim(fgets($stdin));
$str = '';
$length = 0;
for ($i = 1; $length <= $k; $i++) {
    $str .= $i;
    $length += strlen($i);
}
echo $str[$k - 1];


<?php

$stdin = fopen('php://stdin', 'r');
$num = trim(fgets($stdin));
$summ = 0;
for ($i = 2; $i < $num; $i++) {
    $summ += get_summ($num, $i);
}
$count = $num - 2;
for ($i = $count; $i > 0; $i--) {
    if ($summ % $i == 0 && $count % $i == 0) {
        $summ /= $i;
        $count /= $i;
    }
}

echo $summ . '/' . $count;

function get_summ($num, $base) {
    $result = 0;
    while ($num) {
        $result += $num % $base;
        $num = floor($num / $base);
    }
    return $result;
}


<?php

error_reporting(0);
ob_end_clean();

solve();

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

	$I = (int)$Scanner->Scan();

	$ans = $I % 3 + 1;
	if ($I === 5) $ans = 1;
	print($ans);

	$Scanner->Close();
}

class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);
		$contents = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

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

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

?>


<?php
$input = Array();

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

while(count($input) < 9 && $line = fgets($fp)) {
    $input[] = substr($line,0,8);
}

for($i=0;$i<8;$i++) {
    //BBBBBBBB or WWWWWWWW
    if(strpos($input[$i],'W')===false || strpos($input[$i],'B')===false) {
        echo "NO";
        exit();
    }

    //BB, WW or B******B or W******W
    if(strpos($input[$i],'BB')!==false || strpos($input[$i],'WW')!==false || $input[$i][0]==$input[$i][7]) {
        echo "NO";
        exit();
    }

    if($i==0) {
        //First line normalize
        if($input[$i][0] != 'W') {
            $input[$i] = move($input[$i]);
        }

        //Last line normalize
        if($input[$i] == $input[7]) {
            $input[7] = move($input[7]);
        }

    }

    //I like to move it move it
    if($i>0 && $i<7) {
        if($input[$i] == $input[$i-1]) {
            $input[$i] = move($input[$i]);
        }
    }
}

//Final countdown
if($input[0] == $input[2] && $input[0] == $input[4] && $input[0] == $input[6] && $input[1] == $input[3] && $input[1] == $input[5] && $input[1] == $input[7]) {
    echo "YES";
    exit();
} else {
    echo "NO";
    exit();
}

function move($s)
{
    return substr($s,7,1) . substr($s,0,7);
}


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

// Codeforces Contest 157 Div 2 Problem A
$res = true;
for ($i = 0; $i < 8; $i++) {
	$str[$i] = g();
	if (($str[$i][0] != "BWBWBWBW") && ($str[$i][0] != "WBWBWBWB")) {$res = false;}
}
if ($res) {echo "YES";} else {echo "NO";}

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


<?php

class InputReader {
	protected $_fh;

	public function __construct($fileHandler = STDIN)
	{
		$this->_fh = $fileHandler;
	}

	public function readInt()
	{
		$d = trim(fgets($this->_fh));

		return (int)$d;
	}

	public function readArrayOfInt($size, $indexFrom = 0)
	{
		$a = [];
		$ind = $indexFrom;
		foreach (explode(' ', fgets($this->_fh)) as $item) {
			$a[$ind++] = (int)$item;
		}

		return $a;
	}

	public function readArrayOfString($size, $indexFrom = 0)
	{
		$a = [];
		$ind = $indexFrom;
		foreach (explode(' ', fgets($this->_fh)) as $item) {
			$a[$ind++] = $item;
		}

		return $a;
	}
}

function ntimes($n, $func, $returnResults = false) {
	$a = [];
	for ($i=1; $i<=$n; $i++) {
		$result = $func();

		if ($returnResults) {
			$a[$i] = $result;
		}
	}

	return $a;
}

function primes($limit)
{
	$a = str_repeat(chr(85), ($limit>>3) + 1);
	$a[0] = chr(83);
	for ($i=3; $i*$i < $limit; $i+=2) {
		if (ord($a[$i>>3]) & (1<<($i%8))) {
			;
		} else {
			for ($k=$i; $k*$i<$limit; $k++) {
				$n = $k*$i;
				$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));
			}
		}
	}

	yield 2;
	for ($i=3; $i<$limit; $i+=2) {
		if (!(ord($a[$i>>3]) & (1<<($i%8)))) {
			yield $i;
		}
	}
}

$ir = new InputReader();

$n = abs($ir->readInt());
$p = [];
foreach (primes(1e3) as $prime) {
	$p[] = $prime;
}

$powers = [];
if ($n==1) {
	$min = 1;
	$steps = 0;
} elseif ($n==0) {
	$min = 0;
	$steps = 0;
} else {
	while ($n>1) {
		$foundPrime = false;
		foreach($p as $prime) {
			if ($n%$prime == 0) {
				$foundPrime = true;
				if (!isset($powers[$prime])) {
					$powers[$prime] = 0;
				}

				$powers[$prime] += 1;
				$n /= $prime;
				break;
			}
		}

		if(!$foundPrime) {
			if (!isset($powers[$n])) {
				$powers[$n] = 0;
			}
			$powers[$n] += 1;
			$n = 1;
		}
	}

	$min = array_product(array_keys($powers));

	$maxP = max($powers);
	$minP = min($powers);

	if ($maxP == 1) {
		$steps = 0;
	} else {
		$l2 = log($maxP)/log(2);

		$steps = 1 + (int)$l2;
		if (intval($l2) < $l2) {
			$steps++;
		} else {
			if ($maxP==$minP) {
				$steps--;
			}
		}
	}
}
// factorize and grab max power
// echo [log2(power)] + 1

echo $min . ' ' . $steps."\n";

//}


<?php
$time=trim(fgets(STDIN));
$list=explode(":",$time);
$count=0;
while(true) {
    $cur = strrev($time);
    if ($cur == $time) {
        echo $count;
        break;
    }
    $list[0] = (intval($list[0]) + (intval($list[1]) + 1) / 60) % 24;
    $list[1] = (intval($list[1]) + 1) % 60;
    $list[0] = str_pad(strval($list[0]), 2, '0', STR_PAD_LEFT);
    $list[1] = str_pad(strval($list[1]), 2, '0', STR_PAD_LEFT);
    $time = implode(':', $list);
    $count++;
}
?>


<?php

$file = file_get_contents('php://stdin');

$file = preg_replace("/[^0-9a-z]+/i"," ",$file);

$number = explode(' ', $file);

// print_r($number);
$x = $number[0];
$y = $number[1];
$z = $number[2];
$t1 = $number[3];
$t2 = $number[4];
$t3 = $number[5];

/*echo 'Лифт между этажами до Маши = ' . abs($z - $x) * $t2 . '
';
echo 'Лифт между этажами от Маши до этажа = ' . abs($x - $y) * $t2 . '
';
echo 'Время дверей лифта = ' . 3 * $t3 . '
';
echo 'Маша пешком = ' . abs($y - $x) * $t1 . '
';*/

if ((abs($z - $x) * $t2 + abs($x - $y) * $t2 + 3 * $t3) <= (abs($y - $x) * $t1)) file_put_contents('php://stdout', 'YES');
else file_put_contents('php://stdout', 'NO');


<?php
function solve(){
    $x=readLine();
    $cl;
    for($i=2;$i<=sqrt($x);$i++){
        if($x%$i==0)$cl=$i;
    }
    print $cl. $x/$cl;
}
function main(){
    $t=1;
    //$t=readLine();
    for($i=0;$i<$t;$i++){
        solve();
    }
}
main();
?>


<?php
$board = array();
function calc()
{
    global $board;
    for ($i = 0; $i < 8; $i++)
    {
        $board[$i] = rtrim(fgets(STDIN));
    }
    if (dfs(7, 0, 0)) echo "WIN\n";
    else echo "LOSE\n";
}

function dfs($y, $x, $turn)
{
    global $board;
    if ($y - $turn >= 0 && $board[$y - $turn][$x] == 'S') return false;
    if ($turn >= 8) return true;
    for ($vy = -1; $vy <= 1; $vy++)
    {
        for ($vx = -1; $vx <= 1; $vx++)
        {
            $ny = $y + $vy;
            $nx = $x + $vx;
            if ($ny < 0 || $ny >= 8 || $nx < 0 || $ny >= 8) continue;
            if ($ny - $turn >= 0 && $board[$ny - $turn][$nx] == 'S') continue;
            if (dfs($ny, $nx, $turn + 1)) return true;

        }
    }
    return false;
}

calc();
?>


<?php
function calc()
{
    $board = array();
    for ($i = 0; $i < 8; $i++)
    {
        $board[$i] = rtrim(fgets(STDIN));
    }
    if (calc2($board)) echo "WIN\n";
    else echo "LOSE\n";
}

function calc2($board)
{
    $now = array_fill(0, 8, array());
    $now[7][0] = true;
    for ($turn = 0; $turn < 30; $turn++)
    {
        $next = array_fill(0, 8, array());
        for ($y = 0; $y < 8; $y++)
        {
            for ($x = 0; $x < 8; $x++)
            {
                if ($y - $turn >= 0 && $board[$y - $turn][$x] == 'S') continue;
                if ($y - ($turn + 1) >= 0 && $board[$y - ($turn + 1)][$x] == 'S') continue;
                for ($vy = -1; $vy <= 1; $vy++)
                {
                    for ($vx = -1; $vx <= 1; $vx++)
                    {
                        $ny = $y + $vy;
                        $nx = $x + $vx;
                        if (ok($ny, $nx) && $now[$ny][$nx])
                        {
                            $next[$y][$x] = true;
                            if ($board[$y][$x] == 'A') return true;
                        }
                    }
                }
            }
        }
        $now = $next;
    }
    return false;
}

function ok($y, $x)
{
    return $x >= 0 && $y >= 0 && $x < 8 && $y < 8;
}

calc();
?>


<?php
$a = trim(fgets(STDIN));
if($a == 2)
{
     print "2";
}
else
{
     print "1";
}
?>


<?php
    echo (trim(fgets(STDIN)) == "2" ? 2 : 1);
?>


<?php
function decompose($number){
  $sum = 0;
  // while($number > 0){
  //   $sum += $number % 10;
  //   $number /= 10;
  // }
  $number = strval($number);
  for($x = 0; $x < strlen($number); $x++)
  {
       $sum += $number[$x];
  }
  return $sum;
}

fscanf(STDIN, "%d\n", $k);
$i = 2;
$prefect = 19;
while($k > 0){
  if(decompose($prefect) == 10){
    $k--;
  }
  if($k == 0) break;
  $prefect += 9;
}
echo $prefect;


<?php

###### IO ######
error_reporting(E_ALL);
error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	$aPos = str_split('qzawsxedcrfvtgpbyhnujmiklo');
	sort($aPos);
	$aPos = implode('', $aPos);
	$totalLen = strlen($aPos);

	$inputStr = readString($stream);
	$return = 0;
	while (!empty($inputStr)) {
		$char = $inputStr[0];
		$pos = strpos($aPos, $char);
		$left = $totalLen - $pos;
		if ($pos < $left) {
			$return+=$pos;
		} else {
			$return+=$left;
		}
		$aPos = substr($aPos, $pos) . substr($aPos, 0, $pos);

		$inputStr = substr($inputStr, 1);
	}
	echo $return;
	/* / end body */
}

if (empty($is_test))
	getAnswer();


<?php
$line = trim(fgets(STDIN));
function dis($a,$b){
    if($a == $b) return 0;
    if(ord($a)> ord($b)){
        $tmp = $a;
        $a = $b;
        $b = $tmp;
    }
    $i = abs(intval(ord($a) - ord($b)));
    $j = abs(intval(ord($a) - ord('a'))) + abs(intval(ord('z')) - ord($b)) + 1;
//    echo "a: $a  b: $b" . PHP_EOL;
//    echo "i: $i  j: $j " . PHP_EOL;
    return min($i,$j);
}
$current = 'a';
$sum = 0;
foreach(str_split($line) as $c){
    $sum += dis($c,$current);
    $current = $c;
}
echo $sum . PHP_EOL;


<?php
$str=trim(fgets(STDIN));
$alpha='abcdefghijklmnopqrstuvwxyz';
$split=str_split($alpha,1);
//$revAlpha=strrev($alpha);

$concate='a'.$str;
//echo "$concate";
$count=0;
for($i=0;$i<strlen($concate)-1;$i++)
{
	$keyDistance=abs(ord($concate[$i])-ord($concate[$i+1]));
	//echo "$keyDistance\n";
	if($keyDistance>13)
   {
   	     $k1[$i]=array_keys($split,$concate[$i]);
   	    // print_r($k1);
   	     //$key1=$k1[$i];
   	    //
   	     $k2[$i]=array_keys($split,$concate[$i+1]);
   	    //print_r($k2);
   	     //$key2=$k2[$i];
   	     if($k1[$i]>$k2[$i]){

   	       $temp[$i]=$k1[$i];
   	       $k1[$i]=$k2[$i];
   	       $k2[$i]=$temp[$i];

   	   }

   $count+=($k1[$i][0]+26)-$k2[$i][0];
   //echo "plus=$count\n";
   }
   else
   {
   	   	  $k1[$i]=array_keys($split,$concate[$i]);
   	     //$key1=$k1[$i];
   	    //
   	     $k2[$i]=array_keys($split,$concate[$i+1]);
   	     //$key2=$k2[$i];

         $count+=abs($k1[$i][0]-$k2[$i][0]);
   //echo "minus=$count\n";

   }
   //print_r($k1);
  // print_r($k2);

}
echo "$count";

//print_r($keyDistance);


<?php

define("CHARACTER_LIST", ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']);

$word = trim(fgets(STDIN));

$wordLetters = str_split($word);

$prevPosition = 0;
$steps = 0;
foreach ($wordLetters as $letter) {
  $letterNumber = array_search($letter, CHARACTER_LIST);

  $stepsCount = abs($letterNumber - $prevPosition);

  if ($stepsCount >= 13) {
    $actualStepsCount = count(CHARACTER_LIST) - $stepsCount;
    $steps += $actualStepsCount;

    $prevPosition = $letterNumber;
  } else {
    $actualStepsCount = $stepsCount;
    $steps += $actualStepsCount;

    $prevPosition = $letterNumber;
  }
}

echo $steps;


<?php

//=====================================
// link: https://codeforces.com/contest/731/problem/A
//=====================================

// get inputs
$string = trim(fgets(STDIN));

// solution
$alpha   = array_flip(range('a', 'z'));
$travel  = 0;
$pointer = 0;

for ($i = 0; $i < strlen($string); $i++) {
    $clockwise = abs($pointer - $alpha[$string[$i]]);

    $counterclockwise = 26 - $clockwise;

    $travel += min($clockwise, $counterclockwise);

    $pointer = $alpha[$string[$i]];
}

echo "$travel\n";


<?php

	$string = readline("");
	$result = 0;

	$stringArr = str_split($string);
	$len = count($stringArr);
	$pointer = ord("a");
	foreach($stringArr as $ch) {
		$ch = ord($ch);
		$diff = abs($ch - $pointer);
		if($diff < 13) {
			$result += $diff;
		} else {
			$result += (26 - $diff);
		}
		$pointer = $ch;
	}
	echo $result;
?>


<?php
$di=trim(fgets(STDIN));
$ex= explode(" ", $di);

foreach ($ex as $key => $value) {

  if ($key == 1) $value3=$value;
  if ($key == 0) $value2=$value;
  if ($key == 2) $value5=$value;
  if ($key == 3) $value6=$value;

  if ($value2 <= $value5 and $value2 <= $value6) {
       $final=$value2 * 256;

  }elseif ($value5 < $value2 and $value5 < $value6) {

       $final=$value5 * 256;

  }elseif ($value6 < $value2 and $value6 < $value5){

       $final=$value6 * 256;

  }elseif ($value5 == $value6) {

      $final= $value5 * 256;

  }

  $actvalue=$final / 256;
  $ac2=$value2 - $actvalue;

  if ($actvalue == $value2)      {
       $ff =$final ;

  }elseif ($value3 < $ac2) {
      $mm=$value3 * 32;
      $ff=$mm + $final;

    }elseif ($ac2 < $value3) {
          $ff = $ac2 * 32 + $final;

    }elseif ($ac2 == $value3) {

        $ff= $value3 * 32 + $final;
    }

}
  echo $ff;

?>


<?php
$string = trim(fgets(STDIN,100));
$len = strlen($string);
$start = 0;
$index=0;
$arr = array(4);
for($i=0;$i<$len;$i++){
  if(substr($string, $i, 1) == " ")
  {
    $arr[$index] = substr($string, $start, ($i-$start));
    $start = $i+1;
    $index++;
  }
  else if($i == ($len-1)){
    $arr[$index] = substr($string, $start, (($i+1)-$start));
    $start = $i+1;
  }
}
$index = $arr[0];
if($arr[2]<$index){
  $index = $arr[2];
}
if($arr[3]<$index){
  $index = $arr[3];
}
$sum = $index*256;
$arr[0] -= $index;
$index = $arr[0];
if($arr[1]<$index){
  $index = $arr[1];

}
$sum += ($index*32);

echo $sum;

?>


<?php

###### IO ######
error_reporting(E_ALL);
#error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

function readNumArray($f) {
	return readStringExplodeNum($f, ' ', true);
}

function readArray($f) {
	return readStringExplodeNum($f, ' ');
}

function readTrimString($f) {
	return trim(readString($f));
}

###### /IO ######
# for($i=0;$i<$n;$i++)

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	list($k2, $k3, $k5, $k6) = readStringExplodeNum($f, ' ', true);
	$n256 = min($k2, $k5, $k6);
	$k2-=$n256;
	$k5-=$n256;
	$k6-=$n256;

	$n32 = min($k2, $k3);
	echo ($n256 * 256 + $n32 * 32);

	/* / end body */
}

if (empty($is_test))
	getAnswer();


<?php

$buffer = array();
$stdin = fopen('php://stdin', 'r');
while (!feof($stdin)) {
    $buffer[] = fgets($stdin);
}
fclose($stdin);

$c = explode(' ', $buffer[0], 2);
$countBallons = intval($c[0]);
$countFriends = intval($c[1]);
$colors = str_split($buffer[1], 1);

$colorsCount = array();
$max = 0;
foreach ($colors as $color){
    $colorsCount[$color]++;
    if ($colorsCount[$color] > $max){
        $max = $colorsCount[$color];
    }
}

$stdout = fopen('php://stdout', 'w');
fwrite($stdout, ($max <= $countFriends ? "YES" : "NO"));
fclose($stdout);


<?php
$fp = fopen('php://stdin', 'r');
$line1 = trim(fgets($fp));
$line2 = trim(fgets($fp));
fclose($fp);
$twoNumber = explode(' ', $line1);
$fNum = intval($twoNumber[0]);
$sNum = intval($twoNumber[1]);

$arrCount = array_count_values(str_split($line2));
foreach ($arrCount as $value) {
    if ($value > $sNum) {
        echo "NO", PHP_EOL;die;
    }
}
echo "YES", PHP_EOL;


<?php
$p = fopen('php://stdin', 'r');
$input = explode(' ', fgets($p));
$baloonCount = intval($input[0]);
$friendCount = intval($input[1]);
$str = trim(fgets($p));
fclose($p);
$groups = [];
$baloons = str_split($str);
foreach ($baloons as $color) {
    if (isset($groups[$color])) {
        $groups[$color]++;
    } else {
        $groups[$color] = 1;
    }
}
foreach ($groups as $count) {
    if ($count > $friendCount) {
        echo 'NO', PHP_EOL; die;
    };
}
echo 'YES', PHP_EOL;


<?php
$input = fopen("php://stdin","r");
$str = fgets($input);

$max = 0;
for ($i = 0;$i<strlen($str);++$i) {
	if (ord($str[$i])>$max) $max = ord($str[$i]);
}

$ans = '';
for ($i = 0;$i<strlen($str);++$i) {
	if (ord($str[$i])==$max) $ans.=$str[$i];
}

echo $ans;
?>


<?php
// Retrieve input and show output
$stream = fopen("php://stdin", "r");
$input = stream_get_contents($stream);
$inputs = preg_split("/[\s]+/", $input);
echo func($inputs);

// Codeforces Contest 127 Division 2 Problem A
function func($in) {
$len = strlen($in[0]);
$asc = 97;		// ord("A")
$count = 0;
for ($x = 0; $x < $len; $x++) {
	if (ord(substr($in[0], $x, 1)) > $asc) {
		$asc = ord(substr($in[0], $x, 1));
		$count = 1;
	} else if (ord(substr($in[0], $x, 1)) == $asc) {
		$count++;
	}
}
return str_repeat(chr($asc), $count);
}

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


<?php

error_reporting(0);

solve();

function is_length_invalid($str){
	$n = strlen($str);
	if ($n >= 8) return true;
	else if ($n === 7 && $str !== "1000000") return true;

	return false;
}

function is_leadingzero($str){
	$n = strlen($str);
	$str_nums = str_split($str);

	if ($str_nums[0] === "0") {
		if ($n !== 1) return true;
	}

	return false;
}

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

	$S = $Scanner->Scan();
	$len = strlen($S);
	$max = -1;

	for ($i = 1; $i <= $len - 2; $i++) {
		$first = substr($S, 0, $i);
		if (is_leadingzero($first) || is_length_invalid($first)) continue;

		for ($j = 1; $j <= $len - $i - 1; $j++) {
			$second = substr($S, $i , $j);
			if (is_leadingzero($second) || is_length_invalid($second)) continue;

			for ($k = 1; $k <= $len - $i - $j; $k++) {
					$third = substr($S, $i + $j);
					if (is_leadingzero($third) || is_length_invalid($third)) continue;
					$max = max($max, $first + $second + $third);
			}
		}
	}
	print($max);

	$Scanner->Close();
}

class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);
		$contents = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

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

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

?>


<?php

###### IO ######
error_reporting(E_ALL);
error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	$n = readNum($f);
	$times = readStringExplodeNum($f, ' ', true);
	$f = 0;
	$viewTime = 0;
	for ($i = 1; $i <= 90; $i++) {
		if (in_array($i, $times)) {
			$f = 0;
		} else {
			$f ++;
		}

		$viewTime++;
		if ($f >= 15) {
			break;
		}
	}
	echo $viewTime;
	/* / end body */
}

if (empty($is_test))
	getAnswer();


<?php
function test($n,$arr){
    $start = 0;
    for($i = 0;$i< $n ;$i++){
        if(($arr[$i] - $start) > 15) return ($start+15) >= 90 ? 90 : $start+15 ;
        $start = $arr[$i];
    }
    return ($arr[$n-1] + 15) >= 90 ? 90 : $arr[$n-1]+15;
}
    //  Bear and Game
    $in = 'php://stdin';
    $input = fopen($in, "r");
    $n = fgets($input);
    $t = [];
    $t = array_merge($t, explode(" ", trim(fgets($input))));
    echo (test($n,$t));

?>


<?php
$in = 'php://stdin';
$input = fopen($in, "r");
$n = fgets($input);
$t = [0];
$t = array_merge($t, explode(" ", trim(fgets($input))));
$tt = [];
/*
foreach ($t as $i) {
    array_push($tt, intval($i));
}
array_push($tt, 90);
*/
array_push($t, 90);
$isTVOff = false;
for ($i = 0; $i < count($t) - 1; $i++) {
    if (intval($t[$i + 1]) - intval($t[$i]) > 15) {
        echo($t[$i] + 15);
        $isTVOff = true;
        break;
    }
}
if (!$isTVOff) {
    echo(90);
}


<?php
$in = 'php://stdin';
$input = fopen($in, "r");
$n = fgets($input);
$t = [0];
$t = array_merge($t, explode(" ", trim(fgets($input))));
$tt = [];
foreach ($t as $i) {
    array_push($tt, intval($i));
}
array_push($tt, 90);
$isTVOff = false;
for ($i = 0; $i < count($tt) - 1; $i++) {
    if ($tt[$i + 1] - $tt[$i] > 15) {
        echo($tt[$i] + 15);
        $isTVOff = true;
        break;
    }
}
if (!$isTVOff) {
    echo(90);
}


<?php

	$totalInterestingMinutes = readline("");
	$minutes = readline("");

	$minutes = explode(" ", $minutes);

	$prevMin = 0;
	$result = 90;
	$count = count($minutes);
	foreach($minutes as $key => $min) {
		$min = (int)$min;
		if($min - $prevMin > 15) {
			$result = $prevMin + 15;
			break;
		}
		if($min == 90) {
			$result = 90;
			break;
		}
		if($key == $count - 1 && $min + 15 < 90) {
			$result = $min + 15;
			break;
		}
		$prevMin = $min;
	}
	echo $result;
?>


<?php

$in = 'php://stdin';
$input = fopen($in, "r");
$n = fgets($input);
$t = [];
$t = array_merge($t, explode(" ", trim(fgets($input))));

function watchTime($n, $t) {
    $watchTime = 0;
    for($i = 0; $i < $n; $i++){
        if($t[$i]-$watchTime > 15) break;

        $watchTime = $t[$i];
    }
    echo $watchTime+15 > 90 ? 90 : $watchTime+15;
}

watchTime($n,$t);


<?php

$in = 'php://stdin';
$input = fopen($in, "r");
$n = fgets($input);
$t = [];
$t = array_merge($t, explode(" ", trim(fgets($input))));

function watchTime($n, $t) {
    $watchTime = 0;
    $funLimit = 15;
    for($i = 0; $i < $n; $i++){
        $inTime = ceil(($t[$i]-$watchTime)/$funLimit);
        if($inTime > 1){
            break;
        } else {
            $watchTime = $t[$i];
        }
    }
    echo $watchTime+15 > 90 ? 90 : $watchTime+15 ;
}

watchTime($n,$t);


<?php

// სალადინი -> სალაჰ ად-დინ იუსუფ იბნ აიუბი

// ეგვიპტის სულთანი 1171 წლიდან
// Kingdom of Heaven -ში ერთ-ერთი პერსონაჟი
// ჯვაროსნულ ლაშქრობებში ფიგურირებდა

//"I am not those men. I AM Sallah Ad Din. Sallah Ad Din!"

$in = fgets(STDIN);

$str = array();

$salahAdDin = 0;

for($i=0;$i<strlen($in);$i++)
    if($in[$i]=='Q')
        array_push($str,'Q');
    elseif($in[$i]=='A')
        array_push($str,'A');

$n = count($str);

for($i=0;$i<$n-2;$i++)
    for($j=$i+1;$j<$n-1;$j++)
        for($c = $j+1;$c<$n;$c++)
            if($str[$i]=='Q' && $str[$j]=='A' && $str[$c]=='Q')
                $salahAdDin++;

echo $salahAdDin;

?>


<?php

list($x, $y) = explode(' ', line());

$x = intval($x);
$y = intval($y);

if ($x > 0 && $y > 0) {
  $answer = array(0, $x + $y, $x + $y, 0);
}
elseif ($x > 0 && $y < 0) {
  $answer = array(0, -$x + $y, $x - $y, 0);
}
elseif ($x < 0 && $y > 0) {
  $answer = array($x - $y, 0, 0, -$x + $y);
}
elseif ($x < 0 && $y < 0) {
  $answer = array($x + $y, 0, 0, $x + $y);
}

print implode(' ', $answer);

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


<?php
/** SECTION 0: NOTES **/
/*
Problem:
Codeforces Contest 195 Div 2 Problem A

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

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

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

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

/** SECTION 3: SOLVING THE PROBLEM **/
$raw = g();
$x = $raw[0];
$y = $raw[1];
$sum = abs($x)+abs($y);

$signx = ($x > 0) ? 1 : -1;
$signy = ($y > 0) ? 1 : -1;

$points = array(array(0,0), array(0,0));
$points[0][0] = $signx * $sum;
$points[1][1] = $signy * $sum;

if ($points[0][0] < $points[1][0]) {echo $points[0][0] . " " . $points[0][1] . " " . $points[1][0] . " " . $points[1][1];} else {echo $points[1][0] . " " . $points[1][1] . " " . $points[0][0] . " " . $points[0][1];}


<?php
/*  $input = "2 2
..
..";*/
    $input = file_get_contents("php://stdin");
    $split_text = explode(" ",$input);
    $split_text[0] = $split_text[0]-'0';
    $split_text[1] = $split_text[1]-'0';
    if($split_text[0]>=0 && $split_text[1]>=0){
        $result = $split_text[0] + $split_text[1];
        echo '0 '.$result.' '.$result.' 0';
    }
    elseif ($split_text[0]<0 && $split_text[1]>=0) {
        $result = abs($split_text[0]) + $split_text[1];
        echo '-'.$result.' 0 0 '.$result;
    }elseif ($split_text[0]<0 && $split_text[1]<0) {
        $result = $split_text[0] + $split_text[1];
        echo $result.' 0 0 '.$result;
    }else{
        $result = $split_text[0] + abs($split_text[1]);
        echo '0 -'.$result.' '.$result.' 0';
    }


        <?PHP
list($a, $b) = explode(' ', fgets(STDIN));
$r = abs($a) + abs($b);
if ($a >= 0 and $b >= 0)
    echo "0 $r $r 0\n";
else if ($a < 0 and $b >= 0)
    echo "-$r 0 0 $r\n";
else if ($a < 0 and $b < 0)
    echo "-$r 0 0 -$r\n";
else
    echo "0 -$r $r 0\n";
?>


<?php
	$n = trim(fgets(STDIN));
	function counter($x){
		$res = array(2,7,2,3,3,4,2,5,1,2);
		return $res[$x];
	}
	echo (counter($n[0])*counter($n[1]));

?>


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$n = trim(fgets($file));
$aArray = str_split(trim(fgets($file)));
$rArray = array_fill(2, 8, 0);
for ($i = 0; $i < $n; $i++) {
    switch ($aArray[$i]) {
        case 2:
            $rArray[2]++;
            break;
        case 3:
            $rArray[3]++;
            break;
        case 4:
            $rArray[2] += 2;
            $rArray[3]++;
            break;
        case 5:
            $rArray[5]++;
            break;
        case 6:
            $rArray[5]++;
            $rArray[3]++;
            break;
        case 7:
            $rArray[7]++;
            break;
        case 8:
            $rArray[7]++;
            $rArray[2] += 3;
            break;
        case 9:
            $rArray[7]++;
            $rArray[2] += 1;
            $rArray[3] += 2;
            break;
        default:
            continue;
            break;
    }
}
for ($i = 9; $i > 1; $i--) {
    for ($j = 0; $j < $rArray[$i]; $j++) {
        echo $i;
    }
}


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

$etalons = array(
  0 => array(),
  1 => array(),
  2 => array(2 => 1),
  3 => array(2 => 1, 3 => 1),
  4 => array(2 => 3, 3 => 1),
  5 => array(2 => 3, 3 => 1, 5 => 1),
  6 => array(2 => 4, 3 => 2, 5 => 1),
  7 => array(2 => 4, 3 => 2, 5 => 1, 7 => 1),
  8 => array(2 => 7, 3 => 2, 5 => 1, 7 => 1),
  9 => array(2 => 7, 3 => 4, 5 => 1, 7 => 1),
);

$counts = array(2 => 0, 3 => 0, 5 => 0, 7 => 0);
foreach (str_split($a) as $dig) {
  foreach ($etalons[$dig] as $num => $count) {
    $counts[$num] += $count;
  }
}

$asmDigits = array();
while ($counts[7]) {
  $asmDigits[] = 7;
  foreach ($etalons[7] as $num => $count) {
    $counts[$num] -= $count;
  }
}
while ($counts[5]) {
  $asmDigits[] = 5;
  foreach ($etalons[5] as $num => $count) {
    $counts[$num] -= $count;
  }
}
while ($counts[3]) {
  $asmDigits[] = 3;
  foreach ($etalons[3] as $num => $count) {
    $counts[$num] -= $count;
  }
}
while ($counts[2]) {
  $asmDigits[] = 2;
  foreach ($etalons[2] as $num => $count) {
    $counts[$num] -= $count;
  }
}

rsort($asmDigits);
echo implode('', $asmDigits), "\n";


<?php
trim(fgets(STDIN));
$num = trim(trim(fgets(STDIN)),'0');
$num .= '';
$map = array();
$map[0] = array();
$map[1] = array();
$map[2] = array(2);
$map[3] = array(3);
$map[4] = array(2,2,3);
$map[5] = array(5);
$map[6] = array(5,3);
$map[7] = array(7);
$map[8] = array(7,2,2,2);
$map[9] = array(7,3,3,2);
$final = array();
$len = strlen($num);
for($i = 0; $i < $len; $i++) {
	$rem = substr($num,$i,1)+0;
	$final = array_merge($final, $map[$rem]);
}
sort($final);
echo implode("",  array_reverse($final));
?>


<?php

function readArrayInt($std)
{
    $str = ReadArrayString($std);
    $a = array();
    $n = count($str);
    for ($i = 0; $i < $n; ++$i)
    {
        $a[] = $str[$i] + 0;
    }
    return $a;
}

function ReadArrayString($std)
{
    $str = trim(fgets($std));
    $str = explode(' ', $str);
    return $str;
}

$stdin = fopen("php://stdin", 'r');
$s = ReadArrayString($stdin)[0];
$len = strlen($s);
echo $len * 25 + 26;
fclose($stdin);

?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array_sum($c);
$e = round($d / $a);
$f = 0;
while(TRUE)
{
     if($e == $b)
     {
          break;
     }
     else
     {
          $a++;
          $d += $b;
          $e = round($d / $a);
          $f++;
     }
}
print $f;
?>


<?php

$n = 0;
$k = 0;
$data = array();

$i = 0;
while($line = trim(fgets(STDIN)))
{
	if (empty($line)) {
		break;
	}
    if ($i === 0) {
    	list($n, $k) = explode(' ', $line);
    	$n = intval($n);
    	$k = intval($k);
    } else {
    	$data = explode(' ', $line);
    	array_walk($data, function (&$v, $k) { $v = intval($v); });
    }
    $i++;
}

$marksSum = array_sum($data);
$marksCount = count($data);
$currentMark = $marksSum / $marksCount;
$requiredMark = floor($k) - 0.5;

while ($currentMark < $requiredMark) {
	$marksCount++;
	$marksSum += $k;
	$currentMark = $marksSum / $marksCount;
}

echo $marksCount - $n;


<?php
$a=explode(' ',trim(fgets(STDIN)));
$b=explode(' ',trim(fgets(STDIN)));
$i=0;
while (true){
    if ((array_sum($b)+$i*$a[1])/(count($b)+$i)>=$a[1]-0.5){
        print $i;
        break;
    }
    $i++;
}
?>


<?php
$line0 = trim(fgets(STDIN));
$line1 = trim(fgets(STDIN));
$line2 = trim(fgets(STDIN));

$line0 = str_split($line0);
$line1 = str_split($line1);
$line2 = str_split($line2);

$data = array_merge($line0, $line1, $line2);

$counts = array();
$counts['X'] = 0;
$counts['O'] = 0;
$counts['.'] = 0;

foreach ($data as $value) {
    $counts[$value]++;
}
//rjvvtyn

$illegal = false;
$draw = false;

// illegal

if (($counts['X'] - $counts['0']) > 1 || $counts['0'] > $counts['X']) $illegal = true;

// defining if someone won

function fullRow($array, $rowNum, $sign) {
    $index = $rowNum * 3;

    if ($array[$index] == $sign && $array[$index + 1] == $sign && $array[$index + 2] == $sign) return true;
    else return false;
}

function fullCol($array, $colNum, $sign) {
    if ($array[$colNum] == $sign && $array[$colNum + 3] == $sign && $array[$colNum + 6] == $sign) return true;
    else return false;
}

function fullDiag1($array, $sign) {
    if ($array[0] == $sign && $array[4] == $sign && $array[8] == $sign) return true;
    else return false;
}

function fullDiag2($array, $sign) {
    if ($array[2] == $sign && $array[4] == $sign && $array[6] == $sign) return true;
    else return false;
}

function playerWon($array, $sign) {
    for ($i = 0; $i < 3; $i++)
    {
        if (fullCol($array, $i, $sign)) return true;
        if (fullRow($array, $i, $sign)) return true;
    }

    if (fullDiag1($array, $sign) || fullDiag2($array, $sign)) return true;
    else return false;
}

$xWon = playerWon($data, 'X');
$oWon = playerWon($data, '0');

if (($xWon and $oWon) || (( $oWon && ($counts['0'] + 1 == $counts['X'])) || ($xWon && ($counts['0'] == $counts['X'])))) $illegal = true;

// draw

if ($illegal) echo 'illegal';
else if ($xWon || $oWon)
{
        if ($xWon) echo 'the first player won';
        else echo 'the second player won';
}
else
{
    if ($counts['X'] + $counts['0'] == 9)
    {
        echo 'draw';
    }
    else
    {
        if ($counts['X'] > $counts['0']) echo 'second';
        if ($counts['X'] <= $counts['0']) echo 'first';
        //else echo 'first';
    }
}

?>


<?php
$line0 = trim(fgets(STDIN));
$line1 = trim(fgets(STDIN));
$line2 = trim(fgets(STDIN));

$line0 = str_split($line0);
$line1 = str_split($line1);
$line2 = str_split($line2);

$data = array_merge($line0, $line1, $line2);

$counts = array();
$counts['X'] = 0;
$counts['O'] = 0;
$counts['.'] = 0;

foreach ($data as $value) {
    $counts[$value]++;
}

$illegal = false;
$draw = false;

// illegal

if (($counts['X'] - $counts['0']) > 1 || $counts['0'] > $counts['X']) $illegal = true;

// defining if someone won

function fullRow($array, $rowNum, $sign) {
    $index = $rowNum * 3;

    if ($array[$index] == $sign && $array[$index + 1] == $sign && $array[$index + 2] == $sign) return true;
    else return false;
}

function fullCol($array, $colNum, $sign) {
    if ($array[$colNum] == $sign && $array[$colNum + 3] == $sign && $array[$colNum + 6] == $sign) return true;
    else return false;
}

function fullDiag1($array, $sign) {
    if ($array[0] == $sign && $array[4] == $sign && $array[8] == $sign) return true;
    else return false;
}

function fullDiag2($array, $sign) {
    if ($array[2] == $sign && $array[4] == $sign && $array[6] == $sign) return true;
    else return false;
}

function playerWon($array, $sign) {
    for ($i = 0; $i < 3; $i++)
    {
        if (fullCol($array, $i, $sign)) return true;
        if (fullRow($array, $i, $sign)) return true;
    }

    if (fullDiag1($array, $sign) || fullDiag2($array, $sign)) return true;
    else return false;
}

$xWon = playerWon($data, 'X');
$oWon = playerWon($data, '0');

if (($xWon and $oWon) || (( $oWon && ($counts['0'] + 1 == $counts['X'])) || ($xWon && ($counts['0'] == $counts['X'])))) $illegal = true;

// draw

if ($illegal) echo 'illegal';
else if ($xWon || $oWon)
{
        if ($xWon) echo 'the first player won';
        else echo 'the second player won';
}
else
{
    if ($counts['X'] + $counts['0'] == 9)
    {
        echo 'draw';
    }
    else
    {
        if ($counts['X'] > $counts['0']) echo 'second';
        if ($counts['X'] <= $counts['0']) echo 'first';
        //else echo 'first';
    }
}

?>


<?php

$file = file_get_contents('php://stdin');

$file = preg_replace("/[^0-9a-z]+/i"," ",$file);

$number = explode(' ', $file);

// print_r($number);

$w = $number[0];
$h = $number[1];
$k = $number[2];

    $result = 0;
    $result += ($w + $h - 2) * 2;
    for ($i = $k - 1; $i > 0; $i--){
        $w -= 4;
        $h -= 4;
        $result += ($w + $h - 2) * 2;
}

// echo $result;
file_put_contents('php://stdout', $result);


<?php

$line = fgets(STDIN);

sscanf($line, '%d %d %d', $w, $h, $k);

$n = 0;

for ($i = 0; $i < $k; $i++) {
    $width = $w - $i * 4;
    $height = $h - $i * 4;
    $n += $width * 2 + $height * 2 - 4;
}

echo $n;


<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

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

function solve()
{
     $n = 2;
     $t = 0;
     for($i=0; $i<$n; $i++) {
          $a = IO::getArray();
          if($a[0] == 1) {
              $t++;
          }
           if($a[1] == 1) {
              $t++;
          }
     }
    if($t > 0) {
         $ans = $t == 4 ? 2 : 1;

    } else {
         $ans = 0;
    }

     IO::pr($ans);

}

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

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


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
$e = explode(" ", trim(fgets(STDIN)));
$f = min($d);
$g = max($e);
if($f < $g)
{
     if($c % $f == 0)
     {
          $h = $c / $f;
          $i = 0;
     }
     else
     {
          $h = floor($c / $f);
          $i = $c % $f;
     }
     print $g * $h + $i;
}
else
{
     print $c;
}
?>


<?php
list($n,$m,$k) = explode(' ', trim(fgets(STDIN)));
$aBuy = explode(' ', trim(fgets(STDIN)));
$aSell = explode(' ', trim(fgets(STDIN)));

$aBuyMin = min($aBuy);
$aSellMax = max($aSell);
if($aBuyMin >= $aSellMax){
    echo $k;
} else {
    $iBuyMin = min($aBuy);
    $iSellMax = max($aSell);
    $iCount = floor($k / $iBuyMin);
    $iReminder = $k % $iBuyMin;
    $iTotal = $iCount * $iSellMax  +  $iReminder;
    echo $iTotal;
}


<?php

list($x, $y, $a, $b) = explode(' ', line());

$x = intval($x);
$y = intval($y);
$a = intval($a);
$b = intval($b);

$lcm = lcm($x, $y);

print intval($b / $lcm) - intval(($a - 1) / $lcm);

function lcm($a, $b) {
  return $a * ($b / gcd($a, $b));
}

function gcd($a, $b) {
  return $b == 0 ? $a : gcd($b, $a % $b);
}

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


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = sqrt($a * $b / $c);
$e = sqrt($a * $c / $b);
$f = sqrt($b * $c / $a);
print 4 * ($d + $e + $f);
?>


<?php
    define ("TEST", false);
    if (TEST) $GLOBALS['file'] = fopen('input.txt', 'r');
    else $GLOBALS['file'] = fopen('php://stdin', 'r');
    function readStr(){return trim(fgets($GLOBALS['file']));}
    function readArr(){return explode(' ', readStr());}
    /***************************************************************/

    list($ab, $bc, $ac) = readArr();
    $all2 = $ab*$bc*$ac;
    $all = sqrt($all2);

    $c = $all/$ab;
    $a = $all/$bc;
    $b = $all/$ac;

    echo 4*$a + 4*$b + 4*$c;


<?php
$dir = fopen("php://stdin", 'r');
$s = stream_get_contents($dir);
$s = str_replace("\n", "", $s);
//$s="8679647744";
$s_array=str_split($s);
$lucky=array();

for ($i=0; $i < count($s_array); $i++) {
	if($s_array[$i]=="4" || $s_array[$i]=="7"){
		if(!isset($s_array[$i])){
			$lucky[$s_array[$i]]=1;
		}else{
			$lucky[$s_array[$i]]++;
		}
	}
}
ksort($lucky);
if(!count($lucky)){
	echo -1;
}else{
	$bigger=0;
	$bigger_key=-1;
	foreach ($lucky as $key => $value) {
		if($value > $bigger){
			$bigger = $value;
			$bigger_key = $key;
		}
	}
}
echo $bigger_key;


<?php
$dir = fopen("php://stdin", 'r');
$s = stream_get_contents($dir);
$s = str_replace("\n", "", $s);
//$s="8679647744";
$s_array=str_split($s);

$lucky=array();
$subs="";

for ($i=0; $i < count($s_array); $i++) {
	if($s_array[$i]=="4" || $s_array[$i]=="7"){
		//echo $s_array[$i]."\n";
		//$subs.= $s_array[$i];
		/*save and check next*/
		if(!isset($s_array[$i])){
			$lucky[$s_array[$i]]=1;
		}else{
			$lucky[$s_array[$i]]++;
		}
	}else{
		//$subs="";
	}

}
ksort($lucky);
//echo count($lucky);
if(!count($lucky)){
	echo -1;
}else{
	$bigger=0;
	$bigger_key=-1;
	foreach ($lucky as $key => $value) {
		if($value > $bigger){
			$bigger = $value;
			$bigger_key = $key;
		}
	}
}
echo $bigger_key;


<?php
$n = (int)trim(fgets(STDIN));
$k = (int)trim(fgets(STDIN));
$result = [$k, -$k];

for ($i=$n-1;$i>0;$i--) {
    $k = (int)trim(fgets(STDIN));
    $tmp = [];
    foreach ($result as $r) {
        $tmp[] = $r+$k;
        $tmp[] = $r-$k;
    }
    $result = $tmp;
}
foreach ($result as $r) {
        if ($r % 360 === 0) {
            echo 'YES';
            exit;
        }
}
echo 'NO';


<?php
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
echo $n*($n-2)-($n-1)*2+2;
?>


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$n = trim(fgets($file));
echo ($n - 2) * ($n - 2);


<?php

$n = file_get_contents("php://stdin");

echo ($n-2) * ($n-2);
?>


<?php
$dir                = fopen("php://stdin", 'r');
$contents           = stream_get_contents($dir);
$inputs             = explode("\n",$contents);
$problemsCount      = explode(' ', $inputs[0])[0];
$solverSkill        = explode(' ', $inputs[0])[1];

$problemDifficulty  = array_map('intval', explode(' ', $inputs[1]));
echo getMaximumProblems($problemsCount, $problemDifficulty, $solverSkill);

function getMaximumProblems($problemsCount, $problemDifficulty, $solverSkill)
{
    $maximumSolvedProblems    = 0;
    $firstProblemDifficulty   = $problemDifficulty[0];
    $lastProblemDifficulty    = $problemDifficulty[$problemsCount - 1];
    if($firstProblemDifficulty > $solverSkill && $lastProblemDifficulty  > $solverSkill)
    {
        return 0;
    }
    for($problemsCounter = 0; $problemsCounter < $problemsCount; $problemsCounter++)
    {
        if($problemDifficulty[$problemsCounter] <= $solverSkill)
        {
            $maximumSolvedProblems++;
            unset($problemDifficulty[$problemsCounter]);
        }

        if($problemDifficulty[$problemsCounter] > $solverSkill)
        {
            break;
        }
    }

    if(count($problemDifficulty) > 0) {
        $reversedArray  = array_reverse($problemDifficulty);
        for($problemsCounter = 0; $problemsCounter < count($problemDifficulty); $problemsCounter++)
        {
             if($reversedArray[$problemsCounter] <= $solverSkill)
            {
                $maximumSolvedProblems++;
                unset($reversedArray[$problemsCounter]);
            }

            if($reversedArray[$problemsCounter] > $solverSkill)
            {
                break;
            }
        }
    }

    return $maximumSolvedProblems;
}
?>


<?php
fscanf(STDIN,"%d %d",$arrSize,$k);
$arr=explode(' ',trim(fgets(STDIN)));
$pos=array();
$flag=0;
for ($i=0,$j=0; $i <$arrSize; $i++)
{
	if($arr[$i]>$k)
	{
		$pos[$j++]=$i;
        $flag=1;

	}
}
//print_r($pos);
if($flag==1)
  echo $arrSize-1-abs($pos[count($pos)-1]-$pos[0]);
else
  echo $arrSize;


<?php

$arr = explode(' ', trim(fgets(STDIN)));
$result = 0;

if ($arr[1] % $arr[0] != 0) {
    $result = -1;
} else {
    $factor = $arr[1] / $arr[0];
    while ($factor % 3 == 0) {
        $result ++;
        $factor = $factor / 3;
    }
    while ($factor % 2 == 0) {
        $result ++;
        $factor = $factor / 2;
    }
    if ($factor != 1) {
        $result = -1;
    }
}

echo $result;


<?php
// Входящее число: [0 < s < 99]
$s = trim(fgets(STDIN));
// Список числе от 1 до 19, 20, 30, 40, 50, 60, 70, 80, 90
$numbers = array('0' => 'zero', '1' => 'one', '2' => 'two', '3' => 'three', '4' => 'four', '5' => 'five', '6' => 'six', '7' => 'seven', '8' => 'eight', '9' => 'nine', '10' => 'ten', '11' => 'eleven', '12' => 'twelve', '13' => 'thirteen', '14' => 'fourteen', '15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen', '18' => 'eighteen', '19' => 'nineteen', '20' => 'twenty', '30' => 'thirty', '40' => 'forty', '50' => 'fifty', '60' => 'sixty', '70' => 'seventy', '80' => 'eighty', '90' => 'ninety');
// Если число меньше или равно 19
if ($s <= 19) {
	$result = $numbers[$s];
} else {
	// Проверяем второй символ введенного числа
	if($s[1]==0) {
		// Если 0, то выводим из массива
		$result = $numbers[$s];
	} else {
		// Если нет, то собираем число
		$first_number = $numbers[$s[0].'0'];
		$second_number = $numbers[$s[1]];
		$result = $first_number.'-'.$second_number;
	}
}
print($result);
?>


<?php

$number = readline();

$stringNumbers = array(
    1 => 'one',
    2 => 'two',
    3 => 'three',
    4 => 'four',
    5 => 'five',
    6 => 'six',
    7 => 'seven',
    8 => 'eight',
    9 => 'nine',
    10 => 'ten',
    11 => 'eleven',
    12 => 'twelve',
    13 => 'thirteen',
    15 => 'fifteen',
    18 => 'eighteen',
);

$stringFirstNumbers = array(
    1 => '',
    2 => 'twenty',
    3 => 'thirty',
    4 => 'forty',
    5 => 'fifty',
    6 => 'sixty',
    7 => 'seventy',
    8 => 'eighty',
    9 => 'ninety',
);

if ($number <= 13 || $number == 15 || $number == 18)
    echo $number == 0 ? 'zero' : $stringNumbers[$number];

else {
    $firstNumber = $number / 10;
    $secondNumber = $number % 10;

    if ((int)$firstNumber == 1) echo $stringNumbers[(int)$secondNumber].'teen';

    else echo $stringNumbers[(int)$secondNumber] ? $stringFirstNumbers[(int)$firstNumber].'-'.$stringNumbers[(int)$secondNumber] : $stringFirstNumbers[(int)$firstNumber];
}


<?php
// Входная строка
$string = trim(fgets(STDIN));
// Длина строки
$string_length = strlen($string);
// Искомое слово
$word = 'CODEFORCES';
// Длина искомого слова
$word_length = strlen($word);
// Ответ по-умолчанию
$answer = 'NO';
// Всего можно разделить слово "CODEFORCES" 9 способами
// и 1 раз слово будет целиком
for($i=1; $i <= $word_length; $i++) {
	/*
	C ODEFORCES
	CO DEFORCES
	COD EFORCES
	CODE FORCES
	CODEF ORCES
	CODEFO RCES
	CODEFOR CES
	CODEFORC ES
	CODEFORCE S
	CODEFORCES
	*/
	// Первая часть слова
	$first_slice = substr($word, 0, $i);
	// Вторая часть слова
	$second_slice = substr($word, $i, 11);
	// Длина второй части слова
	$second_slice_length = strlen($second_slice);
	// Есть ли в строке первая часть слова
	$pos = strpos($string, $first_slice);
	if ($pos === false) {
		// Нет совпадения
	} else {
		// Есть в какой-то позиции
		if($pos>0) {
			// Если первая часть слова не в начале, то
			// Разбиваем на 3 части правую часть строки
			// $string = $left.$center.$right;
			// До искомой первая части
			$left = substr($string, 0, $pos);
			// Сама первая часть слова
			$center = substr($string, $pos, $i);
			// Остаток строки (полностью)
			$right = substr($string, ($i+$pos), $string_length);
			if($right) {
				// Если существует правая часть, то неподходит, так как придется делить больше
			} else {
				// Если правой части нет, то центральная часть должна быть искомым слово
				if($center == $word) {
					$answer = 'YES';
				}
			}
		} else {
			// Если первая часть слова в начале, то правая часть строки (с конца) должна быть искомой второй частью слова
			// Обрезок правой строки (на длину слова)
			$right = substr($string, -$second_slice_length, $second_slice_length);
			if($right == $second_slice) {
				$answer = 'YES';
			}
		}
	}
}
// Вывожу ответ
print($answer);
?>


<?php
$s = trim(fgets(STDIN));
if (preg_match('#^(\w+CODEFORCES|C\w+ODEFORCES|CO\w+DEFORCES|COD\w+EFORCES|CODE\w+FORCES|CODEF\w+ORCES|CODEFO\w+RCES|CODEFOR\w+CES|CODEFORC\w+ES|CODEFORCE\w+S|CODEFORCES\w+)$#s', $s)) {
  echo "YES\n";
} else {
  echo "NO\n";
}


<?php
	// Main Computation
	function cuttingBanner($text = '') {
		$pattern = 'CODEFORCES';
		$n       = strlen($pattern);
		for ($i = 0; $i <= $n; $i++) {
			$substr  = substr($text, 0, $i);
			$substr .= ($i < $n) ? substr($text, - ($n - $i)) : '';
			if ($substr == $pattern) {
				return 'YES';
			}
		}
		return 'NO';
	}
	// Main
	function main() {
		$stdin = fopen("php://stdin", "r");
		$text = fgets($stdin, 200);
		$text = preg_replace("/[^A-Z]/", '', $text);
		print cuttingBanner($text) . "\n";
	}

	main();
?>


<?PHP

$fileIN = fopen("php://stdin", "r");
$fileOUT = fopen("php://stdout", "w");

$initialBanner = trim(fgets($fileIN));
$searchCodeforces = "CODEFORCES";

$sufixe = array();
$prefixe = array();

$le = 0;
$ri = 0;

for ($i = 0; $i < min(strlen($searchCodeforces), strlen($initialBanner)); ++$i) {
    if ($searchCodeforces[$i] == $initialBanner[$i]) {
        $le++;
    } else {
        break;
    }
}

$revin = strrev($initialBanner);
$codin = strrev($searchCodeforces);

for ($i = 0; $i < min(strlen($revin), strlen($codin)); ++$i) {
    if ($revin[$i] == $codin[$i]) {
        $ri++;
    } else {
        break;
    }
}

if ($ri + $le >= 10) {
    fprintf($fileOUT, "YES\n");
} else {
    fprintf($fileOUT, "NO\n");
}

fclose($fileIN);
fclose($fileOUT);

?>


<?php
$a = " " . trim(fgets(STDIN));
$b = "CODEFORCES";
$c = strpos($a, $b);
if(($c === 1) || ($c === (strlen($a) - 10)))
{
    print "YES";
}
else
{
    $d = array("C", "CO", "COD", "CODE", "CODEF", "CODEFO", "CODEFOR", "CODEFORC", "CODEFORCE");
    $e = array("ODEFORCES", "DEFORCES", "EFORCES", "FORCES", "ORCES", "RCES", "CES", "ES", "S");
    $f = 0;
    for($x = 0; $x < 9; $x++)
    {
        $g = substr($a, 1, $x + 1);
        $h = substr($a, strlen($a) - 9 + $x);
        if(($g == $d[$x]) && ($h == $e[$x]))
        {
            $f = 1;
            break;
        }
    }
    if($f == 1)
    {
        print "YES";
    }
    else
    {
        print "NO";
    }
}
?>


<?php
    $subject = trim(fgets(STDIN));
    $patterns = array(
        '/^([A-Z]+)CODEFORCES$/',
        '/^C([A-Z]+)ODEFORCES$/',
        '/^CO([A-Z]+)DEFORCES$/',
        '/^COD([A-Z]+)EFORCES$/',
        '/^CODE([A-Z]+)FORCES$/',
        '/^CODEF([A-Z]+)ORCES$/',
        '/^CODEFO([A-Z]+)RCES$/',
        '/^CODEFOR([A-Z]+)CES$/',
        '/^CODEFORC([A-Z]+)ES$/',
        '/^CODEFORCE([A-Z]+)S$/',
        '/^CODEFORCES([A-Z]+)$/'
    );
    foreach($patterns as $pattern){
        preg_match($pattern, $subject, $matches);
        //print_r($matches);
        if(count($matches)>0){
            echo "YES";
            exit();
        }
    }
    echo "NO";

?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = ceil($b / $a);
print $c;
?>


<?php
//define('STDIN', fopen('input.txt', 'r'));

function array_value_to_integer(&$arr) {
	foreach ($arr as &$value)
		$value = (int)$value;
	unset($value);
	return $arr;
}

$arrInput = explode(' ', trim(fgets(STDIN)));
list($n, $s) = array_value_to_integer( $arrInput ); //n - макс. номинал монет, s - сумма, которую нужно набрать

$divider = min($n, $s);
$result = (int)ceil($s / $divider);

echo( $result );

fclose(STDIN);

?>


<?php

//$input = '14 28';
$input = fgets(STDIN);
$inputs = explode(' ', $input);
$biggest = $inputs[0];
$S = $inputs[1];
echo ceil($S / $biggest);


<?php
	fscanf(STDIN , "%d", $N);
	$S = trim(fgets(STDIN));
	$A = array();
	$ctr = 0;
	for($i = 0 ;$i<$N;++$i)
	{
		if($S[$i]=='B')
			$ctr++;
		else
		{
			if($ctr)
				$A[]=$ctr;
			$ctr = 0 ;
		}
	}

	if($ctr)
			$A[]=$ctr;
	$ctr = 0 ;
	echo count($A) . "\n";
	foreach($A as $x)
		echo $x . " ";

?>


<?php
$input=trim(fgets(STDIN));
$ex= explode(" ", $input);
sort($ex);
$min1=$ex[2] - $ex[1];
$min2=$ex[1] - $ex[0];
echo $output=$min1 + $min2;
?>


<?php

###### IO ######
error_reporting(E_ALL);
error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	$stream = STDIN;
	if ($is_test)
		$stream = $f;
	/* begin body */
	list($_x1, $_x2, $_x3) = readStringExplodeNum($stream, ' ', true);
	$x1 = min($_x1, $_x3, $_x2);
	$x3 = max($_x1, $_x3, $_x2);
	$x2 = ($_x1 + $_x2 + $_x3) - $x1 - $x3;
	$minRes = 9999;
	for ($i = $x1; $i < $x3; $i++) {
		$pointRes = abs($x1 - $i) + abs($x2 - $i) + abs($x3 - $i);
		if ($pointRes < $minRes) {
			$minRes = $pointRes;
		}
	}
	echo $minRes;
	/* / end body */
}

if (empty($is_test))
	getAnswer();


<?php

$input = explode(" ",trim(fgets(STDIN)));
sort($input);
$two=$input[1];
$x=0;
$x += $two - $input[0];
$x+=$input[2] - $two;
echo $x;


<?php

###### IO ######
error_reporting(E_ALL);
error_reporting(0);

function readString($f) {
	$r = array(
		"\r" => '',
		"\n" => '',
	);
	return strtr(fgets($f), $r);
}

function readNumString($f) {
	return trim(fgets($f));
}

function stringToArray($str) {
	return str_split($str);
}

function readNum($f, $is_int = false) {
	$v = readNumString($f);
	return $is_int ? intval($v) : floatval($v);
}

function readStringExplode($f, $delimiter = ' ') {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = 'trim';
	return array_map($callf, $return);
}

function readStringExplodeNum($f, $delimiter = ' ', $is_int = false) {
	$v = readNumString($f);
	if ($delimiter == '') {
		$return = stringToArray($v);
	} else {
		$return = explode($delimiter, $v);
	}
	$callf = $is_int ? 'intval' : 'floatval';
	return array_map($callf, $return);
}

###### /IO ######

function getAnswer($is_test = false, $f = false) {
	$stream = STDIN;
	if ($is_test)
		$stream = $f;
	/* begin body */
	$arr = readStringExplodeNum($stream, ' ', true);
	rsort($arr);
  echo $arr[0] - $arr[2];
	/* / end body */
}

if (empty($is_test))
	getAnswer();


<?php

	$i = 0 ;
        $arr = explode(" ", trim(fgets(STDIN)));
	sort($arr);

	$out = $arr[2] - $arr[0] ;

	echo $out;
?>


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

$max = max($a, $b, $c);
$min = min($a, $b, $c);

echo $max-$min;


<?php
$v = explode(' ',trim(fgets(STDIN)));
sort($v, SORT_NUMERIC);
$ans = abs($v[0] - $v[1]) + abs($v[1] - $v[2]);
echo $ans . PHP_EOL;
exit;


<?php
    $in = fopen("php://stdin","r");
    //$in = fopen("input.txt","r");
    //$out = fopen("output.txt","w");

    $line = explode(" ",fgets($in));
    $n = (int)$line[0];
    $m = (int)$line[1];

    $max;
    $min;
    if ($n>$m) {
        $max = $n;
        $min = $m;
    } else {
        $max = $m;
        $min = $n;
    }

    echo ($max-1)." ".($min);
    //fclose($out);
?>


<?php

list($count, $a) = explode(" ", fgets(STDIN), 3);

if ($a % 2 == 0) {
    // четная сторона - убывание
    $time = 1 + $count / 2 - floor($a / 2);
} else {
    // нечетная сторона - возрастание
    $time = 1 + floor($a / 2);
}

echo $time;


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

$inp = explode(" ", $inp);

$street1[1] = 1;
$street2[1] = $inp[0];

for ($i=2; $i <= $inp[0]/2; $i++) {
  $street1[$i] = $street1[$i-1] + 2;
  $street2[$i] = $street2[$i-1] - 2;
}

if (($inp[1] % 2) != 0) {
  $result = array_search($inp[1], $street1);
} else {
  $result = array_search($inp[1], $street2);
}

echo $result;


<?php

function getnum(&$c = null)
{
    for ($c = fgetc(STDIN); false !== strpos(" \t\n\r\0\x0B", $c);$c = fgetc(STDIN));
    $result = ''; do { if (!is_numeric($c) && $c !== '.') break; $result .= $c; } while (null !== $c = fgetc(STDIN));

    return (float)$result;
}

$n = getnum();
$a = getnum();

if ($a % 2) {
    echo (++$a / 2) .PHP_EOL;
    return ;
}

echo (($n - $a) / 2 + 1) . PHP_EOL;


<?php

function sameXxorY($a,$b,$c){
    if($a == $b && $c == $a){
        return TRUE;
    }
    return FALSE;
}

function judge(array $a ,array $b){
    if($a[0] == $b[0] ){
        return 2;
    }
    if($a[1] == $b[1]){
        return 1;
    }
    return 0;
}

$aData = array();
for($i = 0; $i < 3;$i++){
    $sLine = trim(fgets(STDIN));
    $aData[] = explode(' ',$sLine);
}

if(sameXxorY($aData[0][0],$aData[1][0],$aData[2][0]) ||sameXxorY($aData[0][1],$aData[1][1],$aData[2][1]) ){
    echo 1;
    exit;
}

for($i = 0; $i < 3;$i++){
    for($j = $i + 1; $j < 3; $j++){
        $t = judge($aData[$i],$aData[$j]);
        if( $t != 0){
            $t = $t-1;
            $k = 3 - $i - $j ;
            if($aData[$k][$t] <= min($aData[$i][$t] , $aData[$j][$t]) || $aData[$k][$t] >= max($aData[$i][$t],$aData[$j][$t])){
                echo 2;
                exit;
            }

        }
    }
}

echo 3;
#var_dump($aData);


<?php
    $input = (int)file_get_contents("php://stdin");
    $i=0;
    $input=abs($input);
    $step=0;
    while(1)
    {
        $i+=$step;
        if($i%2==$input%2 && $input<=$i)
        {
            echo($step);
            break;
        }
        $step++;
    }
?>


<?php
list($a, $b, $c) = explode(' ',trim(fgets(STDIN)));

$r = ceil(($a * $c) / $b) - $c;
if($r < 0) print '0'; else print $r;
?>


<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d%d", $n, $k);
$answer = 0;
$answer += ceil($n * 2 / $k);
$answer += ceil($n * 5 / $k);
$answer += ceil($n * 8 / $k);

echo $answer;


<?php
list($n, $k) = explode(' ', readline());
echo ceil(($n*8)/$k) + ceil(($n*5)/$k) + ceil(($n*2)/$k);


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

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

print strtr($s, $a);

?>


<?php

while (FALSE !== ($passwordLine = fgets(STDIN))) {
    $hash = array();
    for($i = 0; $i < 10; $i ++){
        $line = trim(fgets(STDIN));
        $hash [$line] = $i;  // ;)
    }
    for($j = 0; $j < 8; $j++){
        echo $hash[substr($passwordLine, $j * 10, 10)];
    }
    echo PHP_EOL;
}


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$e = trim(fgets(STDIN));
$f = trim(fgets(STDIN));
$g = trim(fgets(STDIN));
$h = trim(fgets(STDIN));
$i = trim(fgets(STDIN));
$j = trim(fgets(STDIN));
$k = trim(fgets(STDIN));
$l = array($b, $c, $d, $e, $f, $g, $h, $i, $j, $k);
$n = 0;
$o = "";
for($x = 0; $x < 8; $x++)
{

    $m = substr($a, $n, 10);
    for($y = 0; $y < 10; $y++)
    {
        if($m == $l[$y])
        {
            $o .= $y;
        }
    }
    $n += 10;
}
print $o;
?>


#!/usr/bin/env php
<?php
$count = trim(fgets(STDIN));

$line = trim(fgets(STDIN));
$array = array_map('intval', explode(' ', $line));

for(;;) {
	rsort($array);
	if ($array[0] !== $array[$count - 1] && $array[1] !== 0) {
		$sub = $array[1];
		for ($i = 1; $i < $count; $i++) {
			if ($array[$i] !== $array[0]) {
				$sub = $array[$i];
				break;
			}
		}
		$array[0] = $array[0] - $sub;
	} else {
		echo array_sum($array);exit();
	}
}


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
rsort($b);
for($x = 1; $x <= 10000; $x++)
{
    if($b[0] > $b[count($b) - 1])
    {
        $b[0] = $b[0] - $b[count($b) - 1];
        rsort($b);
    }
    else
    {
        break;
    }
}
print array_sum($b);
?>


<?php
fscanf(STDIN,"%d",$n);
fscanf(STDIN,"%s",$str);
$alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$split=str_split($alpha);
for ($i=0; $i <strlen($str)-3 ; $i++)
{
	$str1=substr($str,$i,4);

		if(implode(',',array_keys($split,$str1[0]))>13)

			$g1=abs(implode(',',array_keys($split,$str1[0]))-26);
			//echo "$g1\n";

		else
			$g1=implode(',',array_keys($split,$str1[0]));

		if(implode(',',array_keys($split,$str1[1]))>15)
			$g2=abs(implode(',',array_keys($split,$str1[1]))-28);
		else

			$g2=abs(implode(',',array_keys($split,$str1[1]))-2);
			//echo "$g2\n";

		if(implode(',',array_keys($split,$str1[2]))<6)
			$g3=abs(implode(',',array_keys($split,$str1[2]))+7);
		else
			$g3=abs(19-implode(',',array_keys($split,$str1[2])));

		if(implode(',',array_keys($split,$str1[3]))>19)
			$g4=abs(32-implode(',',array_keys($split,$str1[3])));
		else
			$g4=abs(implode(',',array_keys($split,$str1[3]))-6);
		$count[$i]=$g1+$g2+$g3+$g4;

}
echo min($count);


<?php
fscanf(STDIN, "%d\n", $line1);
$line2 = trim(fgets(STDIN));
$count = strlen($line2);
if ($line1 == $count and !empty($line1) and !empty($line2)) {
    $arr = str_split($line2);
    foreach ($arr as $vl) {
        if ($vl != 'D' and $vl != 'U' and $vl != 'R' and $vl != 'L'){
            echo '-1';
            exit();
        }
    }
    $x = 0;
    $y = 0;
    for ($i = 0; $i <= $line1; $i++) {
    switch (current($arr)) {
	case 'L':
		--$x;
		break;

	case 'R':
		++$x;
		break;

	case 'U':
		++$y;
		break;

	case 'D':
		--$y;
		break;
    }
    next($arr);
    }
    $res = $line1 - abs($x) - abs($y);
    echo $res;
}else{
    echo '-1';
}
?>


<?php
    $n = trim(fgets(STDIN));
    $a = str_split(trim(fgets(STDIN)));
    $i = 0;
    foreach ($a AS $v) {
        if ($v == '+') {
            $i++;
        } elseif ($i > 0) {
            $i--;
        }
    }
    echo $i;
?>


<?php
error_reporting(0);

$fp = fopen('php://stdin','r');
list($a, $b, $m, $r0) = explode( " ",trim( str_replace( "\r\n", '', fgets($fp) ) ) );

$i = 0;
$r = $r0;
$numb = array();
while( $i < 4000000 ){
	$r = ($a * $r + $b) % $m;
	//
	if($i > 2750000){
		$numb[$r]++;
		//echo $i . ' ' . round(memory_get_usage()/1048576,2)." megabytes\n";
	}
	$i++;
}

$count = 0;
$min = min($numb);
foreach( $numb as $val ){
	$count += round($val / $min);
}
echo $count;
fclose($fp);
?>


<?php

function r($a, $b, $m, $r_past) {
  return ($a * $r_past + $b) % $m;
}

function find_t($a, $b, $m, $r0) {
  $values = array($r0 => TRUE);
  $last = $r0;
  while (1) {
    $last = ($a * $last + $b) % $m;
    if (isset($l[$last])) {
      $t = count($l) - array_search($last, array_keys($l));
      return $t;
    }
    $l[$last] = TRUE;
  }
}

list($a, $b, $m, $r0) = explode(' ', trim(fgets(STDIN)));
print (find_t($a, $b, $m, $r0)) . "\n";


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

    list($a, $b, $m, $r0) = read_array();

    $i=0;
    $r[$i] = $r0;
    do
    {
        $i++;
        $r[$i] = ($a*($r[$i-1])+$b)%$m;

    }
    while($i<2*$m);
    $r = array_reverse($r);

    function t($arr, $t)
    {
        for($i=0; $i<$t; $i++)
        {
            if($arr[$i] != $arr[$t+$i]) return false;
        }
        return true;
    }

    for ($k=1; $k<=$m; $k++)
    {
        if(t($r, $k))
        {
            echo $k;die();
        }
    }


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
if($a == 1)
{
     print "0";
}
else
{
     $e = min($b, $c);
     $f = min($b, $c, $d);
     $g = ($a - 1) * $f;
     print $e + $g - $f;
}
?>


<?php
// Retrieve input and show output
$stream = fopen("php://stdin", "r");
$input = stream_get_contents($stream);
$inputs = preg_split("/[\s]+/", $input);
echo func($inputs);

// Codeforces Contest 127 Division 2 Problem C
function func($in) {
$x = $in[0];
if ($x == 3) {return 5;}
$q = 0;
while (true) {
	if ($x <= (pow($q, 2) + pow($q+1, 2))) {return (2 * $q + 1);}
	$q++;
}
}

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


<?php

$f = fopen('php://stdin', 'r');
list($n, $d) = explode(' ', rtrim(fgets($f)));
$a = explode(' ', rtrim(fgets($f)));
$m = rtrim(fgets($f));

$hooks = array(); // [] does not work!
foreach ($a as $index => $price) {
  $hooks[] = array(
    'id' => $index+1,
    'price' => $price
  );
}

usort($hooks, function($a, $b) {
  return ($a['price'] < $b['price']) ? -1 : 1;
});

$rubles = 0;
$min = min($m, $n);
for ($i = 0; $i < $min; $i++) {
  $rubles += $hooks[$i]['price'];
}

if ($m > $n) {
  $rubles -= ($m-$n)*$d;
}

echo $rubles."\n";

?>


<?php
$a = "." . trim(fgets(STDIN));
$b = strpos($a, "ABC");
$c = strpos($a, "BCA");
$d = strpos($a, "CBA");
$e = strpos($a, "BAC");
$f = strpos($a, "ACB");
$g = strpos($a, "CAB");
if(($b == TRUE) || ($c == TRUE) || ($d == TRUE) || ($e == TRUE) || ($f == TRUE) || ($g == TRUE))
{
     print "Yes";
}
else
{
     print "No";
}
?>


<?php

print preg_match('/A(BC|CB)|B(AC|CA)|C(AB|BA)/', substr(fgets(STDIN), 0, 100)) ? 'YES' : 'NO';


<?php

list($h, $m) = explode(':', trim(fgets(STDIN)));
$n = trim(fgets(STDIN));

$time = mktime($h, $m, 0, 11, 11, 2006);

$time = $time + ($n*60);

$asw = date('H:i', $time);

echo $asw;


<?php
/*
 * Secdra @2020
 */

fscanf(STDIN, "%s", $time);
fscanf(STDIN, "%d", $a);

$timea = DateTime::createFromFormat("H:i", trim($time));

$timea->modify("+{$a} minutes");

printf("%s", $timea->format('H:i'));


<?php
$str=trim(fgets(STDIN));
$split=str_split($str);
$count=count(array_unique($split));
if($count==1)
{
	echo "$count";
}
else
{
 $count=1;
 for ($i=0; $i <count($split) ; $i++)
  {
 		# code...
    $rmvLst=array_pop($split);
	array_unshift($split, $rmvLst);
	$str1=implode('',$split);
	if($str1==$str)
	 {
		echo "$count";
		break;
	 }
	 $count++;

  }

}


<?php
$a = trim(fgets(STDIN));
$b = array();
$c = 1;
for($x = 0; $x < strlen($a); $x++)
{
     $d = substr($a, 0, strlen($a) - $c);
     $e = substr($a, strlen($a) - $c);
     $a = $e . $d;
     $b[$x] = $a;
}
$f = array_unique($b);
print count($f);
?>


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

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

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

  $r = pow(2, $p) - 1;
  echo $r.PHP_EOL;
}

?>


<?php
  $f = fopen('php://stdin', 'r');
  $param = explode(" ", str_replace(["\r", "\n"], "", fgets($f)));
  $sequence = explode(" ", str_replace(["\r", "\n"], "", fgets($f)));
  $button = explode(" ", str_replace(["\r", "\n"], "", fgets($f)));
  $out = '';

  for ($i = 0; $i < $param[0]; $i++) {
    if (in_array($sequence[$i], $button)) $out.= $sequence[$i] . ' ';
  }
  echo rtrim($out, ' ');
?>


<?php

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

$max = 0;
foreach (range(1, $n - 1) as $value)
{
    $aDiv = $value;
    $bDiv = $n - $value;
    $max = max($max, min(floor($a / $aDiv), floor($b / $bDiv)));
}

echo $max;


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e, $f) = explode(" ", trim(fgets(STDIN)));
$g = trim(fgets(STDIN));
$h = $a + $b + $c;
$i = $d + $e + $f;
$j = ceil($h / 5);
$k = ceil($i / 10);
if(($j + $k) <= $g)
{
    print "YES";
}
else
{
    print "NO";
}
?>


<?php
    $a = ceil(array_sum(explode(" ", trim(fgets(STDIN))))/5);
    $b = ceil(array_sum(explode(" ", trim(fgets(STDIN))))/10);
    if($a + $b > trim(fgets(STDIN)))
        echo 'NO' . PHP_EOL;
    else echo 'YES' . PHP_EOL;
?>


<?php
    $a = ceil(array_sum(explode(" ", trim(fgets(STDIN))))/5);
    $b = ceil(array_sum(explode(" ", trim(fgets(STDIN))))/10);
    fscanf(STDIN, "%d", $n);
    if($a + $b > $n)
        echo 'NO' . PHP_EOL;
    else echo 'YES' . PHP_EOL;
?>


<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');

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

$result = '';

for($i=0;$i<strlen($s);$i++){

    if ($i==0 && $s[$i]=='9'){
        $result.=$s[$i];
        continue;
    }

    if ($s[$i]>4){
        $t = (9 - $s[$i]);
        $result=$result.$t;
    } else $result.=$s[$i];
}

if ($result=='0') exit($s);

echo $result;


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

$res = '';

foreach (str_split($s) as $i => $ch) {
  $ch = (int)$ch;
  if ($ch >= 5) {
    if ($i != 0 || $ch != 9) {
      $ch = 9 - $ch;
    }
  }
  $res .= $ch;
}

echo "$res\n";


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


<?php

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

$num = file($in);

$a = str_split(trim($num[0]));

sort($a, SORT_NUMERIC);

$a = join('', $a);

$a = preg_replace('/^(0*)([^0])/', '$2$1', $a);

echo $a === trim($num[1]) ? 'OK' : 'WRONG_ANSWER';


<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = str_split($a);
$d = 0;
sort($c);
for($x = 0; $x < count($c); $x++)
{
    if($c[$x] == 0)
    {
       $d++;
    }
}
if($d > 0)
{
    $c = array_slice($c, $d);
    if(count($c) == 1)
    {
        print "WRONG_ANSWER";
    }
    else
    {
        for($x = 1; $x <= $d; $x++)
        {
            array_splice($c, 1, 0, "0");
        }
        if(implode($c) === $b)
        {
            print "OK";
        }
        else
        {
            print "WRONG_ANSWER";
        }
    }
}
else
{
    if(implode($c) === $b)
    {
        print "OK";
    }
    else
    {
        print "WRONG_ANSWER";
    }
}
?>


<?php
$input = trim(file_get_contents('php://stdin'));
list($n, $a, $b) = explode(' ', $input);

echo min($n - $a, $b + 1);


<?php
list($n, $a, $b) = explode(' ', trim(fgets(STDIN)));

$k = 1 + $b;

if ($k > $n - $a)
    while ($k > $n - $a)
        $k--;

echo $k;

?>


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$d = $a - $b;
if($d > $c)
{
    print $c + 1;
}
elseif($d == $c)
{
    print $c;
}
else
{
    print $d;
}
?>


<?php
    $k = (int)readline();
    $l = (int)readline();
    $x = $k;
    $counter = 0;
    while($x < $l){
        $x *= $k;
        $counter ++;
    }
    if($x == $l){
        echo("YES"),("\n");
        echo($counter),("\n");
    } else{
        echo("NO"),("\n");
    }
?>


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

$k = trim(fgets($f));
$l = trim(fgets($f));

$result = $k;
$n = 0;
while($result<$l){
    $result*=$k;
    $n++;

}

if ($result==$l){
    echo "YES\n";
    echo $n;
    exit;
}

echo "NO";


<?php
    list( $x, $y ) = explode(" ", trim(fgets(STDIN)));
    if( log($x) * $y > log($y) * $x )
        echo '>';
    else if(log($x) * $y < log($y) * $x)
        echo '<';
    else echo '=';
?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = $b * log($a);
$d = $a * log($b);
if($c < $d)
{
     print "<";
}
elseif($c == $d)
{
     print "=";
}
elseif($c > $d)
{
     print ">";
}
?>


<?php
list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
list($d, $e, $f) = explode(" ", trim(fgets(STDIN)));
$d -= $a;
if($d < 0)
{
     print "NO";
}
else
{
     if($d + $e >= $b)
     {
          $g = ($d + $e - $b) + $f;
          if($g >= $c)
          {
               print "YES";
          }
          else
          {
               print "NO";
          }
     }
     else
     {
          print "NO";
     }
}
?>


<?php
$word1 = explode(' ', fgets(STDIN));
$word2 = explode(' ', fgets(STDIN));

if (intval($word2[0]) < intval($word1[0]))
	die ('NO');

if ((intval($word2[0]) + intval($word2[1]) - intval($word1[0])) < $word1[1])
	die ('NO');

if (intval($word2[0]) + intval($word2[1]) + intval($word2[2]) < intval($word1[0]) + intval($word1[1]) + intval($word1[2]))
	die ('NO');

die ('YES');


<?php

function solve(int $x, int $y, int $z, int $a, int $b, int $c)
{
    if ($x > $a || $x + $y > $a + $b || $x + $y + $z > $a + $b + $c) {
        return 1;
    } else {
        return 0;
    }
}

list($x, $y, $z) = explode(' ', trim(fgets(STDIN)));
list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));

$ans = solve($x, $y, $z, $a, $b, $c);
echo ['YES', 'NO'][$ans];


<?php

list($x,$y,$z) = explode(' ', trim(fgets(STDIN)));
list($a,$b,$c) = explode(' ', trim(fgets(STDIN)));

$sAll = $a + $b + $c;

if(
    $x>$a ||
    ($y > ($a + $b - $x ))  ||
    ($z > ($sAll - $x - $y))
){
    echo 'NO';
} else{
    echo 'YES';
}


<?php
list($num, $a, $b, $c)=explode(" ", trim(fgets(STDIN)));
$x=0;
while (TRUE) {
    if (($num + $x) % 4 == 0) {
        //echo $x;
        break;
    }else $x++;
}
if ($x == 0) {
    echo 0;

}elseif ($x == 1) {
   if ($a > 3 * $c or $a > $b + $c) {
        if ($b + $c > 3 * $c) {
             echo 3 * $c;
        }else echo $b + $c;
   }else echo $a;

}elseif ($x == 3) {
  if ($a + $b > $c and $c < (3 * $a)) {
echo $c;
}elseif ($b + $a < (3 * $a)) {

    echo $a + $b;
}else echo 3 * $a;

}elseif ($x == 2) {
    if ($b < (2 * $a) and $b < 2 * $c) {
    echo $b;
    }elseif (2 * $c < $x * $a) { echo 2 * $c; }else echo $x * $a ;
}

?>


<?php
# $n=number of copybooks she has, $a,$b,$c 1, 2 and 3 copybook pack cost, $k = need to buy
list($n, $a, $b, $c) = explode(" ", trim(fgets(STDIN)));
$k = 4 - ($n % 4);
if ($k == 4) {
	die("0\n");
}
$cost = array();

switch ($k) {
	case 1:
		$cost[] = $a;
		$cost[] = $c * 3;
		$cost[] = $b + ($a * 3);
		$cost[] = $b + $c;
		break;

	case 2:
		$cost[] = $a * 2;
		$cost[] = $b;
		$cost[] = $c * 2;
		break;
	case 3:
		$cost[] = $a * 3;
		$cost[] = $b + $a;
		$cost[] = $c;
		break;
}
asort($cost);
// print_r($cost);

foreach ($cost as $c) {
	die($c."\n");
}
//die($cost[0]."\n");


<?php
$str=trim(fgets(STDIN));
$rev=strrev($str);
$len=strlen($str);

if($str!=$rev)
	echo "$len";
else
{
	for ($i=1; $i <$len; $i++)
	{
		$flag=0;
		$sbstr=substr($str,$i);
		$revSbstr=strrev($sbstr);
		if($sbstr!=$revSbstr)
		{
          echo strlen($sbstr);
          $flag=1;
          break;
		}

	}
	if ($flag==0)
	 {
		echo "0";
	 }
}


<?php
$a = str_split(trim(fgets(STDIN)));
$b = array_unique($a);
if(count($b) == 1)
{
     print "0";
}
else
{
     $c = floor(count($a) / 2);
     $d = 0;
     $e = count($a) - 1;
     $f = 0;
     for($x = 0; $x < $c; $x++)
     {
          if($a[$d] != $a[$e])
          {
               $f = 1;
               break;
          }
          else
          {
               $d++;
               $e--;
          }
     }
     if($f == 0)
     {
          print count($a) - 1;
     }
     elseif($f == 1)
     {
          print count($a);
     }
}
?>


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

    $primes = Array(2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97);

    $dividers[1] = Array();
    $params = explode(' ', trim(fgets($input)));
    for ($i=2;$i<=max($params);$i++) {
        $current = $i;
        $k=0;
        while ($current!=1) {
            while ($current%$primes[$k]==0) {
                $current = $current / $primes[$k];
                $dividers[$i][] = $primes[$k];
            }
            $k++;
        }
    }

    $sums = 0;
    $solve[1] = 1;
    for ($a=1;$a<=$params[0];$a++) {
        for ($b=1;$b<=$params[1];$b++) {
            for ($c=1;$c<=$params[2];$c++) {
                if (!isset($solve[$a*$b*$c])) {
                    $mergeArray = array_merge($dividers[$a],$dividers[$b],$dividers[$c]);
                    $mergeArray = array_count_values($mergeArray);
                    //print_r($mergeArray);

                    $sum = 1;
                    $sizeArray = count($mergeArray);
                    for($i=0;$i<$sizeArray;$i++) {
                        $sum *= (array_pop($mergeArray) + 1);
                    }
                    $sum = $sum;
                    $sums += $sum;
                    $solve[$a*$b*$c] = $sum;
                }
                else {$sums += $solve[$a*$b*$c];}
            }
        }
    }

    echo $sums;
    fclose($input);
?>


<?php

function gcd($a, $b) {
    while ($a <> 0 && $b <> 0) {
        if ($a > $b)
            $a = $a % $b;
        else
            $b = $b % $a;
    }
    return abs($a + $b);
}

$input = rtrim(fgets(STDIN));
$raw = explode(' ', $input);

$n = (int)$raw[0];

for ($i = (int)($n / 2); $i > 0; $i--) {
    $a = $i;
    $b = $n - $i;

    if ($a >= $b) {
        continue;
    }

    $gcd = gcd($a, $b);

    if ($gcd == 1) {
        echo $a . ' ' . $b . PHP_EOL;
        die;
    }
}


<?php
$n=fgets(STDIN);
$input=fgets(STDIN);
$san=preg_match_all('/(SF)/',$input);
$fra=preg_match_all('/(FS)/',$input);
if($san > $fra){
      echo "YES";
}else{
      echo "NO";
}


<?php
readline();
$s = readline();
echo substr_count($s, 'SF') > substr_count($s, 'FS') ? 'YES' : 'NO';


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

/* Perform action N times. Can return values in array */
function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}

/* Integral. Keys preserved. By reference. */
function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}

/* Difference. Keys preserved. By reference. */
function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}

function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();

$cnt = 0;
for ($a = 1; $a<=$n; $a++) {
	for ($b=$a; $b<=$n; $b++) {
		$c = $a^$b;
		if ($c>=$b && $c<=$n && ($c+$a)>$b && ($a+$b)>$c && ($b+$c)>$a) {
			//echo "$a, $b, $c, " . ($a^$b^$c) . "\n";
			$cnt++;
		}
	}
}

echo $cnt;


<?php
list($w, $h) = explode(' ', trim(fgets(STDIN)));
list($u1, $d1) = explode(' ', trim(fgets(STDIN)));
list($u2, $d2) = explode(' ', trim(fgets(STDIN)));
$res = $w;
while ($h >= 0) {
    if ($d1 == $h || $d2 == $h) {
        if ($d1 == $h) {
            $res = $res - $u1 + $h;
        }
        if ($d2 == $h) {
            $res = $res - $u2 + $h;
        }
        if ($res < 0) {
            $res = 0;
        }
    } else {
        $res += $h;
    }
    $h--;
}
echo $res;


<?php

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

list($w, $h) = explode(" ", rtrim(fgets($in)));
list($A1, $B1) = explode(" ", rtrim(fgets($in)));
list($A2, $B2) = explode(" ", rtrim(fgets($in)));

$now = $w;

for ($i=$h; $i>0; $i--){
    $now += $i;
    if($i == $B1)$now -= $A1;
    if($i == $B2)$now -= $A2;
    if($now < 0)$now = 0;
}

echo $now . "\n";

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

?>