Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't. Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of pieces in the chocolate bar. The second line contains n integers ai (0 ≤ ai ≤ 1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.

Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.

NoteIn the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks.In the second sample you can break the bar in four ways:10|10|11|010|110|1|011|01|01

<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ",trim(fgets(STDIN)));
    $sum = array_sum($a);
    if ($sum == 0)
    {
        echo("0");

    }
    else
    {
        $res = 1;
        $pre = -1;
        for ($i = 0 ; $i < $n ; $i ++)
        {
            if ($a[$i] == 1)
            {
                if ($pre != -1)
                {
                    $res *= $i - $pre;
                }
                $pre = $i ;
            }
        }

        echo(number_format($res,0,'',''));
    }

?>

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/26  9:13
 */
//组合数学问题。
fscanf(STDIN,"%d",$n);
$bans = array();
$line = stream_get_line(STDIN,1000000,"\n");
$line = rtrim($line);//去除右边的换行符。
$bans = explode(" ",$line);

//var_dump($bans);
$result = 0;
$prev = -1;
//连续的的找1，只有出现1的时候才能产生新组合。
//遇到一个1，就是前面的1的方案数，乘上到这个1的区间切割方案，也就是posi - posi-1
for($i = 0 ; $i < $n;$i++){
    if($bans[$i] == 1){
        if($prev == -1){
            $result = 1;
        }else{
            $result *= $i - $prev;
        }
        $prev = $i;
    }
}
fprintf(STDOUT,"%.0f",$result);

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

$counter = 0;
while( $line = fgets( $f ) ) {
  if ($counter == 1) {
      $nutsLine = $line;
  }
  $counter ++ ;
}

$nuts = explode(' ', $nutsLine);
$length = sizeof($nuts);
$vars = 0;
$countMode = false;
$tempVars = 0;
$zero = true;
foreach($nuts as $nut) {
    if ($nut == 1) {
        $zero = false;
    }
}
if ($zero) {
    echo '0';
    die();
}
for($i=0; $i < $length; $i++) {
    if (!$countMode && ($nuts[$i] == '1')) {
        $countMode = true;
        continue;
    }
    if ($countMode && ($nuts[$i] == 0)) {
        $tempVars ++;
    }

    if ($countMode && ($nuts[$i] == 1)) {
        if ($tempVars > 0) {
            $tempVars ++;
            if ($vars > 0) {
                $vars = $vars * $tempVars;
            } else {
                $vars = $tempVars;
            }
            $tempVars = 0;
        } else {

        }
    }

}
if ($vars == 0) {
    echo '1';
} else {
    echo number_format($vars, 0, '', '');
}

?>

<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ",trim(fgets(STDIN)));
    $sum = array_sum($a);
    if ($sum == 0)
    {
        echo("0");

    }
    else
    {
        $res = 1;
        $pre = -1;
        for ($i = 0 ; $i < $n ; $i ++)
        {
            if ($a[$i] == 1)
            {
                if ($pre != -1)
                {
                    $res *= $i - $pre;
                }
                $pre = $i ;
            }
        }

        print($res);
    }

?>

<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ",trim(fgets(STDIN)));
    $sum = array_sum($a);
    if ($sum == 0)
    {
        echo("0");

    }
    else
    {
        $res = 1;
        $pre = -1;
        for ($i = 0 ; $i < $n ; $i ++)
        {
            if ($a[$i] == 1)
            {
                if ($pre != -1)
                {
                    $res *= $i - $pre;
                }
                $pre = $i ;
            }
        }

        echo($res);
    }

?>

<?php
    $n = trim(fgets(STDIN));
    $a = explode(" ",trim(fgets(STDIN)));
    $sum = array_sum($a);
    if ($sum == 0)
    {
        echo("0");

    }
    else
    {
        $res = 1;
        $pre = -1;
        for ($i = 0 ; $i < $n ; $i ++)
        {
            if ($a[$i] == 1)
            {
                if ($pre != -1)
                {
                    $res *= $i - $pre;
                }
                $pre = i ;
            }
        }

        echo($res);
    }

?>

<?php
/**
 * Author: 七柳先森
 * Date: 2016/1/26  9:13
 */
//组合数学问题。
fscanf(STDIN,"%d",$n);
$bans = array();
$line = stream_get_line(STDIN,1000000,"\n");
$line = rtrim($line);//去除右边的换行符。
$bans = explode(" ",$line);

//var_dump($bans);
$result = 0;
$prev = -1;
//连续的的找1，只有出现1的时候才能产生新组合。
//遇到一个1，就是前面的1的方案数，乘上到这个1的区间切割方案，也就是posi - posi-1
for($i = 0 ; $i < $n;$i++){
    if($bans[$i] == 1){
        if($prev == -1){
            $result = 1;
        }else{
            $result *= $i - $prev;
        }
        $prev = $i;
    }
}
fprintf(STDOUT,"%d",$result);

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

$counter = 0;
while( $line = fgets( $f ) ) {
  if ($counter == 1) {
      $nutsLine = $line;
  }
  $counter ++ ;
}

$nuts = explode(' ', $nutsLine);
$length = sizeof($nuts);
$vars = 0;
$countMode = false;
$tempVars = 0;
for($i=0; $i < $length; $i++) {
    if (!$countMode && ($nuts[$i] == '1')) {
        // $vars ++;
        $countMode = true;
        continue;
    }
    if ($countMode && ($nuts[$i] == 0)) {
        $tempVars ++;
        continue;
    }

    if ($countMode && ($nuts[$i] == '1')) {
        $vars = $vars + $tempVars;
        if ($tempVars > 0) {
            $vars ++;
        }
        $tempVars = 0;
        $countMode = false;
        if ($nuts[$i+1] == '0') {
            $countMode = true;
        }
    }
}
if ($vars == 0) {
    echo '1';
} else {
    echo $vars;
}

?>

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

$counter = 0;
while( $line = fgets( $f ) ) {
  if ($counter == 1) {
      $nutsLine = $line;
  }
  $counter ++ ;
}

$nuts = explode(' ', $nutsLine);
$length = sizeof($nuts);
$vars = 0;
$countMode = false;
$tempVars = 0;
$zero = true;
foreach($nuts as $nut) {
    if ($nut == '1') {
        $zero = false;
    }
}
if ($zero) {
    echo '0';
    die();
}
for($i=0; $i < $length; $i++) {
    if (!$countMode && ($nuts[$i] == '1')) {
        $countMode = true;
        continue;
    }
    if ($countMode && ($nuts[$i] == 0)) {
        $tempVars ++;
    }

    if ($countMode && ($nuts[$i] == 1)) {
        if ($tempVars > 0) {
            $tempVars ++;
            if ($vars > 0) {
                $vars = $vars * $tempVars;
            } else {
                $vars = $tempVars;
            }
            $tempVars = 0;
        } else {

        }
    }

}
if ($vars == 0) {
    echo '1';
} else {
    echo number_format($vars, 0, '', '');
}

?>

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

$counter = 0;
while( $line = fgets( $f ) ) {
  if ($counter == 1) {
      $nutsLine = $line;
  }
  $counter ++ ;
}

$nuts = explode(' ', $nutsLine);
$length = sizeof($nuts);
$vars = 0;
$countMode = false;
$tempVars = 0;
$zero = true;
foreach($nuts as $nut) {
    if ($nut == '1') {
        $zero = false;
    }
}
if ($zero) {
    echo '0';
    die();
}
for($i=0; $i < $length; $i++) {
    if (!$countMode && ($nuts[$i] == '1')) {
        $countMode = true;
        continue;
    }
    if ($countMode && ($nuts[$i] == 0)) {
        $tempVars ++;
    }

    if ($countMode && ($nuts[$i] == 1)) {
        if ($tempVars > 0) {
            $tempVars ++;
            if ($vars > 0) {
                $vars = $vars * $tempVars;
            } else {
                $vars = $tempVars;
            }
            $tempVars = 0;
        } else {

        }
    }

}
if ($vars == 0) {
    echo '1';
} else {
    echo $vars;
}

?>

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

$counter = 0;
while( $line = fgets( $f ) ) {
  if ($counter == 1) {
      $nutsLine = $line;
  }
  $counter ++ ;
}

$nuts = explode(' ', $nutsLine);
$length = sizeof($nuts);
$vars = 0;
$countMode = false;
$tempVars = 0;
for($i=0; $i < $length; $i++) {
    if (!$countMode && ($nuts[$i] == '1')) {
        // $vars ++;
        $countMode = true;
        continue;
    }
    if ($countMode && ($nuts[$i] == 0)) {
        $tempVars ++;
        continue;
    }

    if ($countMode && ($nuts[$i] == '1')) {
        $vars = $vars + $tempVars;
        if ($tempVars > 0) {
            $vars ++;
        }
        $tempVars = 0;
        $countMode = false;
        if ($nuts[$i+1] == '0') {
            $countMode = true;
        }
    }
}

echo $vars;

?>

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

$counter = 0;
while( $line = fgets( $f ) ) {
  if ($counter == 1) {
      $nutsLine = $line;
  }
  $counter ++ ;
}

$nuts = explode(' ', $nutsLine);
$length = sizeof($nuts);
$vars = 0;
$countMode = false;
$tempVars = 0;
for($i=0; $i < $length; $i++) {
    if (!$countMode && ($nuts[$i] == '1')) {
        $vars ++;
        $countMode = true;
        continue;
    }
    if ($countMode && ($nuts[$i] == 0)) {
        $tempVars ++;
        continue;
    }

    if ($countMode && ($nuts[$i] == '1')) {
        $vars = $vars + $tempVars;
        if ($i != ($length -1)) {
            $vars++;
        }
        $tempVars = 0;
    }
}

echo $vars;

?>

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

$counter = 0;
while( $line = fgets( $f ) ) {
  if ($counter == 1) {
      $nutsLine = $line;
  }
  $counter ++ ;
}

$nuts = explode(' ', $nutsLine);
$length = sizeof($nuts);
$vars = 0;
$countMode = false;
$tempVars = 0;
$zero = true;
foreach($nuts as $nut) {
    if ($nut == '1') {
        $zero = false;
    }
}
if ($zero) {
    echo '0';
    die();
}
for($i=0; $i < $length; $i++) {
    if (!$countMode && ($nuts[$i] == '1')) {
        // $vars ++;
        $countMode = true;
        continue;
    }
    if ($countMode && ($nuts[$i] == 0)) {
        $tempVars ++;
    }

    if ($countMode && ($nuts[$i] == '1')) {
        if ($tempVars > 0) {
            $vars = $vars + $tempVars;
            $vars ++;
            $countMode = false;
        }
        $tempVars = 0;

        if ($nuts[$i+1] == '0') {
            $countMode = true;
        }
    }
    /*
    if ($i == ($length - 1)) {
        if ($tempVars > 0) {
            $vars ++;
        }
    }
    */
}
if ($vars == 0) {
    echo '1';
} else {
    echo $vars;
}

?>

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

$counter = 0;
while( $line = fgets( $f ) ) {
  if ($counter == 1) {
      $nutsLine = $line;
  }
  $counter ++ ;
}

$nuts = explode(' ', $nutsLine);
$length = sizeof($nuts);
$vars = 0;
$countMode = false;
$tempVars = 0;
for($i=0; $i < $length; $i++) {
    if (!$countMode && ($nuts[$i] == '1')) {
        $vars ++;
        $countMode = true;
        continue;
    }
    if ($countMode && ($nuts[$i] == 0)) {
        $tempVars ++;
        continue;
    }

    if ($countMode && ($nuts[$i] == '1')) {
        $vars = $vars + $tempVars;
        if (($i != ($length -1)) && ($tempVars > 0)) {
            $vars++;
        }
        $tempVars = 0;
    }
}

echo $vars;

?>

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

$counter = 0;
while( $line = fgets( $f ) ) {
  if ($counter == 1) {
      $nutsLine = $line;
  }
  $counter ++ ;
}

$nuts = explode(' ', $nutsLine);
$length = sizeof($nuts);
$vars = 0;
$countMode = false;
$tempVars = 0;
$zero = true;
foreach($nuts as $nut) {
    if ($nut == '1') {
        $zero = false;
    }
}
if ($zero) {
    echo '0';
    die();
}
for($i=0; $i < $length; $i++) {
    if (!$countMode && ($nuts[$i] == '1')) {
        // $vars ++;
        $countMode = true;
        continue;
    }
    if ($countMode && ($nuts[$i] == 0)) {
        $tempVars ++;
        continue;
    }

    if ($countMode && ($nuts[$i] == '1')) {
        $vars = $vars + $tempVars;
        if ($tempVars > 0) {
            $vars ++;
        }
        $tempVars = 0;
        $countMode = false;
        if ($nuts[$i+1] == '0') {
            $countMode = true;
        }
    }
}
if ($vars == 0) {
    echo '1';
} else {
    echo $vars;
}

?>


String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".You are given a correct string s.You can perform two different operations on this string:   swap any pair of adjacent characters (for example, "101"  "110");  replace "11" with "1" (for example, "110"  "10"). Let val(s) be such a number that s is its binary representation.Correct string a is less than some other correct string b iff val(a) < val(b).Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all).

The first line contains integer number n (1 ≤ n ≤ 100) — the length of string s. The second line contains the string s consisting of characters "0" and "1". It is guaranteed that the string s is correct.

Print one string — the minimum correct string that you can obtain from the given one.

NoteIn the first example you can obtain the answer by the following sequence of operations: "1001"  "1010"  "1100"  "100".In the second example you can't obtain smaller answer no matter what operations you use.


The last stage of Football World Cup is played using the play-off system.There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids a and b can meet.

The only line contains three integers n, a and b (2 ≤ n ≤ 256, 1 ≤ a, b ≤ n) — the total number of teams, and the ids of the teams that Arkady is interested in.  It is guaranteed that n is such that in each round an even number of team advance, and that a and b are not equal.

In the only line print "Final!" (without quotes), if teams a and b can meet in the Final. Otherwise, print a single integer — the number of the round in which teams a and b can meet. The round are enumerated from 1.

NoteIn the first example teams 1 and 2 meet in the first round.In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round.


Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to n from the left to the right, the desks in a lane are numbered from 1 to m starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).The organizers numbered all the working places from 1 to 2nm. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right.    The picture illustrates the first and the second samples. Santa Clause knows that his place has number k. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!

The only line contains three integers n, m and k (1 ≤ n, m ≤ 10 000, 1 ≤ k ≤ 2nm) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.

Print two integers: the number of lane r, the number of desk d, and a character s, which stands for the side of the desk Santa Claus. The character s should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.

NoteThe first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.


Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. Brainfuck programs use 8 commands: "+", "-", "[", "]", "<", ">", "." and "," (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuck programs using the following algorithm. First, replace each command with a corresponding binary code, using the following conversion table:   ">"  →  1000,  "<"  →  1001,  "+"  →  1010,  "-"  →  1011,  "."  →  1100,  ","  →  1101,  "["  →  1110,  "]"  →  1111. Next, concatenate the resulting binary codes into one binary number in the same order as in the program. Finally, write this number using unary numeral system — this is the Unary program equivalent to the original Brainfuck one.You are given a Brainfuck program. Your task is to calculate the size of the equivalent Unary program, and print it modulo 1000003 (106 + 3).

The input will consist of a single line p which gives a Brainfuck program. String p will contain between 1 and 100 characters, inclusive. Each character of p will be "+", "-", "[", "]", "<", ">", "." or ",".

Output the size of the equivalent Unary program modulo 1000003 (106 + 3).

NoteTo write a number n in unary numeral system, one simply has to write 1 n times. For example, 5 written in unary system will be 11111.In the first example replacing Brainfuck commands with binary code will give us 1101 1100. After we concatenate the codes, we'll get 11011100 in binary system, or 220 in decimal. That's exactly the number of tokens in the equivalent Unary program.

<?php
	function gao($c)
	{
		switch($c)
		{
			case '>':
				return "8";
			case '<':
				return "9";
			case '+':
				return "10";
			case '-':
				return "11";
			case '.':
				return "12";
			case ',':
				return "13";
			case '[':
				return "14";
			case ']':
				return "15";
		}
	}
	$stdin = fopen("php://stdin", "r");
	$str = fgets($stdin);
	$len = strlen($str);
	$num = "0";
	for($i = 0; $i < $len-1; $i++)
	{
		$num = bcmul($num, "16");
		$num = bcadd($num, gao($str[$i]));
	}
	echo (bcmod($num, "1000003"))."\n";
?>


Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.The first player wrote number a, the second player wrote number b. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins?

The single line contains two integers a and b (1 ≤ a, b ≤ 6) — the numbers written on the paper by the first and second player, correspondingly.

Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly.

NoteThe dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.You can assume that number a is closer to number x than number b, if |a - x| < |b - x|.

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

$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

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
error_reporting("off");
//378A: Playing with Dice
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$awins = 0;
$bwins = 0;
$tie = 0;
for ($i = 1; $i <= 6; $i++) {
    if (abs($a - $i) < abs($b - $i)) {
        $awins++;
    } elseif (abs($a - $i) > abs($b - $i)) {
        $bwins++;
    } else {
        $tie++;
    }
}

echo $awins." ".$tie." ".$bwins;
?>

<?php
error_reporting("off");
//378A: Playing with Dice
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$awins = 0;
$bwins = 0;
$tie = 0;
for ($i = 1; $i <= 6; $i++) {
    if (abs($a - $x) < abs($b - $x)) {
        $awins++;
    } elseif (abs($a - $x) > abs($b - $x)) {
        $bwins++;
    } else {
        $tie++;
    }
}

echo $awins." ".$tie." ".$bwins;
?>


Any resemblance to any real championship and sport is accidental.The Berland National team takes part in the local Football championship which now has a group stage. Let's describe the formal rules of the local championship:   the team that kicked most balls in the enemy's goal area wins the game;  the victory gives 3 point to the team, the draw gives 1 point and the defeat gives 0 points;  a group consists of four teams, the teams are ranked by the results of six games: each team plays exactly once with each other team;  the teams that get places 1 and 2 in the group stage results, go to the next stage of the championship. In the group stage the team's place is defined by the total number of scored points: the more points, the higher the place is. If two or more teams have the same number of points, then the following criteria are used (the criteria are listed in the order of falling priority, starting from the most important one):   the difference between the total number of scored goals and the total number of missed goals in the championship: the team with a higher value gets a higher place;  the total number of scored goals in the championship: the team with a higher value gets a higher place;  the lexicographical order of the name of the teams' countries: the country with the lexicographically smaller name gets a higher place. The Berland team plays in the group where the results of 5 out of 6 games are already known. To be exact, there is the last game left. There the Berand national team plays with some other team. The coach asks you to find such score X:Y (where X is the number of goals Berland scored and Y is the number of goals the opponent scored in the game), that fulfills the following conditions:   X > Y, that is, Berland is going to win this game;  after the game Berland gets the 1st or the 2nd place in the group;  if there are multiple variants, you should choose such score X:Y, where value X - Y is minimum;  if it is still impossible to come up with one score, you should choose the score where value Y (the number of goals Berland misses) is minimum.

The input has five lines. Each line describes a game as "team1 team2 goals1:goals2" (without the quotes), what means that team team1 played a game with team team2, besides, team1 scored goals1 goals and team2 scored goals2 goals. The names of teams team1 and team2 are non-empty strings, consisting of uppercase English letters, with length of no more than 20 characters; goals1, goals2 are integers from 0 to 9.  The Berland team is called "BERLAND". It is guaranteed that the Berland team and one more team played exactly 2 games and the the other teams played exactly 3 games.

Print the required score in the last game as X:Y, where X is the number of goals Berland scored and Y is the number of goals the opponent scored. If the Berland team does not get the first or the second place in the group, whatever this game's score is, then print on a single line "IMPOSSIBLE" (without the quotes). Note, that the result score can be very huge, 10:0 for example.

AERLAND DERLAND 2:1
DERLAND CERLAND 0:3
CERLAND AERLAND 0:1
AERLAND BERLAND 2:0
DERLAND BERLAND 4:0

AERLAND DERLAND 2:2
DERLAND CERLAND 2:3
CERLAND AERLAND 1:3
AERLAND BERLAND 2:1
DERLAND BERLAND 4:1

NoteIn the first sample "BERLAND" plays the last game with team "CERLAND". If Berland wins with score 6:0, the results' table looks like that in the end:   AERLAND (points: 9, the difference between scored and missed goals: 4, scored goals: 5)  BERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 6)  DERLAND (points: 3, the difference between scored and missed goals: 0, scored goals: 5)  CERLAND (points: 3, the difference between scored and missed goals: -4, scored goals: 3) In the second sample teams "AERLAND" and "DERLAND" have already won 7 and 4 points, respectively. The Berland team wins only 3 points, which is not enough to advance to the next championship stage.


InputThe input contains a single integer $$$a$$$ ($$$0 \le a \le 63$$$).OutputOutput a single number.ExamplesInput
2
Output
2
Input
5
Output
24
Input
35
Output
50


Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them.A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable professor of all times, a three times Soviet Union Hero, a Noble Prize laureate in student expulsion, venerable Petr Palych.The poor student couldn't answer a single question. Thus, instead of a large spacious office he is going to apply for a job to thorium mines. But wait a minute! Petr Palych decided to give the student the last chance! Yes, that is possible only in dreams. So the professor began: "Once a Venusian girl and a Marsian boy met on the Earth and decided to take a walk holding hands. But the problem is the girl has al fingers on her left hand and ar fingers on the right one. The boy correspondingly has bl and br fingers. They can only feel comfortable when holding hands, when no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. And in addition, no three fingers of the boy should touch each other. Determine if they can hold hands so that the both were comfortable."The boy any the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa.

The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly.

Print YES or NO, that is, the answer to Petr Palych's question.

NoteThe boy and the girl don't really care who goes to the left.

<?php
$handle = fopen ("php://stdin","r");
$lines = array();
$lines[0] = fgets($handle);
$lines[1] = fgets($handle);
fclose($handle);

$v_girl_fingers = explode(" ", $lines[0]);
$m_boy_fingers = explode(" ", $lines[1]);

for( $i = 0; $i < 2; $i++ ) {
	$v_girl_finger = (int)$v_girl_fingers[$i];
	$m_boy_finger = (int)$m_boy_fingers[1-$i];

#	var_dump($v_girl_finger);
#	var_dump($m_boy_finger);
#	var_dump('===================');
	if ( $v_girl_finger >= (ceil($m_boy_finger/2)-1) && $v_girl_finger <= ($m_boy_finger + 1) ) {
		echo "YES";
		exit(0);
	}
}

echo "NO";
exit(0);

<?php
list($al, $ar) = explode(' ',trim(fgets(STDIN)));
list($bl, $br) = explode(' ',trim(fgets(STDIN)));

if((($bl - 2) / $ar <= 2 && $ar - $bl <= 1 ) || (($br - 2) / $al <= 2 && $al - $br <= 1 ))
 print 'YES'; else print 'NO';
?>

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

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

<?php

$lines = explode("\n", $argv[1]);
$v_girl_fingers = explode(" ", $lines[0]);
$m_boy_fingers = explode(" ", $lines[1]);

for( $i = 0; $i < 2; $i++ ) {
	$v_girl_finger = $v_girl_fingers[$i];
	$m_boy_finger = $m_boy_fingers[1-$i];

#	var_dump($v_girl_finger);
#	var_dump($m_boy_finger);
#	var_dump('===================');
	if ( ($v_girl_finger > $m_boy_finger - 2 && $v_girl_finger <= $m_boy_finger + 1)
	  && ($m_boy_finger < $v_girl_finger + 1 && $m_boy_finger >= $v_girl_finger - 1 ) ) {
		echo "YES";
		exit(0);
	}
}

echo "NO";
exit(0);

<?php
 var_dump($argv);
$lines = explode("\n", $argv[1]);
$v_girl_fingers = explode(" ", $lines[0]);
$m_boy_fingers = explode(" ", $lines[1]);

for( $i = 0; $i < 2; $i++ ) {
	$v_girl_finger = $v_girl_fingers[$i];
	$m_boy_finger = $m_boy_fingers[1-$i];

#	var_dump($v_girl_finger);
#	var_dump($m_boy_finger);
#	var_dump('===================');
	if ( ($v_girl_finger > $m_boy_finger - 2 && $v_girl_finger <= $m_boy_finger + 1)
	  && ($m_boy_finger < $v_girl_finger + 1 && $m_boy_finger >= $v_girl_finger - 1 ) ) {
		echo "YES";
		exit(0);
	}
}

echo "NO";
exit(0);

<?php
$handle = fopen ("php://stdin","r");
$lines = array();
$lines[0] = fgets($handle);
$lines[1] = fgets($handle);
fclose($handle);

$v_girl_fingers = explode(" ", $lines[0]);
$m_boy_fingers = explode(" ", $lines[1]);

for( $i = 0; $i < 2; $i++ ) {
	$v_girl_finger = (int)$v_girl_fingers[$i];
	$m_boy_finger = (int)$m_boy_fingers[1-$i];

#	var_dump($v_girl_finger);
#	var_dump($m_boy_finger);
#	var_dump('===================');
	if ( ($v_girl_finger >= $m_boy_finger - 2 && $v_girl_finger <= $m_boy_finger + 1)
	  && ($m_boy_finger <= $v_girl_finger + 1 && $m_boy_finger >= $v_girl_finger - 1 ) ) {
		echo "YES";
		exit(0);
	}
}

echo "NO";
exit(0);

<?php
$handle = fopen ("php://stdin","r");
$lines = array();
$lines[0] = fgets($handle);
$lines[1] = fgets($handle);
fclose($handle);

$v_girl_fingers = explode(" ", $lines[0]);
$m_boy_fingers = explode(" ", $lines[1]);

for( $i = 0; $i < 2; $i++ ) {
	$v_girl_finger = $v_girl_fingers[$i];
	$m_boy_finger = $m_boy_fingers[1-$i];

#	var_dump($v_girl_finger);
#	var_dump($m_boy_finger);
#	var_dump('===================');
	if ( ($v_girl_finger > $m_boy_finger - 2 && $v_girl_finger <= $m_boy_finger + 1)
	  && ($m_boy_finger < $v_girl_finger + 1 && $m_boy_finger >= $v_girl_finger - 1 ) ) {
		echo "YES";
		exit(0);
	}
}

echo "NO";
exit(0);

<?php
$handle = fopen ("php://stdin","r");
$lines = array();
$lines[0] = fgets($handle);
$lines[1] = fgets($handle);
fclose($handle);

$v_girl_fingers = explode(" ", $lines[0]);
$m_boy_fingers = explode(" ", $lines[1]);

for( $i = 0; $i < 2; $i++ ) {
	$v_girl_finger = (int)$v_girl_fingers[$i];
	$m_boy_finger = (int)$m_boy_fingers[1-$i];

#	var_dump($v_girl_finger);
#	var_dump($m_boy_finger);
#	var_dump('===================');
	if ( $v_girl_finger >= (ceil($m_boy_finger/2)-1) && $v_girl_finger <= ($m_boy_finger + 2) ) {
		echo "YES";
		exit(0);
	}
}

echo "NO";
exit(0);

<?php
list($al, $ar) = explode(' ',trim(fgets(STDIN)));
list($bl, $br) = explode(' ',trim(fgets(STDIN)));

if(($bl - $ar <= 3 && $ar - $bl <= 1 ) || ($br - $al <= 3 && $al - $br <= 1 ))
 print 'YES'; else print 'NO';
?>


Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.

The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.

Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.

NoteIn first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.Picture explaning fourth sample:Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
sort($b);
$c = count($b) % 2;
if($c == 0)
{
     $d = array_slice($b, 0, $a / 2);
     $e = array_slice($b, $a / 2);
     $f = array_sum($d);
     $g = array_sum($e);
     $h = abs($f - $g);
     print $h;
}
else
{
     $d = array_slice($b, 0, ceil($a / 2));
     $e = array_slice($b, ceil($a / 2));
     $f = array_sum($d);
     $g = array_sum($e);
     $h = abs($f - $g);
     print $h;
}
?>


Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a1 × b1 rectangle, the paintings have shape of a a2 × b2 and a3 × b3 rectangles.Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?

The first line contains two space-separated numbers a1 and b1 — the sides of the board. Next two lines contain numbers a2, b2, a3 and b3 — the sides of the paintings. All numbers ai, bi in the input are integers and fit into the range from 1 to 1000.

If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes).

NoteThat's how we can place the pictures in the first test:And that's how we can do it in the third one.


The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday.The calendar is so beautiful that she wants to know what is the next year after y when the calendar will be exactly the same. Help Taylor to find that year.Note that leap years has 366 days. The year is leap if it is divisible by 400 or it is divisible by 4, but not by 100 (https://en.wikipedia.org/wiki/Leap_year).

The only line contains integer y (1000 ≤ y < 100'000) — the year of the calendar.

Print the only integer y' — the next year after y when the calendar will be the same. Note that you should find the first year after y with the same calendar.

NoteToday is Monday, the 13th of June, 2016.

<?php
$a = trim(fgets(STDIN));
$b = $a % 4;
if($b == 0)
{
     print $a + 28;
}
elseif($b == 1)
{
     print $a + 6;
}
elseif($b == 2)
{
     print $a + 11;
}
elseif($b == 3)
{
     print $a + 11;
}
?>

<?php
$a = trim(fgets(STDIN));
$b = $a % 4;
print $b . "\n";
if($b == 0)
{
     print $a + 28;
}
elseif($b == 1)
{
     print $a + 6;
}
elseif($b == 2)
{
     print $a + 11;
}
elseif($b == 3)
{
     print $a + 11;
}
?>

<?php
$a = trim(fgets(STDIN));
$b = $a % 4;
if($b == 0)
{
     print $a + 28;
}
else
{
     print $a + 6;
}
?>


There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size b of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins b in the initial bet.

The input consists of a single line containing five integers c1, c2, c3, c4 and c5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0 ≤ c1, c2, c3, c4, c5 ≤ 100).

Print the only line containing a single positive integer b — the number of coins in the initial bet of each player. If there is no such value of b, then print the only value "-1" (quotes for clarity).

NoteIn the first sample the following sequence of operations is possible:  One coin is passed from the fourth player to the second player;  One coin is passed from the fourth player to the fifth player;  One coin is passed from the first player to the third player;  One coin is passed from the fourth player to the second player.

<?php
$a = explode(" ", trim(fgets(STDIN)));
$b = array_sum($a);
$c = $b % 5;
$d = $b / 5;
if($b == 0)
{
    print "-1";
}
elseif($c == 0)
{
    print $d;
}
else
{
    print "-1";
}
?>

<?php
error_reporting(0);
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
// $datatxt = "1000000000 1000000000 1";
$text = explode(" ",$datatxt);
$total= 0;
for($i=0;$i<5;$i++){
$total+=$text[$i];
}
$initial = $total/5;
if (($total%5)==0 && $initial>0){
echo $initial;
}else {
echo "-1";
}
?>

<?php
$input = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($input);
echo (($sum%5!=0 || $sum==0) ? -1 : ($sum/5));
?>

<?php
$player = explode(" ",trim(fgets(STDIN)));
$summ =0;
for ($i=0;$i<count($player);$i++)
{
    $summ+=$player[$i];
}
if ($summ%5==0&&$summ!=0)echo $summ/5;
else echo -1;

<?php
	$input = explode(" ",trim(fgets(STDIN)));
	$sum = array_sum($input);
	if($sum%5==0 && $sum>0){
		echo $sum/5;
	}
	else{
		echo "-1";
	}
?>

<?

$input = trim(fgets(STDIN));

$cs = explode(' ', $input);

$sum = array_sum($cs);

if(($sum/5)==ceil($sum/5)&&$sum!=0){
    echo ($sum/5);
}else{
    echo -1;
}

?>

<?php
// 478A     Начальная ставка
$in = fopen("php://stdin", 'r');

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

$sum = 0;
foreach ($arr as $key => $value) {
    $sum += (int) $value;
}

if ((($sum % 5) !== 0) or ($sum == 0)) {
    echo -1;
} else {
    echo $sum / 5;
}

?>

<?php

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

$a = (int)$raw[0];
$b = (int)$raw[1];
$c = (int)$raw[2];
$d = (int)$raw[3];
$e = (int)$raw[4];

$count = $a + $b + $c + $d + $e;

if ($count % 5 != 0 || $count == 0) {
    echo -1 . PHP_EOL;
} else {
    echo $count / 5 . PHP_EOL;
}

<?php
$a = explode(" ", trim(fgets(STDIN)));
$b = array_sum($a);
$c = $b % 5;
$d = $b / 5;
if($b == 0)
{
    print "0";
}
elseif($c == 0)
{
    print $d;
}
else
{
    print "-1";
}
?>

<?php
$a = explode(" ", trim(fgets(STDIN)));
$b = array_sum($a);
$c = $b % 5;
$d = $b / 5;
if($c == 0)
{
    print $d;
}
else
{
    print "-1";
}
?>

<?php
$input = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($input);
echo (($sum%5 || !sum) ? -1 : ($sum/5));
?>

<?php
    $s = 0;
    for ($i = 1; $i <= 5; $i++)    {
        fscanf(STDIN, "%d\n", $number);
        $s += $number;
    }

    if ($s % 5 == 0)
    {
        fprintf(STDOUT, "%d\n", $s / 5);
    }
    else {
        fprintf(STDOUT, "-1\n");
    }
?>

<?php
$player = explode(" ",trim(fgets(STDIN)));
$summ =0;
for ($i=0;$i<count($player);$i++)
{
    $summ+=$player[$i];
}
if ($summ%5==0)echo $summ/5;
else echo -1;

<?php
	$input = explode(" ",trim(fgets(STDIN)));
	$sum = array_sum($input);
	if($sum%5==0 && $sum>0){
		echo "$sum/5";
	}
	else{
		echo "-1";
	}
?>

<?

$input = trim(fgets(STDIN));

$cs = explode(' ', $input);

$sum = array_sum($cs);

if(($sum/5)==ceil($sum/5)){
    echo ($sum/5);
}else{
    echo -1;
}

?>

<?php
// 478A     Начальная ставка
$in = fopen("php://stdin", 'r');

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

$sum = 0;
foreach ($arr as $key => $value) {
    $sum += (int) $value;
}

if (($sum % 5) == 0) {
    echo $sum / 5;
} else {
    echo -1;
}

?>

<?php

$line = fgets(STDIN);
$ex = explode(" ",$line);

$sum = $ex[0] + $ex[1] + $ex[2] + $ex[3] + $ex[4];
if($sum % 5 == 0){
    echo $sum / 5;
}else{
    echo -1;
}

<?php

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

$a = (int)$raw[0];
$b = (int)$raw[1];
$c = (int)$raw[2];
$d = (int)$raw[3];
$e = (int)$raw[4];

$count = $a + $b + $c + $d + $e;

if ($count % 5 != 0) {
    echo -1 . PHP_EOL;
} else {
    echo $count / 5 . PHP_EOL;
}


Limak is a little polar bear. He has n balls, the i-th ball has size ti.Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy:  No two friends can get balls of the same size.  No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2).Your task is to check whether Limak can choose three balls that satisfy conditions above.

The first line of the input contains one integer n (3 ≤ n ≤ 50) — the number of balls Limak has. The second line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 1000) where ti denotes the size of the i-th ball.

Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes).

NoteIn the first sample, there are 4 balls and Limak is able to choose three of them to satisfy the rules. He must must choose balls with sizes 18, 16 and 17.In the second sample, there is no way to give gifts to three friends without breaking the rules.In the third sample, there is even more than one way to choose balls:  Choose balls with sizes 3, 4 and 5.  Choose balls with sizes 972, 970, 971.

<?php
$n = trim(fgets(STDIN));
$ti = explode(" ", trim(fgets(STDIN)));
sort($ti);
$r = false;
$b = 0;
for ($j = 0; $j < $n - 1; $j++) {
    if ($ti[$j+1] - $ti[$j] == 1) {
        $b++;
    } else if ($ti[$j+1] - $ti[$j] == 0) {
        continue;
    } else {
        $b = 0;
    }
    if ($b == 2) $r = true;
}
if ($r) {
    print "YES";
} else {
    print "NO";
}
?>

<?php
$n = trim(fgets(STDIN));
$ti = explode(" ", trim(fgets(STDIN)));
sort($ti);
$r = false;
$b = 0;
for ($j = 0; $j < $n - 1; $j++) {
    if ($ti[$j+1] - $ti[$j] == 1) {
        $b++;
    } else {
        $b = 0;
    }
    if ($b == 2) $r = true;
}
if ($r) {
    print "YES";
} else {
    print "NO";
}
?>


Misha and Vanya have played several table tennis sets. Each set consists of several serves, each serve is won by one of the players, he receives one point and the loser receives nothing. Once one of the players scores exactly k points, the score is reset and a new set begins.Across all the sets Misha scored a points in total, and Vanya scored b points. Given this information, determine the maximum number of sets they could have played, or that the situation is impossible.Note that the game consisted of several complete sets.

The first line contains three space-separated integers k, a and b (1 ≤ k ≤ 109, 0 ≤ a, b ≤ 109, a + b > 0).

If the situation is impossible, print a single number -1. Otherwise, print the maximum possible number of sets.

NoteNote that the rules of the game in this problem differ from the real table tennis game, for example, the rule of "balance" (the winning player has to be at least two points ahead to win a set) has no power within the present problem.

<?php

error_reporting(0);

while($line = trim(fgets(STDIN))){

$linhas[]=$line;
if($a==1) break;
$a++;
}

$explode = explode(" ",$linhas[0]);

$k=$explode[0];
$a=$explode[1];
$b=$explode[2];

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

$set1 = $max/$k;
$set2 = $min/$k;

$sum = intval($set1)+intval($set2);

$sum+=0;

$resto1=$max%$k;
$resto2=$min%$k;

if($resto1!=0 && $max>=$k) {

	if($min >= $k) {

		echo $sum;
		die();

	}

}

else if(($resto1==0) && ($max>=$k)) {
	echo $sum; die(); }

	// var_dump($resto1==0,$max>=$k);

echo "-1";

?>

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


Arkady and his friends love playing checkers on an $$$n \times n$$$ field. The rows and the columns of the field are enumerated from $$$1$$$ to $$$n$$$.The friends have recently won a championship, so Arkady wants to please them with some candies. Remembering an old parable (but not its moral), Arkady wants to give to his friends one set of candies per each cell of the field: the set of candies for cell $$$(i, j)$$$ will have exactly $$$(i^2 + j^2)$$$ candies of unique type.There are $$$m$$$ friends who deserve the present. How many of these $$$n \times n$$$ sets of candies can be split equally into $$$m$$$ parts without cutting a candy into pieces? Note that each set has to be split independently since the types of candies in different sets are different.

The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^9$$$, $$$1 \le m \le 1000$$$) — the size of the field and the number of parts to split the sets into.

Print a single integer — the number of sets that can be split equally.

NoteIn the first example, only the set for cell $$$(3, 3)$$$ can be split equally ($$$3^2 + 3^2 = 18$$$, which is divisible by $$$m=3$$$).In the second example, the sets for the following cells can be divided equally:   $$$(1, 2)$$$ and $$$(2, 1)$$$, since $$$1^2 + 2^2 = 5$$$, which is divisible by $$$5$$$;  $$$(1, 3)$$$ and $$$(3, 1)$$$;  $$$(2, 4)$$$ and $$$(4, 2)$$$;  $$$(2, 6)$$$ and $$$(6, 2)$$$;  $$$(3, 4)$$$ and $$$(4, 3)$$$;  $$$(3, 6)$$$ and $$$(6, 3)$$$;  $$$(5, 5)$$$. In the third example, sets in all cells can be divided equally, since $$$m = 1$$$.

<?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 readArrayOfFloat($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (float)$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;}
/*****************************************/

$ir = new InputReader();

/* TASK */

list($n, $m) = $ir->readArrayOfInt(2);
$fullTimes = intval($n/$m);
$mod = $n%$m;

$a = array_fill(1,$m, []);

for ($i=1; $i<=$m; $i++) {
	for ($j=$i; $j<=$m; $j++) {
		$a[$i][$j] = ( $i*$i + $j*$j )%$m;
		$a[$j][$i] = $a[$i][$j];
	}
}

$fullCnt = 0;
for ($i=1; $i<=$m; $i++) {
	for ($j=1; $j<=$m; $j++) {
		if ($a[$i][$j] == 0) {
			$fullCnt++;
		}
	}
}

$halfCnt = 0;
for ($i=1; $i<=$m; $i++) {
	for ($j=1; $j<=$mod; $j++) {
		if ($a[$i][$j] == 0) {
			$halfCnt++;
		}
	}
}

$quarterCnt = 0;
for ($i=1; $i<=$mod; $i++) {
	for ($j=1; $j<=$mod; $j++) {
		if ($a[$i][$j] == 0) {
			$quarterCnt++;
		}
	}
}

$totalCnt = bcadd(bcadd(bcmul($fullCnt, bcmul($fullTimes,$fullTimes)), bcmul(bcmul(2,$halfCnt),$fullTimes)), $quarterCnt);

echo $totalCnt;


So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in the figure (all blocks are square and are numbered from bottom to top, blocks in the same row are numbered from left to right). Let us describe the hopscotch with numbers that denote the number of squares in the row, staring from the lowest one: 1-1-2-1-2-1-2-(1-2)..., where then the period is repeated (1-2).  The coordinate system is defined as shown in the figure. Side of all the squares are equal and have length a.Maria is a very smart and clever girl, and she is concerned with quite serious issues: if she throws a stone into a point with coordinates (x, y), then will she hit some square? If the answer is positive, you are also required to determine the number of the square.It is believed that the stone has fallen into the square if it is located strictly inside it. In other words a stone that has fallen on the square border is not considered a to hit a square.

The only input line contains three integers: a, x, y, where a (1 ≤ a ≤ 100) is the side of the square, x and y ( - 106 ≤ x ≤ 106, 0 ≤ y ≤ 106) are coordinates of the stone.

Print the number of the square, inside which the stone fell. If the stone is on a border of some stone or outside the court, print "-1" without the quotes.


The Smart Beaver from ABBYY decided to have a day off. But doing nothing the whole day turned out to be too boring, and he decided to play a game with pebbles. Initially, the Beaver has n pebbles. He arranges them in a equal rows, each row has b pebbles (a > 1). Note that the Beaver must use all the pebbles he has, i. e. n = a·b.   10 pebbles are arranged in two rows, each row has 5 pebbles  Once the Smart Beaver has arranged the pebbles, he takes back any of the resulting rows (that is, b pebbles) and discards all other pebbles. Then he arranges all his pebbles again (possibly choosing other values of a and b) and takes back one row, and so on. The game continues until at some point the Beaver ends up with exactly one pebble. The game process can be represented as a finite sequence of integers c1, ..., ck, where:   c1 = n  ci + 1 is the number of pebbles that the Beaver ends up with after the i-th move, that is, the number of pebbles in a row after some arrangement of ci pebbles (1 ≤ i < k). Note that ci > ci + 1.  ck = 1 The result of the game is the sum of numbers ci. You are given n. Find the maximum possible result of the game.

The single line of the input contains a single integer n — the initial number of pebbles the Smart Beaver has. The input limitations for getting 30 points are:    2 ≤ n ≤ 50  The input limitations for getting 100 points are:    2 ≤ n ≤ 109

Print a single number — the maximum possible result of the game.

NoteConsider the first example (c1 = 10). The possible options for the game development are:  Arrange the pebbles in 10 rows, one pebble per row. Then c2 = 1, and the game ends after the first move with the result of 11.  Arrange the pebbles in 5 rows, two pebbles per row. Then c2 = 2, and the game continues. During the second move we have two pebbles which can be arranged in a unique way (remember that you are not allowed to put all the pebbles in the same row!) — 2 rows, one pebble per row. c3 = 1, and the game ends with the result of 13.  Finally, arrange the pebbles in two rows, five pebbles per row. The same logic leads us to c2 = 5, c3 = 1, and the game ends with the result of 16 — the maximum possible result.

<?
    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());}
    /***************************************************************/

    $n = read_str();

    function find_max($n)
    {
        $max = $n/2;
        $a=1;
        do
        {
            $a++;
            $b = $n/$a;
            if(is_int($b)) break;
        } while ($a<$max);
        if($a>$max) return 1;
        else return max($a,$b);
    }

    function calc($n)
    {
        $count = $n;
        do
        {
            $n = find_max($n);
            $count += $n;
        } while($n != 1);

        return $count;
    }

    echo calc($n);
?>

<?
    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());}
    /***************************************************************/

    $n = read_str();

/**
 * Checks if $num is a Prime Number
 * @param int $num
 * @return boolean
 */
function isPrime($num) {
    //1 is not prime. See: http://en.wikipedia.org/wiki/Prime_number#Primality_of_one
    if($num == 1)
        return false;

    //2 is prime (the only even number that is prime)
    if($num == 2)
        return true;

  /**
     * if the number is divisible by two, then it's not prime and it's no longer
     * needed to check other even numbers
     */
    if($num % 2 == 0) {
        return false;
    }

    /**
     * Checks the odd numbers. If any of them is a factor, then it returns false.
     * The sqrt can be an aproximation, hence just for the sake of
     * security, one rounds it to the next highest integer value.
     */
    for($i = 3; $i <= ceil(sqrt($num)); $i = $i + 2) {
        if($num % $i == 0)
            return false;
    }

    return true;
}

    function find_max($n)
    {
        if(isPrime($n)) return 1;
        $max = $n/2;
        $a=1;
        do
        {
            $a++;
            $b = $n/$a;

            if(is_int($b)) break;
        } while ($a<$max);
        if($a>$max) return 1;
        else return max($a,$b);
    }

    function calc($n)
    {
        $count = $n;
        do
        {
            $n = find_max($n);

            $count += $n;
        } while($n != 1);

        return $count;
    }

    echo calc($n);
?>


There are $$$n$$$ students in a school class, the rating of the $$$i$$$-th student on Codehorses is $$$a_i$$$. You have to form a team consisting of $$$k$$$ students ($$$1 \le k \le n$$$) such that the ratings of all team members are distinct.If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $$$k$$$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 100$$$) — the number of students and the size of the team you have to form. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the rating of $$$i$$$-th student.

If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $$$1$$$ to $$$n$$$.

NoteAll possible answers for the first example:   {1 2 5}  {2 3 5}  {2 4 5} Note that the order does not matter.

<?php
fscanf(STDIN,"%d %d",$arrSize,$k);
$arr=explode(' ',trim(fgets(STDIN)));
$trgtArr[0]=$arr[0];
$l=1;
$m=1;
$key[0]=1;
for ($i=1; $i <$arrSize ; $i++)
{
	$count=0;
     for ($j=0; $j <count($trgtArr); $j++)
     {
     	if($trgtArr[$j]!=$arr[$i])
     	{
     		$count++;
     		if($count==count($trgtArr))
     		{
     			$trgtArr[$l++]=$arr[$i];
     			$key[$m++]=$i+1;
     		}
     	}
     }
}
if(count($key)>=$k)
  {
	echo "YES\n";
	for ($i=0; $i <count($key) ; $i++)
	 {
		if($i==$k-1)
		{
			echo "$key[$i]";
			break;
		}
		else
			echo "$key[$i] ";
	}
  }
	else
		echo "NO\n";

<?php
$debug=0;
$b=readline ("n k:");
$a=readline ("ratings:");
$arr1=explode(" ",$b);
$a=explode(" ",$a);
$n=($arr1[0]);
$k=($arr1[1]);
($debug) ? print ($n . "\r\n"): "";
($debug) ? print ($k . "\r\n"): "";
($debug) ? print_r ($a): "" ;
$uniq=array_unique($a);
$out=[];

if (count($uniq)>=$k):
        foreach ($uniq as $value) {
                for ($i=0;$i<=$k+1;$i++){
                        if ($a[$i] == $value):
                        $out[]=$i+1;
                        $i=0;
                        break;
                        endif;
                }
        }

        print ("YES\r\n");
        print (implode(" ",$out));
else:
        print("NO");
endif;

<?php
$debug=0;
$b=readline ("n k:");
$a=readline ("ratings:");
$arr1=explode(" ",$b);
$a=explode(" ",$a);
$n=($arr1[0]);
$k=($arr1[1]);
($debug) ? print ($n . "\r\n"): "";
($debug) ? print ($k . "\r\n"): "";
($debug) ? print_r ($a): "" ;
$uniq=array_unique($a);
$out=[];

if (count($uniq)>=$k):
        foreach ($uniq as $value) {
                for ($i=0;$i<=$k;$i++){
                        if ($a[$i] == $value):
                        $out[]=$i;
                        break;
                        endif;
                }
        }

        print ("YES\r\n");
        print (implode(" ",$out));
else:
        print("NO");
endif;

<?php
$debug=0;
$b=readline ("n k:");
$a=readline ("ratings:");
$arr1=explode(" ",$b);
$a=explode(" ",$a);
$n=($arr1[0]);
$k=($arr1[1]);
($debug) ? print ($n . "\r\n"): "";
($debug) ? print ($k . "\r\n"): "";
($debug) ? print_r ($a): "" ;
$uniq=array_unique($a);
$out=[];

if (count($uniq)>=$k):
        foreach ($uniq as $value) {
                for ($i=0;$i<=$k+1;$i++){
                        if ($a[$i] == $value):
                        $out[]=$i+1;
                        break;
                        endif;
                }
        }

        print ("YES\r\n");
        print (implode(" ",$out));
else:
        print("NO");
endif;

<?php
$debug=0;
$b=readline ("n k:");
$a=readline ("ratings:");
$arr1=explode(" ",$b);
$a=explode(" ",$a);
$n=($arr1[0]);
$k=($arr1[1]);
($debug) ? print ($n . "\r\n"): "";
($debug) ? print ($k . "\r\n"): "";
($debug) ? print_r ($a): "" ;
$uniq=array_unique($a);
$out=[];

if (count($uniq)>=$k):
        foreach ($uniq as $value) {
                for ($i=0;$i<=$k;$i++){
                        if ($a[$i] == $value):
                        $out[]=$i+1;
                        break;
                        endif;
                }
        }

        print ("YES\r\n");
        print (implode(" ",$out));
else:
        print("NO");
endif;

<?php
fscanf(STDIN,"%d %d",$arrSize,$k);
$arr=explode(' ',trim(fgets(STDIN)));
$trgtArr[0]=$arr[0];
$l=1;
$m=1;
$key[0]=1;
for ($i=1; $i <$arrSize ; $i++)
{
	$count=0;
     for ($j=0; $j <count($trgtArr); $j++)
     {
     	if($trgtArr[$j]!=$arr[$i])
     	{
     		$count++;
     		if($count==count($trgtArr))
     		{
     			$trgtArr[$l++]=$arr[$i];
     			$key[$m++]=$i+1;
     		}
     	}
     }
}
if(count($key)==$k)
  {
	echo "YES\n";
	for ($i=0; $i <count($key) ; $i++)
	 {
		if($i==$k-1)
			echo "$key[$i]";
		else
			echo "$key[$i] ";
	}
  }
	else
		echo "NO\n";


Dawid has four bags of candies. The $$$i$$$-th of them contains $$$a_i$$$ candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?Note, that you can't keep bags for yourself or throw them away, each bag should be given to one of the friends.

The only line contains four integers $$$a_1$$$, $$$a_2$$$, $$$a_3$$$ and $$$a_4$$$ ($$$1 \leq a_i \leq 100$$$) — the numbers of candies in each bag.

Output YES if it's possible to give the bags to Dawid's friends so that both friends receive the same amount of candies, or NO otherwise. Each character can be printed in any case (either uppercase or lowercase).

NoteIn the first sample test, Dawid can give the first and the third bag to the first friend, and the second and the fourth bag to the second friend. This way, each friend will receive $$$12$$$ candies.In the second sample test, it's impossible to distribute the bags.

<?php
$__fp = fopen('php://stdin', 'r');
$a = array_map('intval', explode(' ', fgets($__fp)));
sort($a);
if ($a[0] + $a[3] == $a[1] + $a[2]) {
    echo 'YES' . PHP_EOL;
} else {
    echo 'NO' . PHP_EOL;
}

<?php
$line=explode(" ",trim(fgets(STDIN)));
$first=$line[0]+$line[1];
$second=$line[2]+$line[3];
$third=$line[1]+$line[2];
$fourth=$line[0]+$line[3];
$fifth=$line[0]+$line[2];
$sixth=$line[1]+$line[3];
if($first==$second||$third==$fourth||$fifth==$sixth)
	echo "YES";
else
	echo "NO";


Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off.Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b1, b2, ..., bm (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button bi is actually bi, not i.Please, help Mashmokh, print these indices.

The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b1, b2, ..., bm (1 ≤ bi ≤ n). It is guaranteed that all lights will be turned off after pushing all buttons.

Output n space-separated integers where the i-th number is index of the button that turns the i-th light off.

NoteIn the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off.

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

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

list($n,$m) = explode(' ', trim(fgets(MY_STDIN)));
$a = explode(' ', trim(fgets(MY_STDIN)));
$aa = array_fill(1, $n, 0);
foreach ($a as $k) {
    for ($i = $k; $i <= $n; $i++) {
        if ($aa[$i] == 0) {
            $aa[$i] = $k;
        }
    }
}
echo join(' ', $aa);

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

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

$line = trim(fgets($fileIN));
$line = explode(" ", $line);

$a = array();

for ($i = 0; $i <= $n; ++$i) {
    $a[$i] = 0;
}

for ($i = 0; $i < $k; ++$i) {
    for ($j = $line[$i]; $j <= $n; ++$j) {
        if ($a[$j] == 0) {
            $a[$j] = $line[$i];
        }
    }
}

for ($i = 1; $i <= $n; ++$i) {
    fprintf($fileOUT, $a[$i] . " ");
}

fclose($fileIN);
fclose($fileOUT);
?>

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

list($n,$m) = explode(' ', trim(fgets(MY_STDIN)));
$a = explode(' ', trim(fgets(MY_STDIN)));
var_dump($a);
$aa = array_fill(1, $n, 0);
foreach ($a as $k) {
    for ($i = $k; $i <= $n; $i++) {
        if ($aa[$i] == 0) {
            $aa[$i] = $k;
        }
    }
}
echo join(' ', $aa);

<?PHP
$fileIN = fopen("in.txt", "r");
$fileOUT = fopen("out.txt", "w");

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

$line = trim(fgets($fileIN));
$line = explode(" ", $line);

$a = array();

for ($i = 0; $i <= $n; ++$i) {
    $a[$i] = 0;
}

for ($i = 0; $i < $k; ++$i) {
    for ($j = $line[$i]; $j <= $n; ++$j) {
        if ($a[$j] == 0) {
            $a[$j] = $line[$i];
        }
    }
}

for ($i = 1; $i <= $n; ++$i) {
    fprintf($fileOUT, $a[$i] . " ");
}

fclose($fileIN);
fclose($fileOUT);
?>


Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium. The scales is in equilibrium if the total sum of weights on the left pan is equal to the total sum of weights on the right pan.

The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially on the left pan of the scale. All weights that are recorded in the sequence after the delimiter are initially on the right pan of the scale.  The second line contains a non-empty sequence containing uppercase English letters. Each letter indicates a weight which is not used yet.  It is guaranteed that all the English letters in the input data are different. It is guaranteed that the input does not contain any extra characters.

If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input. If there are multiple answers, print any of them.

<?php
$in=fgets(STDIN);
$in2=fgets(STDIN);
$in2=trim($in2);

$strArr=explode("|", $in);
$str1=trim($strArr[0]);
$str2=trim($strArr[1]);
$len1=strlen($str1);
$len2=strlen($str2);

$del=abs($len1-$len2);
$lend=strlen($in2);

if($lend<$del) {echo "Impossible";
exit();
}

if($del%2!=$lend%2) echo "Impossible";
else{
	while(strlen($in2)!=0){
		$len1=strlen($str1);
		$len2=strlen($str2);
		if($len1<$len2){
			$str1=$str1.$in2[0];
			$in2=substr($in2, 1);
		}else if($len1>$len2){
			$str2=$str2.$in2[0];
			$in2=substr($in2, 1);
		}else{
			$str1=$str1.$in2[0];
			$str2=$str2.$in2[1];
			$in2=substr($in2, 2);
		}

	}
	echo $str1."|".$str2;
}

?>


You have a positive integer m and a non-negative integer s. Your task is to find the smallest and the largest of the numbers that have length m and sum of digits s. The required numbers should be non-negative integers written in the decimal base without leading zeroes.

The single line of the input contains a pair of integers m, s (1 ≤ m ≤ 100, 0 ≤ s ≤ 900) — the length and the sum of the digits of the required numbers.

In the output print the pair of the required non-negative integer numbers — first the minimum possible number, then — the maximum possible number. If no numbers satisfying conditions required exist, print the pair of numbers "-1 -1" (without the quotes).

<?php
$input2=trim(fgets(STDIN));
settype($input2,'string');
$input=explode(' ',$input2);
$num=$input[0];
$jame=$input[1];
$v=str_repeat('0',$num-1);
$min='1'.$v;
$mino=str_split($min);
if( $jame == 0 and $num!=1){
      echo "-1 -1";
      exit;
}
if($num * 9 < $jame ){
echo "-1 -1";
exit;
}
$max=str_repeat('9',$num);
$q=$num-1;
$a=$jame-1;
$maxo=str_split($max);
while ($a>=9) {
      $mino[$q]+=9;
      $a-=9;
      $q--;
}
$mino[$q]+=$a;
$x=join('',$mino);
echo $x;
echo "\n";
$s=$jame;
$q2=$num-1;
$i=0;
$maxo=str_split(str_repeat('0',$num));
while ($s >=9 and $i <$num) {
      $maxo[$i]+=9;
      $s-=9;
      $i++;
}
if($s !=0){
      @$maxo[$i]+=$s;
}
$y=join('',$maxo);
echo $y;

<?php
$num=trim(fgets(STDIN));
settype($num,'string');
$jame=trim(fgets(STDIN));
settype($jame,'string');
$v=str_repeat('0',$num-1);
$min='1'.$v;
$mino=str_split($min);
if($num * 9 < $jame){
echo "-1 -1";
exit;
}
$max=str_repeat('9',$num);
$q=$num-1;
$a=$jame-1;
$maxo=str_split($max);
while ($a>=9) {
      $mino[$q]+=9;
      $a-=9;
      $q--;
}
$mino[$q]+=$a;
$x=join('',$mino);
echo $x;
echo "\n";
$s=$jame;
$q2=$num-1;
$i=0;
$maxo=str_split(str_repeat('0',$num));
while ($s >=9 and $i <$num) {
      $maxo[$i]+=9;
      $s-=9;
      $i++;
}
if($s !=0){
      @$maxo[$i]+=$s;
}
$y=join('',$maxo);
echo $y;

<?php
$num=trim(fgets(STDIN));
settype($num,'string');
$jame=trim(fgets(STDIN));
settype($jame,'string');
$v=str_repeat('0',$num-1);
$min='1'.$v;
$mino=str_split($min);

$max=str_repeat('9',$num);
$q=$num-1;
$a=$jame-1;
$maxo=str_split($max);
while ($a>=9) {
      $mino[$q]+=9;
      $a-=9;
      $q--;
}
$mino[$q]+=$a;
echo join('',$mino);
echo "\n";
$s=$jame;
$q2=$num-1;
$i=0;
$maxo=str_split(str_repeat('0',$num));
while ($s >=9 and $i <$num) {
      $maxo[$i]=9;
      $s-=9;
      $i++;
}
@$maxo[$i]+=$s;
echo join('',$maxo);

<?php
$input2=trim(fgets(STDIN));
settype($input2,'string');
$input=explode(' ',$input2);
$num=$input[0];
$jame=$input[1];
$v=str_repeat('0',$num-1);
$min='1'.$v;
$mino=str_split($min);
if($num * 9 < $jame  or $jame == 0){
echo "-1 -1";
exit;
}
$max=str_repeat('9',$num);
$q=$num-1;
$a=$jame-1;
$maxo=str_split($max);
while ($a>=9) {
      $mino[$q]+=9;
      $a-=9;
      $q--;
}
$mino[$q]+=$a;
$x=join('',$mino);
echo $x;
echo "\n";
$s=$jame;
$q2=$num-1;
$i=0;
$maxo=str_split(str_repeat('0',$num));
while ($s >=9 and $i <$num) {
      $maxo[$i]+=9;
      $s-=9;
      $i++;
}
if($s !=0){
      @$maxo[$i]+=$s;
}
$y=join('',$maxo);
echo $y;


Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.One day in 230 AD Shapur was trying to find out if any one can possibly do calculations faster than him. As a result he made a very great contest and asked every one to come and take part.In his contest he gave the contestants many different pairs of numbers. Each number is made from digits 0 or 1. The contestants should write a new number corresponding to the given pair of numbers. The rule is simple: The i-th digit of the answer is 1 if and only if the i-th digit of the two given numbers differ. In the other case the i-th digit of the answer is 0.Shapur made many numbers and first tried his own speed. He saw that he can perform these operations on numbers of length ∞ (length of a number is number of digits in it) in a glance! He always gives correct answers so he expects the contestants to give correct answers, too. He is a good fellow so he won't give anyone very big numbers and he always gives one person numbers of same length.Now you are going to take part in Shapur's contest. See if you are faster and more accurate.

There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100.

Write one line — the corresponding answer. Do not omit the leading 0s.

<?php
    $fp = fopen('php://stdin', 'r');
    $a = rtrim(fgets($fp));
    $b = rtrim(fgets($fp));
    $c = '';

    $len = strlen($a);
    for($i = 0; $i < $len; $i++)
        $c .= (int)($a[$i] xor $b[$i]);
    echo $c;
?>

<?php

if (getenv('APPLICATION_ENV') == 'development') {
    $inputStream = STDIN;
    $outputStream = STDOUT;
} else {
    $inputStream = STDIN;
    $outputStream = STDOUT;
}

$input = trim(fgets($inputStream));
$input2 = trim(fgets($inputStream));

$out = '';

for ($i = 0; $i < strlen($input); $i++) {
    $out .= $input{$i} != $input2{$i} ? '1' : '0';
}

fwrite($outputStream, $out);

if (getenv('APPLICATION_ENV') == 'development') {
    fclose($inputStream);
    fclose($outputStream);
}

<?php
    fscanf(STDIN, "%s", $a);
    fscanf(STDIN, "%s", $b);

    for ($i = 0; $i < strlen($a); $i++){
        if ($a[$i]  == $b[$i]){
            echo 0;
        }
        else {
            echo 1;
        }
    }

<?php
    fscanf(STDIN, "%s", $a);
    fscanf(STDIN, "%s", $b);
    $arr = array();
        for ($i = 0; $i < strlen($a); $i++){
            if ($a[$i]  == $b[$i]){
                $arr[$i] = 0;
            }
            else $arr[$i] = 1;
            echo $arr[$i];
        }

<?php
function input()
{
    while (($line = trim(fgets(STDIN))) != PHP_EOL) {
        yield $line;
    }
}

$COUNT = 0;
$xy = array();
foreach (input() as $line) {
    $q = $line;

    array_push($xy, array_map('intval',str_split($q)));

    if (++$COUNT > 1) {
        break;
    }
}

for($i = 0; $i<count($xy[0]); ++$i) {
    echo $xy[0][$i] ^ $xy[1][$i];
}

<?php
function input()
{
    while (($line = trim(fgets(STDIN))) != PHP_EOL) {
        yield $line;
    }
}

$COUNT = 0;
$xy = array();
foreach (input() as $line) {
    $q = $line;

    // array_push($xy, array_map('intval',str_split($q)));
    array_push($xy, $q);

    if (++$COUNT > 1) {
        break;
    }
}

for($i = 0; $i<strlen($xy[0]); ++$i) {
    echo intval($xy[0][$i])^intval($xy[1][$i]);
}

<?php
function input()
{
    while (($line = trim(fgets(STDIN))) != PHP_EOL) {
        yield $line;
    }
}

$COUNT = 0;
$xy = array();
foreach (input() as $line) {
    $q = $line;

    // array_push($xy, array_map('intval',str_split($q)));
    array_push($xy, $q);

    if (++$COUNT > 1) {
        break;
    }
}

for($i = 0; $i<strlen($xy[0]); ++$i) {
   if ($xy[0][$i] != $xy[1][$i])
        echo 1;
    else {
        echo 0;
    }
}

<?php
function input()
{
    while (($line = trim(fgets(STDIN))) != PHP_EOL) {
        yield $line;
    }
}

$COUNT = 0;
$xy = array();
foreach (input() as $line) {
    if ($COUNT == 0) {
        $r1 = $line;
        ++$COUNT;
        continue;
    }
    // $q = $line;

    // array_push($xy, array_map('intval',str_split($q)));
    // array_push($xy, $q);
    for ($i = 0; $i < strlen($r1); ++$i) {
        if ($r1[$i] != $line[$i]) {
            echo 1;
        } else {
            echo 0;
        }
    }

    if (++$COUNT > 1) {
        break;
    }
}

<?php
/*
 * A. Быстрый математик
 */

$s1 = trim(fgets(STDIN));
$s2 = trim(fgets(STDIN));
$output = array();

for( $i=0; $i<strlen($s1); $i++ ){
    if( $s1[$i] != $s2[$i] ){
        $output[] = 1;
    }else{
        $output[] = 0;
    }
}
echo implode('',$output);

<?php
$fl=STDIN;//fopen("input.txt","r");
$a=trim(fgets($fl));
$b=trim(fgets($fl));
for($i=0;$i<strlen($a);++$i)
    printf("%d",((int)($a[$i])^(int)($b[$i])));
printf("\n");
?>

<?php
$a=trim(fgets(STDIN));
$b=trim(fgets(STDIN));
for($i=0;$i<strlen($a);++$i)
    printf("%d",((int)($a[$i])^(int)($b[$i])));
printf("\n");
?>

<?php
$line1 = trim(fgets(STDIN));
$line2 = trim(fgets(STDIN));
$length = strlen($line1);
for ($i=0;$i<$length;$i++)
{
    if ($line1[$i]==$line2[$i])echo 0;
    else echo 1;
}

<?php
$input=str_split(trim(fgets(STDIN)));
$input2=str_split(trim(fgets(STDIN)));
$a=null;
for ($i=0;$i<count($input);$i++) {
      if($input[$i] == $input2[$i]){
        $a.='0';
      }else{
            $a.='1';
      }
}
echo $a;

<?php
fscanf(STDIN,"%s",$str1);
fscanf(STDIN,"%s",$str2);
$str3="";
for($i=0;$i<strlen($str1);$i++)
{

		if($str1[$i]==$str2[$i])
		{
			$str3.=0;

		}

		else	$str3.=1;

	}
echo $str3;

<?php
$one=readline();
$two=readline();
//$one = '1010100';
$one = str_split($one);
//$two = '0100101';
$two = str_split($two);
$i = 0;
$summa = array();
foreach ($one as $v) {
    if ($v==$two[$i]){
        array_push($summa, "0");
        $i++;
    } else {
        array_push($summa, "1");
        $i++;
    }
}
echo implode($summa);

<?php
    define('DEBUG', 0);

    if(DEBUG) $GLOBALS['file'] = fopen('input.txt', 'r');
    function debug($var){echo '<pre>';print_r($var);echo '</pre>';}
    function read_line()
    {
        if(DEBUG) { $file = $GLOBALS['file'];$line = trim(fgets($file));}
        else $line = trim(fgets(STDIN));
        return $line;
    }
    function get_array($line){return explode(' ', $line);}
    function read_array(){return get_array(read_line());}
    //echo "$s\n";
    /*****************************************************************/

    $line1 = read_line();
    $line2 = read_line();
    $len = strlen($line1);

    for ($i=0; $i<$len; $i++)
    {
        $char1 = $line1[$i];
        $char2 = $line2[$i];

        if($char1 == $char2) echo '0';
        else echo '1';
    }
?>

<?php
$a = str_split(trim(fgets(STDIN)));
$b = str_split(trim(fgets(STDIN)));
$ans = "";
for($i=0;$i<count($a);$i++){
    if ($a[$i] != $b[$i])
        $ans .= "1";
    else
        $ans .= "0";
}
echo $ans;
?>

<?php
$str1 = trim(fgets(STDIN));
$str2 = trim(fgets(STDIN));

for ($i = 0; $i < strlen($str1); $i++)
    echo $str1[$i] === $str2[$i] ? "0" : "1";
?>

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

$first_line = explode("\n",$input)[0];
$second_line = explode("\n",$input)[1];

$given_str = "";

//Loop Throw Them.
for($i = 0;$i < strlen($first_line) - 1;$i++) {

   if($first_line[$i] != $second_line[$i]) {

        $given_str .= "1";

   }else {

        $given_str .= "0";

   }

}

echo $given_str;

<?php
// 61A  Быстрый математик
$in = fopen("php://stdin", 'r');

$str1 = fgets($in);
$str2 = fgets($in);
//list($n, $t) = preg_split('/ /', $input_line, -1, PREG_SPLIT_NO_EMPTY);
$len = strlen($str1) - 2;

$out = '';

for ($i=0; $i < $len ; $i++) {
    if ($str1[$i] === $str2[$i]) {
        $out .= '0';
    } else {
        $out .= '1';
    }
}

echo $out;

?>

<?php
$aNums = explode("\n", stream_get_contents(fopen("php://stdin", 'r')));
for($i = 0; $i < strlen($aNums[0])-1; $i++){
if($aNums[0][$i] == $aNums[1][$i]) $aNums[2] .= 0; else $aNums[2] .= 1;
}
echo $aNums[2];
?>

<?php

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

for($i=0;$i<strlen($a);$i++) print ($a[$i]==$b[$i]?'0':'1');
?>

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

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

$first=trim($lines[0]);
$second=trim($lines[1]);
for ($i=0; $i<strlen($first); $i++)
    echo ($first{$i}!=$second{$i})?'1':'0';

?>

<?php
error_reporting("off");
//61A: Ultra-Fast Mathematician
$one = str_split(trim(fgets(STDIN))); //$one = str_split("000");
$two = str_split(trim(fgets(STDIN))); //$two = str_split("111");
$length = count($one);
$result = "";
for ($i = 0; $i < $length; $i++) {
    if ($one[$i] !== $two[$i]) {
        $result .="1";
    } else {
        $result .="0";
    }
}
echo $result;
?>

<?php
function input()
{
    while (($line = trim(fgets(STDIN))) != PHP_EOL) {
        yield $line;
    }
}

$COUNT = 0;
$xy = array();
foreach (input() as $line) {
    $q = $line;

    // array_push($xy, array_map('intval',str_split($q)));
    array_push($xy, $q);

    if (++$COUNT > 1) {
        break;
    }
}

for($i = 0; $i<strlen($xy[0]); ++$i) {
    echo $xy[0][$i] ^ $xy[1][$i];
}

<?php

$a=trim(fgets(STDIN));
$b=trim(fgets(STDIN));
for($i=0;$i<strlen($a);++$i)
    printf("%d",$a[$i]^$b[$i]);
printf("\n");


Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.

The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20).

If it's impossible to find the representation of n as a product of k numbers, print -1. Otherwise, print k integers in any order. Their product must be equal to n. If there are multiple answers, print any of them.


Flatland is inhabited by pixels of three colors: red, green and blue. We know that if two pixels of different colors meet in a violent fight, only one of them survives the fight (that is, the total number of pixels decreases by one). Besides, if pixels of colors x and y (x ≠ y) meet in a violent fight, then the pixel that survives the fight immediately changes its color to z (z ≠ x; z ≠ y). Pixels of the same color are friends, so they don't fight.The King of Flatland knows that his land will be peaceful and prosperous when the pixels are of the same color. For each of the three colors you know the number of pixels of this color that inhabit Flatland. Help the king and determine whether fights can bring peace and prosperity to the country and if it is possible, find the minimum number of fights needed to make the land peaceful and prosperous.

The first line contains three space-separated integers a, b and c (0 ≤ a, b, c ≤ 231; a + b + c > 0) — the number of red, green and blue pixels, correspondingly.

Print a single number — the minimum number of pixel fights before the country becomes peaceful and prosperous. If making the country peaceful and prosperous is impossible, print -1.

NoteIn the first test sample the country needs only one fight to achieve peace and prosperity. Besides, it can be any fight whatsoever. For example, let's assume that the green and the blue pixels fight, then the surviving pixel will be red. As a result, after the fight there are two red pixels. There won't be other pixels.In the second sample the following sequence of fights is possible: red and blue, green and red, red and blue. As a result, after all fights there is one green pixel left.


You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction  whose denominator is no more than n. Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value  is as minimal as possible.If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator.

A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 105).

Print the required fraction in the format "a/b" (without quotes).


In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 × 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone — neither any other statues, nor Anna, nor Maria.Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is — to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared.At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner.Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error.

You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one — for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S". It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S".

If Maria wins, print string "WIN". If the statues win, print string "LOSE".

<?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
$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
$board = array();
function calc()
{
    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)
{
    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
$board = array();
function calc()
{
    for ($i = 0; $i < 8; $i++)
    {
        $board[$i];
    }
    if (dfs(7, 0, 0)) echo "WIN\n";
    else echo "LOSE\n";
}

function dfs($y, $x, $turn)
{
    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
$area = array();
for( $i=0; $i<8; $i++) {
    $area[$i] = trim(fgets(STDIN));
}

$x = 0;
$y = 7;
$i = 0;
while(1) {
    if( is_free_point(($x+1),($y-1),$area) &&
        !is_danger_point(($x+1),($y-1),$area) ) {
        set_round($x,$y,$x+1,$y-1,$area);
        $x++;$y--;
    }
    else if( is_free_point(($x+1),($y),$area) &&
        !is_danger_point(($x+1),($y),$area) ) {
        set_round($x,$y,$x+1,$y,$area);
        $x++;
    }
    else if( is_free_point(($x),($y-1),$area) &&
        !is_danger_point(($x),($y-1),$area) ) {
        set_round($x,$y,$x,$y-1,$area);
        $y--;
    }
    else {
        set_round($x,$y,$x,$y,$area);
    }
}

function set_round($x1, $y1, $x2, $y2, &$area) {
    if($x2==7 && $y2==0) {
        die('WIN');
    }
    else {
        $area[$y1][$x1] = '.';
        $area[$y2][$x2] = 'M';
    }
    move_enemy($area);
}

function move_enemy(&$area) {
    for($x=0;$x<8;$x++) {
        for($y=7;$y>=0;$y--) {
            if(in_array($area[$y][$x], array('S'))) {
                $area[$y][$x] = '.';
                if($y+1 <= 7) {
                    if(in_array($area[$y+1][$x], array('M'))) {
                        die('LOSE');
                    }
                    $area[$y+1][$x] = 'S';
                }
            }
        }
    }
}

function is_free_point($x,$y, $area) {
    if(valid_point($x, $y)) {
        if(in_array($area[$y][$x], array('.','A','M'))) {
            return TRUE;
        }
    }
    return FALSE;
}

function is_danger_point($x,$y,$area) {
    if( valid_point($x,($y-1) ) === FALSE || is_free_point($x, ($y-1) , $area) ) {
        return FALSE;
    }
    return TRUE;
}

function valid_point($x,$y) {
    if($x > 7 || $y > 7 || $x < 0 || $y < 0) {
        return FALSE;
    }
    return TRUE;
}

<?php
$area = array();
for( $i=0; $i<8; $i++) {
    $area[$i] = trim(fgets(STDIN));
}

$x = 0;
$y = 7;
$i = 0;
while(1) {
    if( is_free_point(($x+1),($y-1),$area) &&
        !is_danger_point(($x+1),($y-1),$area) ) {
        set_round($x,$y,$x+1,$y-1,$area);
        $x++;$y--;
    }
    else if( is_free_point(($x+1),($y),$area) &&
        !is_danger_point(($x+1),($y),$area) ) {
        set_round($x,$y,$x+1,$y,$area);
        $x++;
    }
    else if( is_free_point(($x-1),($y-1),$area) &&
        !is_danger_point(($x-1),($y-1),$area) ) {
        set_round($x,$y,$x-1,$y-1,$area);
        $x--;$y--;
    }
    else if( is_free_point(($x),($y-1),$area) &&
        !is_danger_point(($x),($y-1),$area) ) {
        set_round($x,$y,$x,$y-1,$area);
        $y--;
    }
    else if( is_free_point(($x),($y+1),$area) &&
        !is_danger_point(($x),($y+1),$area) ) {
        set_round($x,$y,$x,$y+1,$area);
        $y++;
    }
    else {
        set_round($x,$y,$x,$y,$area);
    }
}

function set_round($x1, $y1, $x2, $y2, &$area) {
    if($x2==7 && $y2==0) {
        die('WIN');
    }
    else {
        $area[$y1][$x1] = '.';
        $area[$y2][$x2] = 'M';
    }
    move_enemy($area);
}

function move_enemy(&$area) {
    for($x=0;$x<8;$x++) {
        for($y=7;$y>=0;$y--) {
            if(in_array($area[$y][$x], array('S'))) {
                $area[$y][$x] = '.';
                if($y+1 <= 7) {
                    if(in_array($area[$y+1][$x], array('M'))) {
                        die('LOSE');
                    }
                    $area[$y+1][$x] = 'S';
                }
            }
        }
    }
}

function is_free_point($x,$y, $area) {
    if(valid_point($x, $y)) {
        if(in_array($area[$y][$x], array('.','A','M'))) {
            return TRUE;
        }
    }
    return FALSE;
}

function is_danger_point($x,$y,$area) {
    if( valid_point($x,($y-1) ) === FALSE || is_free_point($x, ($y-1) , $area) ) {
        return FALSE;
    }
    return TRUE;
}

function valid_point($x,$y) {
    if($x > 7 || $y > 7 || $x < 0 || $y < 0) {
        return FALSE;
    }
    return TRUE;
}