Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number a and Antisimon receives number b. They also have a heap of n stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given a, b and n who wins the game.

The only string contains space-separated integers a, b and n (1 ≤ a, b, n ≤ 100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.

If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).

NoteThe greatest common divisor of two non-negative integers a and b is such maximum positive integer k, that a is divisible by k without remainder and similarly, b is divisible by k without remainder. Let gcd(a, b) represent the operation of calculating the greatest common divisor of numbers a and b. Specifically, gcd(x, 0) = gcd(0, x) = x.In the first sample the game will go like that: Simon should take gcd(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left. Antisimon should take gcd(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left. Simon should take gcd(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left. Antisimon should take gcd(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left. Simon should take gcd(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left. Antisimon should take gcd(5, 0) = 5 stones from the heap. As 0 < 5, it is impossible and Antisimon loses.In the second sample each player during each move takes one stone from the heap. As n is even, Antisimon takes the last stone and Simon can't make a move after that.

<?php
list($a,$b,$n)=explode(" ", trim(fgets(STDIN)));
function nod($a, $b) {
    while ($a != $b)
        if ($a>$b)
            $a -= $b;
        else
            $b -= $a;
    return $a;
}
function lite($a,$b,$n){
   $f=nod($a,$n);
   if (($n-$f)==0) return 0;
   $f1=nod($b,$n-$f);
   if (($n-$f-$f1)==0) return 1;
   return lite($a,$b,$n-=($f+$f1));
}
print lite($a, $b, $n);
?>

<?php
while($s = fgets(STDIN)){
$input .= $s;
}

function NOD($a, $b) {
    if($a == 0) return $b;
    if($b == 0) return $a;
    $max = max($a, $b);
    for ($i=1; $i <= $max; $i++) {
        if((($a % $i) == 0) && (($b % $i) == 0)) {
            $delitels[] = $i;
        }
    }

    return max($delitels);
}

$input = explode(' ', $input);
$semen = (int)$input[0];
$anti = (int)$input[1];
$stones = (int)$input[2];

$status = 0;
$winner = 0;
while(true) {

    if($status == 0) {
        $take = NOD($semen, $stones);
        $stones = $stones - $take;
        if($stones < $take) {
            $winner = 0;
            break;
        }

        $status = 1;
    }

    if($status == 1) {
        $take = NOD($stones, $anti);
        $stones = $stones - $take;
        if($stones < $take) {
            $winner = 1;
            break;
        }

        $status = 0;
    }

}

echo $winner;

<?php
list($a,$b,$n) = explode(" ",trim(fgets(STDIN)));
function gcd($a,$b)
{
    return ($a % $b) ? gcd($b,$a % $b) : $b;
}
while (true)
{
    if ($n==0){echo "1";break;}
    $n -= gcd($a,$n);
    if ($n==0){echo "0";break;}
    $n -= gcd($b,$n);
}

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

$k = $a;
$nn = $n;
$sem = true;

while ($n > 0)
{
    while ($k != $n)
    {
        if ($k > $n)
            $k -= $n;
        else
            $n -= $k;
    }

    if ($sem)
    {
        $sem = false;
        $k = $b;
    }
    else
    {
        $sem = true;
        $k = $a;
    }

    $n = $nn - $n;
    $nn = $n;
    if ($n <= 0)
    {
        switch ($sem)
        {
            case true:
                echo "1";
                break;
            case false:
                echo "0";
                break;
        }
        break;
    }
}
?>

<?php
// 119A Эпическая игра

// Наибольший общий делитель НОД
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

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

$input_line = fgets($in);
list($a, $b, $n) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$flag = true;
while (true) {
    if ($flag) {
        $c = $a;
    } else {
        $c = $b;
    }

    $cc = max(abs($c), abs($n));
    $nn = min(abs($c), abs($n));

    $gcd = gcd ($cc, $nn);
//echo "c=$c gcd=$gcd n=$n flag=$flag \n";
    if (($gcd <= $n) and ($n > 0)) {
        $n -= $gcd;
        $flag = $flag ^ true;
    } else {
        break;
    }
}

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

?>

<?php
function NWD($a, $b) {
    while ($b != 0) {
        $c = $a % $b;
        $a = $b;
        $b = $c;
    }
    return $a;
}

fscanf(STDIN, '%d %d %d', $a, $b, $n);

$player = 0;
while($n > 0) {
    if(!$player) {
        $c = $a;
    } else {
        $c = $b;
    }
    $n -= NWD($c, $n);
    $player = !$player;
}

echo intVal(!$player);

<?php
function gcd($i, $j){
 if($i == 0) return $j;
 if($j == 0) return $i;
 if($i == $j) return $i;
 if($i > $j) return gcd($i % $j, $j); else return gcd($i, $j % $i);
}

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

$r = 1;
while($n > 0){
 if($r == 1) $n -= gcd($n, $a); else $n -= gcd($n, $b);
 $r = 1 - $r;
}

print $r;

?>

<?php
list($a,$b,$n)=explode(' ',trim(fgets(STDIN)));
function HOD($a,$n) {
    while ($a*$n != 0) !($a < $n) ? $a %= $n : $n %= $a;
    return ($a + $n);
}
while(true) {
    $n -= HOD($a,$n);
    if($n<=0) { echo '0'; break; }
    $n -= HOD($b,$n);
    if($n<=0) { echo '1'; break; }
}

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

$k = $a;
$nn = $n;
$sem = true;

while ($n > 0)
{
    while ($k != $n)
    {
        if ($k > $n)
            $k -= $n;
        else
            $n -= $k;
    }

    if ($sem)
    {
        $sem = false;
        $k = $b;
        $m++;
    }
    else
    {
        $sem = true;
        $k = $a;
        $l++;
    }

    $n = $nn - $n;
    $nn = $n;
}
if ($k == max($k, $l))
    echo "0";
else
    echo "1";
?>

<?php
// 119A Эпическая игра

// Наибольший общий делитель НОД
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

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

$input_line = fgets($in);
list($a, $b, $n) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$flag = true;
while (true) {
    if ($flag) {
        $sum = $a + $n;
        $c = $a;
    } else {
        $sum = $b + $n;
        $c = $b;
    }

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

echo " c=$c sum=$sum gcd=$gcd \n";
    if ($gcd <= $n) {
        $n -= $gcd;
        $flag = $flag ^ true;
    } else {
        break;
    }
}

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

?>

<?php
// 119A Эпическая игра

// Наибольший общий делитель НОД
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

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

$input_line = fgets($in);
list($a, $b, $n) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$flag = true;
while (true) {
    if ($flag) {
        $c = $a;
    } else {
        $c = $b;
    }

    $cc = max(abs($c), abs($n));
    $nn = min(abs($c), abs($n));

    $gcd = gcd ($cc, $nn);
echo "c=$c gcd=$gcd n=$n flag=$flag \n";
    if (($gcd <= $n) and ($n > 0)) {
        $n -= $gcd;
        $flag = $flag ^ true;
    } else {
        break;
    }
}

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

?>

<?php
// 119A Эпическая игра

// Наибольший общий делитель НОД
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

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

$input_line = fgets($in);
list($a, $b, $n) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$flag = true;
while (true) {
    if ($flag) {
        $sum = $a + $n;
        $c = $a;
    } else {
        $sum = $b + $n;
        $c = $b;
    }

    $gcd = gcd($с, $sum);

    if ($gcd <= $n) {
        $n -= $gcd;
        $flag = $flag ^ true;
    } else {
        break;
    }
}

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

?>

<?php
// 119A Эпическая игра

// Наибольший общий делитель НОД
function gcd($a, $b)
{
    if ($a == 0 || $b == 0)
        return abs( max(abs($a), abs($b)) );

    $r = $a % $b;
    return ($r != 0) ?
        gcd($b, $r) :
        abs($b);
}

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

$input_line = fgets($in);
list($a, $b, $n) = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);

$flag = true;
while (true) {
    if ($flag) {
        $sum = $a + $n;
        $c = $a;
    } else {
        $sum = $b + $n;
        $c = $b;
    }

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

    if ($gcd <= $n) {
        $n -= $gcd;
        $flag = $flag ^ true;
    } else {
        break;
    }
}

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

?>


In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.

Four lines contain four characters each: the j-th character of the i-th line equals "." if the cell in the i-th row and the j-th column of the square is painted white, and "#", if the cell is black.

Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise.

NoteIn the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column.

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

// Codeforces Contest 176 Div 2 Problem A
for ($i = 0; $i < 4; $i++) {
	$raw = g();
	for ($j = 0; $j < 4; $j++) {
		$x[$i][$j] = ((substr($raw[0], $j, 1) == "#") ? 1 : 0);
	}
}

function square($i,$j) {
	global $x;
	return $x[$i][$j] + $x[$i][$j+1] + $x[$i+1][$j] + $x[$i+1][$j+1];
}

for ($i = 0; $i < 3; $i++) {
	for ($j = 0; $j < 3; $j++) {
		if (square($i, $j) != 2) {echo "YES"; exit;}
	}
}

echo "NO";

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


You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.

First line contains an integer n (6 ≤ n ≤ 8) – the length of the string. Next line contains a string consisting of n characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).

Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).

NoteHere's a set of names in a form you can paste into your solution:["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}

<?php
$names = array("vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon");
$num = (int)trim(fgets(STDIN));
$str = trim(fgets(STDIN));
$rezult='';

if ($num<6 || $num >8) exit;

foreach($names as $k=>$v){
if(strlen($v)==$num){
$temp=0;
for($i=0;$i<=strlen($str)-1;$i++){

if($v[$i]==$str[$i] || $str[$i]=='.'){
$temp++;
}

}
if($temp==$num){$rezult=$v;}
}
}

print $rezult;
?>

<?php

$len = (int)trim(fgets(STDIN));

if ($len < 6 OR $len > 8) exit;

$letter = trim(fgets(STDIN));

if ($len !== strlen($letter)) exit;

$pokemons = array("vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon");

$letters = array();
for ($i=0; $i<$len; $i++)
{
    if ($letter{$i} === '.') continue;
    $letters[$i] = $letter{$i};
}

$result = '';
foreach ($pokemons as $pokemon)
{
    if (strlen($pokemon) !== $len) continue;

    $find = TRUE;
    foreach ($letters as $k => $v)
        if ($pokemon{$k} !== $v)
            $find = FALSE;

    if ($find)
    {
        $result = $pokemon;
        break;
    }
}

print $result;

<?php

//$t = microtime(true);
$n = (int)(trim(readln()));

if ($n === 6) {
	echo 'espeon';
	die();
}
elseif ($n === 8) {
	echo 'vaporeon';
	die();
}
elseif ($n === 7) {
	$ar = array(
		'jolteon',
		'flareon',
		'umbreon',
		'leafeon',
		'glaceon',
		'sylveon'
	);
	$str = trim(readln());
	for($i = 0; $i < 7; $i++) {
		$char = $str[$i];
		if ($str[$i] === '.') {
			continue;
		}
		$ar = array_filter($ar, function($item) use ($char, $i) {
			return $item[$i] == $char;
		});
	}
	echo reset($ar);
}

//echo $t - microtime(true);
function readln()
{
	static $input =null;
	if ($input === null) {
		$input = fopen('php://STDIN', 'r');
//		$debug = __FILE__ . '.txt';
//		var_dump($debug);
//		$input = fopen($debug, 'r');
	}
	return trim(fgets($input));
}

<?php
fscanf(STDIN,"%d",$n);
$str=trim(fgets(STDIN));
$eve=[
		 0=>"vaporeon",
		 1=>"jolteon",
		 2=>"flareon",
		 3=>"espeon",
		 4=>"umbreon",
		 5=>"leafeon",
		 6=>"glaceon",
		 7=>"sylveon"
    ];
 $ev1="vaporeon";
 $ev2="jolteon";
 $ev3="flareon";
 $ev4="espeon";
 $ev5="umbreon";
 $ev6="leafeon";
 $ev7="glaceon";
 $ev8="sylveon";
if($str=='......')
echo "espeon";
elseif ($str=='........')
 {
 	echo "vaporeon";
	# code...
}

else
{

   $flag=0;
   $max=0;
   //$length=9;
   $trgetStr=findTrgtStr($str);
for ($i=0; $i <count($eve) ; $i++)
{

	$count=0;

   for ($j=0; $j <5 ; $j++)
    {

   	   if($eve[$i][$j]==$trgetStr[$count])
   	   {

   	   	   $count++;
   	   	  // $str3=$eve[$i];

   	   	   if($count==strlen($trgetStr))
   	   	   {
             //echo "$str3\n";
   	   	   	$flag=1;
   	   	   	break;
   	   	   }
   	   }

    }

          if($count>=$max&&strlen($eve[$i])==$n)
          {
          	$max=$count;
          	//$length=strlen($eve[$i]);
          	$str3=$eve[$i];
          }
          //echo "$max\n";

}
print_r($str3);
}

function findTrgtStr($str)
{
	$trgetStr="";
for ($i=0; $i <strlen($str) ; $i++)
{
	if($str[$i]=='.')
		continue;
	else
		$trgetStr.=$str[$i];

}
return $trgetStr;
}

<?php
fscanf(STDIN,"%d",$n);
$str=trim(fgets(STDIN));
$eve=[
		 0=>"vaporeon",
		 1=>"jolteon",
		 2=>"flareon",
		 3=>"espeon",
		 4=>"umbreon",
		 5=>"leafeon",
		 6=>"glaceon",
		 7=>"sylveon"
    ];

if($str=='......')
echo "espeon";
elseif ($str=='........')
 {
 	echo "vaporeon";
	# code...
}

else
{

   $flag=0;
   $max=0;
   //$length=9;
   $trgetStr=findTrgtStr($str);
for ($i=0; $i <count($eve) ; $i++)
{

	$count=0;

   for ($j=0; $j <5 ; $j++)
    {

   	   if($eve[$i][$j]==$trgetStr[$count])
   	   {

   	   	   $count++;
   	   	  // $str3=$eve[$i];

   	   	   if($count==strlen($trgetStr))
   	   	   {
             //echo "$str3\n";
   	   	   	$flag=1;
   	   	   	break;
   	   	   }
   	   }

    }

          if($count>=$max&&strlen($eve[$i])==$n)
          {
          	$max=$count;
          	//$length=strlen($eve[$i]);
          	$str3=$eve[$i];
          }
          //echo "$max\n";

}
print_r($str3);
}

function findTrgtStr($str)
{
	$trgetStr="";
for ($i=0; $i <strlen($str) ; $i++)
{
	if($str[$i]=='.')
		continue;
	else
		$trgetStr.=$str[$i];

}
return $trgetStr;
}

<?php
/**
 * User: Nash
 * Date: 7/27/14
 * Time: 10:29 PM
 */
$in = fopen('php://stdin', 'r');

$names = array("jolteon", "flareon", "umbreon", "leafeon", "glaceon", "sylveon");
$pos = array(1,1,1,1,1,1);
$n = intval(rtrim(fgets($in)));
$s = rtrim(fgets($in));

if($n==6){
    echo "espeon";
}
else if($n==8){
    echo "vaporeon";
}else{
    $c = 6;
    for($i=0; $i<$n; $i++){
        if($s[$i]!="."){
            foreach($names as $k => $name){
                if($pos[$k] && $s[$i]!=$name[$i]){
                    $pos[$k] = 0;
                    $c--;
                }
            }
            if($c==1){
                break;
            }
        }
    }

    for($i=0; $i<$n; $i++){
        if($pos[$i]){
            echo $names[$i];
            break;
        }
    }

}

<?php
$pokemons = array("vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon");
$num = (int)trim(fgets(STDIN));
$str = trim(fgets(STDIN));

print 'jolteon';
?>

<?php
fscanf(STDIN,"%d",$n);
$str=trim(fgets(STDIN));
$trgetStr="";
for ($i=0; $i <strlen($str) ; $i++)
{
	if($str[$i]=='.')
		continue;
	else
		$trgetStr.=$str[$i];

}
$eve=[
		 0=>"vaporeon",
		 1=>"jolteon",
		 2=>"flareon",
		 3=>"espeon",
		 4=>"umbreon",
		 5=>"leafeon",
		 6=>"glaceon",
		 7=>"sylveon"
    ];

   $flag=0;
   $max=0;
for ($i=0; $i <count($eve) ; $i++)
{   $count=0;
   for ($j=0; $j <5 ; $j++)
    {

   	   if($eve[$i][$j]==$trgetStr[$count])
   	   {

   	   	   $count++;
   	   	  // $str3=$eve[$i];

   	   	   if($count==strlen($trgetStr))
   	   	   {
             //echo "$str3\n";
   	   	   	$flag=1;
   	   	   	break;
   	   	   }
   	   }

    }
          if($count>=$max)
          {
          	$max=$count;
          	$str3=$eve[$i];
          }
          //echo "$max\n";

   if($flag==1)
   	break;

}
echo "$str3\n";

<?php
fscanf(STDIN,"%d",$n);
$str=trim(fgets(STDIN));
if($str=='......')
echo "espeon";
elseif ($str=='........')
 {
 	echo "vaporeon";
	# code...
}
else
{
$trgetStr="";
for ($i=0; $i <strlen($str) ; $i++)
{
	if($str[$i]=='.')
		continue;
	else
		$trgetStr.=$str[$i];

}
$eve=[
		 0=>"vaporeon",
		 1=>"jolteon",
		 2=>"flareon",
		 3=>"espeon",
		 4=>"umbreon",
		 5=>"leafeon",
		 6=>"glaceon",
		 7=>"sylveon"
    ];

   $flag=0;
   $max=0;
for ($i=0; $i <count($eve) ; $i++)
{   $count=0;
   for ($j=0; $j <5 ; $j++)
    {

   	   if($eve[$i][$j]==$trgetStr[$count])
   	   {

   	   	   $count++;
   	   	  // $str3=$eve[$i];

   	   	   if($count==strlen($trgetStr))
   	   	   {
             //echo "$str3\n";
   	   	   	$flag=1;
   	   	   	break;
   	   	   }
   	   }

    }
          if($count>=$max)
          {
          	$max=$count;
          	$str3=$eve[$i];
          }
          //echo "$max\n";

   if($flag==1)
   	break;

}
echo "$str3\n";
}


While playing with geometric figures Alex has accidentally invented a concept of a $$$n$$$-th order rhombus in a cell grid.A $$$1$$$-st order rhombus is just a square $$$1 \times 1$$$ (i.e just a cell).A $$$n$$$-th order rhombus for all $$$n \geq 2$$$ one obtains from a $$$n-1$$$-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better).    Alex asks you to compute the number of cells in a $$$n$$$-th order rhombus.

The first and only input line contains integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — order of a rhombus whose numbers of cells should be computed.

Print exactly one integer — the number of cells in a $$$n$$$-th order rhombus.

NoteImages of rhombus corresponding to the examples are given in the statement.

<?php
# 1180A
$stdin = STDIN;
[$n] = fscanf($stdin, '%u');
$quarter = 0;
$quarterLimit = $n - 1;
for ($i = 1; $i <= $quarterLimit; $i++) {
    $quarter += $i;
}
echo $quarter * 4 + 1;

<?php
$n = trim(fgets(STDIN));
echo $n ** 2 + ($n - 1) ** 2;

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

    echo pow($n, 2) + pow($n-1, 2);

?>

<?php
$input=trim(fgets(STDIN));
$sum=0;
$array=range(1,1000,2);
for ($i=0;$i<$input;$i++) {
      $sum+=$array[$i];
}
$sum=$sum*2-$array[$input-1];
echo $sum;


Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.You know that there will be n interesting minutes t1, t2, ..., tn. Your task is to calculate for how many minutes Limak will watch the game.

The first line of the input contains one integer n (1 ≤ n ≤ 90) — the number of interesting minutes. The second line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... tn ≤ 90), given in the increasing order.

Print the number of minutes Limak will watch the game.

NoteIn the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.In the second sample, the first 15 minutes are boring.In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game.

<?php

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

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

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

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

?>

<?php
// http://codeforces.com/problemset/problem/691/A
$handle = fopen ("php://stdin", "r");
fscanf($handle, "%i",$n);
$arr_temp = fgets($handle);
$arrInput = explode(" ",$arr_temp);
$arr = array_map('intval', $arrInput);

$maxWait = 15;
foreach ($arr as $interestMin) {
	if($interestMin > $maxWait){
		echo $maxWait;die;
	}else{
		$maxWait = $interestMin + 15;
	}
}
echo $maxWait > 90 ? 90 : $maxWait;

?>

<?php

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

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

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

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

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

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

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

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

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

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

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

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

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

<?php

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

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

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

watchTime($n,$t);

<?php

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

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

watchTime($n,$t);

<?php

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

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

	$prevMin = 0;
	foreach($minutes as $min) {
		$min = (int)$min;
		if($min == 90) {
			echo 90;
			break;
		}
		if($min - $prevMin > 15) {
			echo $prevMin + 15;
			break;
		}
		$prevMin = $min;
	}

?>

<?php

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

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

	$prevMin = 0;
	foreach($minutes as $min) {
		$min = (int)$min;
		if($min == 90) {
			echo 90;
			break;
		}
		if($min - $prevMin > 15) {
			echo $prevMin + 15;
			break;
		}
	}

?>

<?php

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

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

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

<?php

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

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

	$prevMin = 0;
	foreach($minutes as $min) {
		$min = (int)$min;
		if($min == 90) {
			echo 90;
			break;
		}
		if($min - $prevMin > 15) {
			echo $min + 15;
			break;
		}
	}

?>

<?php

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

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

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

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

?>

<?php
// http://codeforces.com/problemset/problem/691/A
$handle = fopen ("php://stdin", "r");
fscanf($handle, "%i",$n);
$arr_temp = fgets($handle);
$arrInput = explode(" ",$arr_temp);
$arr = array_map('intval', $arrInput);
if(empty($arr)){
	echo 15;
	die;
}
$maxWait = 15;
foreach ($arr as $interestMin) {
	if($interestMin > $maxWait){
		echo $maxWait;die;
	}else{
		$maxWait = $interestMin + 15;
	}
}
echo 90;

?>

<?php

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

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

watchTime($n,$t);

<?php

$in = 'php://stdin';
$input = fopen($in, "r");
$n = fgets($input);
$t = [];
$t = array_merge($t, explode(" ", trim(fgets($input))));
function watchTime($n, $t) {
    $watchTime = 0;
    $funLimit = 15;
    for($i = 0; $i < $n; $i++){
        $inTime = ceil(($t[$i]-$watchTime)/$funLimit);
        if($inTime > 1){
            $watchTime+=15;
            break;
        } else {
            $watchTime = $t[$i];
        }
    }
    echo $watchTime;
}

echo watchTime($n,$t);

<?php

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

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

echo watchTime($n,$t);

<?php

$in = 'php://stdin';

$input = fopen($in, "r");

$n = fgets($input);

$t = [];

$t = array_merge($t, explode(" ", trim(fgets($input))));

function kq($t, $n) {

    $temp=1;

    for($i=0;$i<$n;$i++)
    {
        $delta = $t[$i] - $temp;

        if ($delta >= 15) {
            return $temp + 15;
        }

        $temp = $t[$i];
    }

    $temp += 15;

    return $temp >= 90 ? 90 : $temp;
}

echo kq($t,$n);

<?php

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

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

watchTime($n,$t);

<?php

$in = 'php://stdin';
$input = fopen($in, "r");
$n = fgets($input);
$t = [];
$t = array_merge($t, explode(" ", trim(fgets($input))));
function watchTime($n, $t) {
    $watchTime = 0;
    $funLimit = 15;
    for($i = 0; $i < $n; $i++){
        echo "[$i] watchTime=$watchTime atTime=$t[$i] ";
        $inTime = ceil(($t[$i]-$watchTime)/$funLimit);

        if($inTime > 1){
            $watchTime+=15;
            echo "inTime=$inTime".PHP_EOL;
            break;
        } else {
            $watchTime = $t[$i];
        }

        echo "inTime=$inTime".PHP_EOL;
    }

    echo $watchTime;
}

echo watchTime($n,$t);


A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels. Your task is to determine the size of the rectangular display — the number of lines (rows) of pixels a and the number of columns of pixels b, so that:  there are exactly n pixels on the display;  the number of rows does not exceed the number of columns, it means a ≤ b;  the difference b - a is as small as possible.

The first line contains the positive integer n (1 ≤ n ≤ 106) — the number of pixels display should have.

Print two integers — the number of rows and columns on the display.

NoteIn the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels.

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

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

$n = $dxs->GL();
$a = (int) sqrt($n);

for( ; $a ; $a--) {
	if($n % $a == 0) {
		$t = $n / $a;
		echo min($t, $a) . ' ' . max($t, $b);
		break;
	}
}

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

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

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

<?php
fscanf(STDIN,"%d",$lenOfStr);
fscanf(STDIN,"%s",$str);
$decision=false;

if($lenOfStr%4==0)
 {
 	 $a=0;
 	 $g=0;
 	 $c=0;
 	 $t=0;
     $split=str_split($str);
     for ($i=0; $i <count($split) ; $i++)
      {
     	   if($split[$i]=='A')
     	   	   $a++;
     	   	elseif ($split[$i]=='G')
     	   	 {
     	   		$g++;
     	   	 }
     	   	elseif ($split[$i]=='C')
     	   	 {
     	   		$c++;
     	   	 }
     	   	 else
     	   	 {
     	   	 	if($split[$i]=='T')
     	   	 		$t++;
     	   	 }

      }
      $div=$lenOfStr/4;
      if($div<$a||$div<$g||$div<$c||$div<$t)
      	  $decision=false;
       //$loop=$div;
       else
       {

       	    while($a<$div)
       	    {
       	    	for ($i=0; $i <strlen($str) ; $i++)
       	    	 {
       	    		if($str[$i]=='?')
       	    		{
       	    			$str[$i]='A';
       	    			break;
       	    		}
       	    	 }
       	    	$a++;
       	    }
       	    while($c<$div)
       	    {
       	    	for ($i=0; $i <strlen($str) ; $i++)
       	    	 {
       	    		if($str[$i]=='?')
       	    		{
       	    			$str[$i]='C';
       	    			break;
       	    		}
       	    	 }
       	    	$c++;
       	    }
       	    while($g<$div)
       	    {
       	    	for ($i=0; $i <strlen($str) ; $i++)
       	    	 {
       	    		if($str[$i]=='?')
       	    		{
       	    			$str[$i]='G';
       	    			break;
       	    		}
       	    	 }
       	    	$g++;
       	    }
       	    while($t<$div)
       	    {
       	    	for ($i=0; $i <strlen($str) ; $i++)
       	    	 {
       	    		if($str[$i]=='?')
       	    		{
       	    			$str[$i]='T';
       	    			break;
       	    		}
       	    	 }
       	    	$t++;
       	    }

       	    //echo "$str";
        	$decision=true;
       }
 }
 echo $decision?"$str":"===";


Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.  Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!

The first line of input contains an integer n (1 ≤ n ≤ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 ≤ ai ≤ 100) denotes the number of cubes in the i-th column.

Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.

NoteThe first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.In the second example case the gravity switch does not change the heights of the columns.

<?php fgets(STDIN); $a = explode(' ', trim(fgets(STDIN))); sort($a); echo join( ' ',  $a);

<?php
$n = trim(fgets(STDIN));
$a = trim(fgets(STDIN));
$a = explode( ' ' , $a);
sort($a);
echo join(' ', $a);

<?php

$n = (readline() - 1);
$input = (explode(" ",readline()));

for($i = 0; $i < $n; $i++){
    for($x = 0; $x < $n; $x++) {
        if($input[$x] > $input[$x+1]){
            $z = $input[$x];
            $input[$x] = $input[$x+1];
            $input[$x+1] = $z;
        }
    }
}

$output = implode(" ", $input);

print $output;

?>

<?php

$n = readline();
$input = explode(" ",readline());
sort($input);

print implode(" ", $input);

?>

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

sort($a);
for($i=0;$i<$n;$i++)
{
echo $a[$i]." ";
}
?>

<?php
$dir = fopen("php://stdin", 'r');;
$input= file('php://stdin');
$arr= explode(' ',trim($input[1]));
sort($arr);
echo  implode(' ',$arr);

<?php
$dir = fopen("php://stdin", 'r');;
$input= file('php://stdin');
$arr= explode(' ',trim($input[1]));
sort($arr);
foreach ($arr as $item){
    echo  $item . " ";
}

<?php

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

// get inputs
$number_of_columns = trim(fgets(STDIN));
$columns_cubes = explode(' ', trim(fgets(STDIN)));

// solution
sort($columns_cubes);
echo implode(' ', $columns_cubes) . "\n";

<?php
	$n = trim(fgets(STDIN));
	$str = trim(fgets(STDIN));
	$strx = explode(" ",$str);
	sort($strx);
	echo implode(" ", $strx);
?>

<?php
    fscanf (STDIN, "%d", $n);
    $arr = explode(" ", trim(fgets(STDIN)));
    sort($arr);
        for ($i = 0; $i < $n; $i++){
            echo ($arr[$i] . " ");
        }

<?php

function r(){
    return trim(fgets(STDIN));
}
function w($str = ''){
    echo $str . "\r\n";
}

$count = r();
$col = explode(' ', r());

do{
    $end = true;
    for($i = 0; $i < $count-1; $i++){
        if($col[$i + 1] > $col[$i]){
            $t = $col[$i + 1];
            $col[$i + 1] = $col[$i];
            $col[$i] = $t;

            $end = false;
        }
    }
}while(!$end);

$col = array_reverse($col);
w(implode(' ', $col));

<?php

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

sort($arr);
$str = implode(' ', $arr);
echo $str;

<?php
$n= trim(fgets(STDIN));
$stolb = explode(" ",trim(fgets(STDIN)));
asort($stolb);
foreach ($stolb as $key)echo $key." ";

<?php
fscanf(STDIN,"%d",$n);
$line=trim(fgets(STDIN));
$singleValue=explode(' ', $line);
for($i=0;$i<$n;$i++){
	for($j=0;$j<$n-1;$j++){
		if($singleValue[$i]<$singleValue[$j])
		{
			$singleValue[$i]=$singleValue[$i]+$singleValue[$j];
			$singleValue[$j]=$singleValue[$i]-$singleValue[$j];
			$singleValue[$i]=$singleValue[$i]-$singleValue[$j];

		}

	}
}
for($i=0;$i<$n;$i++)
	echo "$singleValue[$i] ";

<?php
	$stream = fopen("php://stdin", "r");
	$input = stream_get_contents($stream);
    $ins = preg_split("/[\s]+/", $input);
    $cnt = 0;
    $N = $ins[$cnt++];
    for($i = 0; $i < $N; $i++) $arr[$i] = $ins[$cnt++];
    sort($arr);
	for($i = 0; $i < $N; $i++)
		echo "{$arr[$i]} ";
	echo "\n";
?>

<?php

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

$a = explode(" ",trim(fgets($f)));

sort($a);
$s = implode(" ",$a);

print_r($s);

<?php

$stdout = fopen(getenv("OUTPUT_PATH"), "w");
$stdin = fopen("php://stdin", "r");

fscanf( $stdin , "%d" , $n ) ;
fscanf( $stdin , "%[^\n]" , $arr ) ;

$array = array_map( 'intval' , preg_split('/ /' , $arr, -1 , PREG_SPLIT_NO_EMPTY ) );
sort( $array ) ;
for( $i=0 ; $i<$n ; $i++ )
{
     echo $array[$i] . " " ;
}

fwrite($stdout);

fclose($stdin);
fclose($stdout);

?>

<?php
$n = fgets(STDIN);
$array = explode(" ", fgets(STDIN));
$output = [];
for($i=0;$i<$n;$i++){
    $output[] =(int)$array[$i];
}
sort($output);
for($i=0;$i<$n;$i++){
    echo $output[$i].' ';
}

<?php
$fi=@fopen('test.inp',"r");
$n=trim(fgets(STDIN));
$a=explode(" ",trim(fgets(STDIN)));
sort($a);
for ($i=0;$i<$n;$i++)
	echo $a[$i]." ";
?>

<?php
$n = trim(fgets(STDIN));
$cube = explode(" ", trim(fgets(STDIN)));
for($i=$n-1;$i>=0;$i--){
    for($j=$n-1;$j>=0;$j--){
		if ($cube[$i] > $cube[$j]){
			$sisa = $cube[$i] - $cube[$j];
			$cube[$j] += $sisa;
			$cube[$i] -= $sisa;
		}
	}
}
foreach($cube as $value){
	echo $value . " ";
}
?>

<?php
	$cin = fopen("php://stdin", "r");
	$n = intval(fgets($cin));
	$s = fgets($cin);
	$a = explode(" ", $s);
	sort($a, SORT_NUMERIC);
	for($i = 0; $i < $n; $i++){
		echo $a[$i]." ";
	}
	fclose($cin);
?>

<?php
// 405A     Переключение гравитации
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);

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

foreach ($arr as $key => &$value) {
    $value = (int) $value;
}
unset($value);

sort($arr);

$out = implode(" ", $arr);

echo $out;

?>

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

	$n = fgets($temp);
	$arr = explode(" ", fgets($temp));

	$int_arr =array();

	foreach($arr as $a )
	{
		$int_arr[] = intval($a);
	}

	sort($int_arr);

	foreach($int_arr as $a)
	{
		echo $a . " ";
	}
?>

<?
$a=fgets(STDIN);
$m=explode(" ",trim(fgets(STDIN)));
sort($m);
echo join(" ",$m);
?>

<?php

$n = readline();
$input = (explode(" ",readline()));

for($i = 0; $i < ($n-1); $i++){
    for($x = 0; $x < ($n-1); $x++) {
        if($input[$x] > $input[$x+1]){
            $z = $input[$x];
            $input[$x] = $input[$x+1];
            $input[$x+1] = $z;
        } else {
            break;
        }
    }
}

$output = implode(" ", $input);

print $output;

?>

<?php

$n = (readline() - 1);
$input = (explode(" ",readline()));

for($i = 0; $i < $n; $i++){
    for($x = 0; $x < $n-1; $x++) {
        if($input[$x] > $input[$x+1]){
            $z = $input[$x];
            $input[$x] = $input[$x+1];
            $input[$x+1] = $z;
        }
    }
}

$output = implode(" ", $input);

print $output;

?>

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

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

<?php
    $arr = explode(" ", trim(fgets(STDIN)));
    sort($arr);
        for ($i = 0; $i < count($arr); $i++){
            echo ($arr[$i] . " ");
        }

<?php
$n= trim(fgets(STDIN));
$stolb = explode(" ",trim(fgets(STDIN)));
asort($stolb);
foreach ($stolb as $key)echo $key;

<?php
$n = fgets(STDIN);
$array = explode(" ", fgets(STDIN));
sort($array);
for($i=0;$i<$n;$i++){
    echo $array[$i]. ' ';
}

<?php
$n = fgets(STDIN);
$array = explode(" ", fgets(STDIN));
sort($array);
echo implode(' ',$array);

<?php
$n = fgets(STDIN);
$array = explode(" ", fgets(STDIN));
sort($array);
echo $output = implode(' ',$array);

<?
$a=fgets(STDIN);
$m=explode(" ",fgets(STDIN));
sort($m);
foreach($m as $v)
    {
        echo $v." ";
    }
?>

<?
$a=fgets(STDIN);
$m=explode(" ",trim(" ",fgets(STDIN)));
sort($m);
foreach($m as $v)
    {
        echo $v." ";
    }
?>


There are n students who have taken part in an olympiad. Now it's time to award the students.Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and certificates. The number of certificates must be exactly k times greater than the number of diplomas. The number of winners must not be greater than half of the number of all students (i.e. not be greater than half of n). It's possible that there are no winners.You have to identify the maximum possible number of winners, according to these rules. Also for this case you have to calculate the number of students with diplomas, the number of students with certificates and the number of students who are not winners.

The first (and the only) line of input contains two integers n and k (1 ≤ n, k ≤ 1012), where n is the number of students and k is the ratio between the number of certificates and the number of diplomas.

Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible. It's possible that there are no winners.

<?php

$inputLine = fgets(STDIN);

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

$n = (float) $input[0];

$k = (float) $input[1];

$pr = $n / 2.0;

$nParts = $k + 1;

$partSize = $pr / $nParts;

$dipF = $partSize;

$dip1 = ceil($dipF);

$gr1 = $dip1 * $k;

if ($gr1 + $dip1 <= $pr) {
    echo $dip1 . ' ' . $gr1 . ' ' . ($n - $dip1 - $gr1);
    exit;
}

$dip2 = floor($dipF);

$gr2 = $dip2 * $k;

echo $dip2 . ' ' . $gr2 . ' ' . ($n - $dip2 - $gr2);

<?php

$inputLine = fgets(STDIN);

echo $inputLine;


Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible.Please help Ciel to find this minimal sum.

The first line contains an integer n (2 ≤ n ≤ 100). Then the second line contains n integers: x1, x2, ..., xn (1 ≤ xi ≤ 100).

Output a single integer — the required minimal sum.

NoteIn the first example the optimal way is to do the assignment: x2 = x2 - x1.In the second example the optimal sequence of operations is: x3 = x3 - x2, x2 = x2 - x1.

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

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

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

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

<?php
error_reporting("off");
//389A: Fox and Number Game
$n = trim(fgets(STDIN)); //$n = 2;
$array = explode(" ", trim(fgets(STDIN))); //$array = explode(" ", "45 12 27 30 18");
while (true) {
	arsort($array);
	$nums = array_unique($array);
	rsort($nums);
	if (count($nums) == 1) {
		break;
	}
	$biggest = $nums[0];
	$second = $nums[1];
	$indexone = array_search($biggest, $array);
	$indextwo = array_search($second, $array);
	$array[$indexone] = $biggest - $second;
}
$sum = 0;
foreach ($array as $value) {
	$sum += $value;
}
echo $sum;
?>

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

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

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

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

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

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

for(;;) {
	rsort($array);
	if ($array[0] !== $array[1]) {
		$array[0] = $array[0] - $array[1];
	} else {
		echo array_sum($array);exit();
	}
}

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

$line = trim(fgets(STDIN));
$array = array_map('intval', explode(' ', $line));
echo 'working', PHP_EOL;
for(;;) {
	rsort($array);
	if ($array[0] !== $array[$count - 1] && $array[1] !== 0) {
		$array[0] = $array[0] - $array[1];
	} else {
		echo array_sum($array);exit();
	}
}


Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas.Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into n consecutive segments, each segment needs to be painted in one of the colours.Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them.

The first line contains a single positive integer n (1 ≤ n ≤ 100) — the length of the canvas. The second line contains a string s of n characters, the i-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one).

If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes). You can print each character in any case (upper or lower).

NoteFor the first example, there are exactly two different ways of colouring: CYCMY and CYMCY.For the second example, there are also exactly two different ways of colouring: CMCMY and CYCMY.For the third example, there are four ways of colouring: MCYCM, MCYCY, YCYCM, and YCYCY.For the fourth example, no matter how the unpainted segments are coloured, the existing magenta segments will prevent the painting from satisfying the requirements. The similar is true for the fifth example.


Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game. The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins. You have to calculate how many fights will happen and who will win the game, or state that game won't end.

First line contains a single integer n (2 ≤ n ≤ 10), the number of cards. Second line contains integer k1 (1 ≤ k1 ≤ n - 1), the number of the first soldier's cards. Then follow k1 integers that are the values on the first soldier's cards, from top to bottom of his stack. Third line contains integer k2 (k1 + k2 = n), the number of the second soldier's cards. Then follow k2 integers that are the values on the second soldier's cards, from top to bottom of his stack. All card values are different.

If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won. If the game won't end and will continue forever output  - 1.


There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.To play durak you need a pack of 36 cards. Each card has a suit ("S", "H", "D" and "C") and a rank (in the increasing order "6", "7", "8", "9", "T", "J", "Q", "K" and "A"). At the beginning of the game one suit is arbitrarily chosen as trump. The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.You are given the trump suit and two different cards. Determine whether the first one beats the second one or not.

The first line contains the tramp suit. It is "S", "H", "D" or "C". The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank ("6", "7", "8", "9", "T", "J", "Q", "K" and "A"), and the second one stands for the suit ("S", "H", "D" and "C").

Print "YES" (without the quotes) if the first cards beats the second one. Otherwise, print "NO" (also without the quotes).

<?
$root=trim(fgets(STDIN));
$k=explode(' ',trim(fgets(STDIN)));
$first=$k[0];
$second=$k[1];
function differ($a,$b){
    switch($a){
        case 'T': $a=10; break;
        case 'J': $a=11; break;
        case 'Q': $a=12; break;
        case 'K': $a=13; break;
        case 'A': $a=14; break;
    }
    switch($b){
        case 'T': $b=10; break;
        case 'J': $b=11; break;
        case 'Q': $b=12; break;
        case 'K': $b=13; break;
        case 'A': $b=14; break;
    }
    if($a>$b) return 1;
    else return 0;
}
if($first[1]==$root){
    if($second[1]==$root){
        if(differ($first[0],$second[0])) echo "YES";
            else echo "NO";
    }else{
        echo "YES";
    }
}else{
    if($second[1]==$root) echo "NO";
    else{
        if($first[1]==$second[1]){
            if(differ($first[0],$second[0])) echo "YES";
            else echo "NO";
        }else{
            echo "NO";
        }
    }
}
?>

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

$cards=array("6", "7", "8", "9", "T", "J", "Q", "K", "A");
$jok=trim($lines[0]);
list($first, $second)=explode(" ", trim($lines[1]));
$key_2=array_search($second{0}, $cards);    //10
$key_1=array_search($first{0}, $cards); //1
if($first{1}==$second{1})
    echo ($key_1>$key_2)?'YES':'NO';
else
    echo ($first{1}==$jok)?'YES':'NO';
?>

<?
$root=trim(fgets(STDIN));
$k=explode(' ',trim(fgets(STDIN)));
$first=$k[0];
$second=$k[1];
function differ($a,$b){
    switch($a){
        case 'T': $a=10; break;
        case 'J': $a=11; break;
        case 'Q': $a=12; break;
        case 'K': $a=13; break;
        case 'A': $a=14; break;
    }
    switch($b){
        case 'T': $a=10; break;
        case 'J': $a=11; break;
        case 'Q': $a=12; break;
        case 'K': $a=13; break;
        case 'A': $a=14; break;
    }
    if($a>$b) return 1;
}
if($first[1]==$root){
    if($second[1]==$root){
        if(differ($first[0],$second[0])) echo "YES";
            else echo "NO";
    }else{
        echo "YES";
    }
}else{
    if($second[1]==$root) echo "NO";
    else{
        if($first[1]==$second[1]){
            if(differ($first[0],$second[0])) echo "YES";
            else echo "NO";
        }else{
            echo "NO";
        }
    }
}
?>

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

$cards=array("6", "7", "8", "9", "T", "J", "Q", "K", "A");
$jok=trim($lines[0]);
list($first, $second)=explode(" ", trim($lines[1]));
$key_2=array_search($second{0}, $cards);
$key_1=array_search($first{0}, $cards);
echo (($first{1}==$second{1} and $key_1>$key_2) or $first{1}==$jok)?'YES':'NO';
?>


Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn only the multiplication table of decimals (and some students even learn it in the first grade). Help Petya make a multiplication table for numbers in the system of notations with the radix k.

The first line contains a single integer k (2 ≤ k ≤ 10) — the radix of the system.

Output the multiplication table for the system of notations with the radix k. The table must contain k - 1 rows and k - 1 columns. The element on the crossing of the i-th row and the j-th column is equal to the product of i and j in the system of notations with the radix k. Each line may have any number of spaces between the numbers (the extra spaces in the samples are put for clarity).


This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different.You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.You have to color all its characters one of the two colors (each character to exactly one color, the same letters can be colored the same or different colors, i.e. you can choose exactly one color for each index in $$$s$$$).After coloring, you can swap any two neighboring characters of the string that are colored different colors. You can perform such an operation arbitrary (possibly, zero) number of times.The goal is to make the string sorted, i.e. all characters should be in alphabetical order.Your task is to say if it is possible to color the given string so that after coloring it can become sorted by some sequence of swaps. Note that you have to restore only coloring, not the sequence of swaps.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the length of $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of exactly $$$n$$$ lowercase Latin letters.

If it is impossible to color the given string so that after coloring it can become sorted by some sequence of swaps, print "NO" (without quotes) in the first line. Otherwise, print "YES" in the first line and any correct coloring in the second line (the coloring is the string consisting of $$$n$$$ characters, the $$$i$$$-th character should be '0' if the $$$i$$$-th character is colored the first color and '1' otherwise).

<?php

namespace io {
	$input_file_content = file_get_contents("php://stdin");
	$input_buf = explode("\r\n", $input_file_content);
	unset($input_file_content);
}

namespace main {
	error_reporting(E_ALL);
	ini_set('display_errors', true);
	ini_set('html_errors', false);

	use function io\next_line as next_line;
	use function io\next_ as next;
	use function io\next_int as next_int;
	use function io\next_double as next_double;

	$n = next_int();
	$s = next_line();

	$a = [];
	$f = array_fill(0, 32, 0);
	for($i=0; $i<$n; $i++) {
		$j = ord($s[$i]) - ord('a');
		$a[] = max(array_slice($f, $j + 1)) + 1;
		$f[$j] = max($f[$j], $a[$i]);
	}

	$m = max($a);
	if($m <= 2) {
		for($i=0; $i<$n; $i++) $a[$i]--;
		printf("YES\n%s\n", implode("", $a));
	}
	else printf("NO");
}

namespace io {
	function next_line() {
		static $cnt = 0;
		global $input_buf;
		// while($input_buf[$cnt] == "") $cnt++;
		return $input_buf[$cnt++];
		// return trim($input_buf[$cnt++]);
	}
	function next_() {
		static $tk = [];
		static $tk_cnt = 0;
		if($tk_cnt == count($tk)) {
			$tk = explode(" ", next_line());
			$tk_cnt = 0;
		}
		return $tk[$tk_cnt++];
	}
	function next_int() {
		return (int)next_();
	}
	function next_double() {
		return (double)next_();
	}
}

?>

<?php

namespace io {
	$input_file_content = file_get_contents("php://stdin");
	$input_buf = explode("\r\n", $input_file_content);
	unset($input_file_content);
}

namespace main {
	error_reporting(E_ALL);
	ini_set('display_errors', true);
	ini_set('html_errors', false);

	use function io\next_line as next_line;
	use function io\next_ as next;
	use function io\next_int as next_int;
	use function io\next_double as next_double;

	$n = next_int();
	$s = next_line();

	$a = [];
	$f = array_fill(0, 32, 0);
	for($i=0; $i<$n; $i++) {
		$j = ord($s[$i]) - ord('a');
		$a[] = max(array_slice($f, $j + 1)) + 1;
		$f[$j] = max($f[$j], $a[$i]);
	}

	$m = max($a);
	if($m < 2) {
		for($i=0; $i<$n; $i++) $a[$i]--;
		printf("YES\n%s\n", implode("", $a));
	}
	else printf("NO");
}

namespace io {
	function next_line() {
		static $cnt = 0;
		global $input_buf;
		// while($input_buf[$cnt] == "") $cnt++;
		return $input_buf[$cnt++];
		// return trim($input_buf[$cnt++]);
	}
	function next_() {
		static $tk = [];
		static $tk_cnt = 0;
		if($tk_cnt == count($tk)) {
			$tk = explode(" ", next_line());
			$tk_cnt = 0;
		}
		return $tk[$tk_cnt++];
	}
	function next_int() {
		return (int)next_();
	}
	function next_double() {
		return (double)next_();
	}
}

?>


Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate.  Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10B is true. In our case A is between 0 and 9 and B is non-negative.Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.

The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10100, 0 ≤ b ≤ 100) — the scientific notation of the desired distance value. a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.

Print the only real number x (the desired distance value) in the only line in its decimal notation.  Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes.  Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).

<?php
$a = str_split(trim(fgets(STDIN)));
for($x = 0; $x < count($a); $x++)
{
     if($a[$x] == ".")
     {
          $b = array_slice($a, 0, $x);
          $c = array_slice($a, $x + 1);
          break;
     }
}
for($x = 0; $x < count($c); $x++)
{
     if($c[$x] == "e")
     {
          $d = array_slice($c, 0, $x);
          $e = array_slice($c, $x + 1);
     }
}
$f = implode($e);
if(count($d) < $f)
{
     $g = $f - count($d);
     for($x = 1; $x <= $g; $x++)
     {
          array_push($d, 0);
     }
     $h = array_merge($b, $d);
     $i = count($h);
     for($x = 0; $x < $i; $x++)
     {
          if($h[$x] == 0)
          {
               unset($h[$x]);
          }
          else
          {
               break;
          }
     }
     print implode($h);
}
elseif(count($d) == $f)
{
     $g = array_merge($b, $d);
     $h = count($g);
     for($x = 0; $x < $h; $x++)
     {
          if($g[$x] == 0)
          {
               unset($g[$x]);
          }
          else
          {
               break;
          }
     }
     print implode($g);
}
elseif(count($d) > $f)
{
     $g = array_slice($d, 0, $f);
     $h = array_slice($d, $f);
     $i = array_merge($b, $g);
     $h2 = array_unique($h);
     sort($h2);
     if((count($h2) == 1) && ($h2[0] == 0))
     {
          $j = $i;
          if(count($j) == 1)
          {
               print implode($j);
          }
          else
          {
               $k = count($j);
               for($x = 0; $x < $k; $x++)
               {
                    if($j[$x] == 0)
                    {
                         unset($j[$x]);
                    }
                    else
                    {
                         break;
                    }
               }
               print implode($j);
          }
     }
     else
     {
          array_push($i, ".");
          $j = array_merge($i, $h);
          if($j[1] == ".")
          {
               print implode($j);
          }
          else
          {
               $k = count($j);
               for($x = 0; $x < $k; $x++)
               {
                    if($j[$x] == 0)
                    {
                         unset($j[$x]);
                    }
                    else
                    {
                         break;
                    }
               }
               print implode($j);
          }
     }
}
?>

<?php

$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

fscanf($fr, "%s", $str);

$a = substr($str, 0, 1);

$charPosition = strpos($str, 'e');

$d = substr($str, 2, $charPosition - 2);

$b =  substr($str, $charPosition + 1);

if (($dLen = strlen($d)) < $b) {
	$d .= str_repeat('0', $b - $dLen);
}

if ($a == '0' && $d == '0' && $b == '0') {
	$realNumber = 0;
} elseif ($b == '0') {
	$realNumber = $a . '.' . $d;
	$realNumber = removeLeadingZeroes($realNumber);
} else {
	$realNumber = $a . substr($d, 0, $b);

	if ($dLen > $b) {
		$realNumber .= '.';
	}

	$realNumber .= substr($d, $b);

	$realNumber = removeLeadingZeroes($realNumber);
}

function removeLeadingZeroes($realNumber)
{
	if (! strpos($realNumber, '.')) {
		return $realNumber;
	}

	for ($i = strlen($realNumber); $i> 0; $i--) {
		if ($realNumber[$i-1] != 0) {
			return $realNumber;
		}

		$realNumber = substr($realNumber, 0, $i-1);
	}

	return $realNumber;
}

fprintf($fw, $realNumber);

fclose($fr);
fclose($fw);

<?php
$a = str_split(trim(fgets(STDIN)));
for($x = 0; $x < count($a); $x++)
{
     if($a[$x] == ".")
     {
          $b = array_slice($a, 0, $x);
          $c = array_slice($a, $x + 1);
          break;
     }
}
for($x = 0; $x < count($c); $x++)
{
     if($c[$x] == "e")
     {
          $d = array_slice($c, 0, $x);
          $e = array_slice($c, $x + 1);
     }
}
$f = implode($e);
if(implode($a) == "0.0e0")
{
     print "0";
}
elseif(count($d) < $f)
{
     $g = $f - count($d);
     for($x = 1; $x <= $g; $x++)
     {
          array_push($d, 0);
     }
     $h = array_merge($b, $d);
     $i = count($h);
     for($x = 0; $x < $i; $x++)
     {
          if($h[$x] == 0)
          {
               unset($h[$x]);
          }
          else
          {
               break;
          }
     }
     print implode($h);
}
elseif(count($d) == $f)
{
     $g = array_merge($b, $d);
     $h = count($g);
     for($x = 0; $x < $h; $x++)
     {
          if($g[$x] == 0)
          {
               unset($g[$x]);
          }
          else
          {
               break;
          }
     }
     print implode($g);
}
elseif(count($d) > $f)
{
     $g = array_slice($d, 0, $f);
     $h = array_slice($d, $f);
     $i = array_merge($b, $g);
     array_push($i, ".");
     $j = array_merge($i, $h);
     if($j[1] == ".")
     {
          print implode($j);
     }
     else
     {
          $k = count($j);
          for($x = 0; $x < $k; $x++)
          {
               if($j[$x] == 0)
               {
                    unset($j[$x]);
               }
               else
               {
                    break;
               }
          }
          print implode($j);
     }
}
?>

<?php
$a = str_split(trim(fgets(STDIN)));
for($x = 0; $x < count($a); $x++)
{
     if($a[$x] == ".")
     {
          $b = array_slice($a, 0, $x);
          $c = array_slice($a, $x + 1);
          break;
     }
}
for($x = 0; $x < count($c); $x++)
{
     if($c[$x] == "e")
     {
          $d = array_slice($c, 0, $x);
          $e = array_slice($c, $x + 1);
     }
}
$f = implode($e);
if(count($d) < $f)
{
     $g = $f - count($d);
     for($x = 1; $x <= $g; $x++)
     {
          array_push($d, 0);
     }
     $h = array_merge($b, $d);
     $i = count($h);
     for($x = 0; $x < $i; $x++)
     {
          if($h[$x] == 0)
          {
               unset($h[$x]);
          }
          else
          {
               break;
          }
     }
     print implode($h);
}
elseif(count($d) == $f)
{
     $g = array_merge($b, $d);
     $h = count($g);
     for($x = 0; $x < $h; $x++)
     {
          if($g[$x] == 0)
          {
               unset($g[$x]);
          }
          else
          {
               break;
          }
     }
     print implode($g);
}
elseif(count($d) > $f)
{
     $g = array_slice($d, 0, $f);
     $h = array_slice($d, $f);
     $i = array_merge($b, $g);
     array_push($i, ".");
     $j = array_merge($i, $h);
     if($j[1] == ".")
     {
          print implode($j);
     }
     else
     {
          $k = count($j);
          for($x = 0; $x < $k; $x++)
          {
               if($j[$x] == 0)
               {
                    unset($j[$x]);
               }
               else
               {
                    break;
               }
          }
          print implode($j);
     }
}
?>

<?php

$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

fscanf($fr, "%s", $str);

$charPosition = strpos($str, 'e');

$number = substr($str, 0, $charPosition);

$exp =  substr($str, $charPosition + 1);

$realNumber = $number * pow(10, $exp);

fprintf($fw, $realNumber);

fclose($fr);
fclose($fw);

<?php

$fr = fopen("php://stdin", "r");
$fw = fopen("php://stdout", "w");

fscanf($fr, "%s", $str);

$a = substr($str, 0, 1);

$charPosition = strpos($str, 'e');

$d = substr($str, 2, $charPosition - 2);

$b =  substr($str, $charPosition + 1);

if ($b == '0') {
	$realNumber = $a . '.' . $d;
	$realNumber = removeLeadingZeroes($realNumber);
} else {
	$realNumber = $a . substr($d, 0, $b);
	$realNumber .= '.';
	$realNumber .= substr($d, $b);

	$realNumber = removeLeadingZeroes($realNumber);
}

function removeLeadingZeroes($realNumber)
{
	if (! strpos($realNumber, '.')) {
		return $realNumber;
	}

	for ($i = strlen($realNumber); $i> 0; $i--) {
		if ($realNumber[$i-1] != 0) {
			return $realNumber;
		}

		$realNumber = substr($realNumber, 0, $i-1);
	}

	return $realNumber;
}

fprintf($fw, $realNumber);

fclose($fr);
fclose($fw);


During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to n, at that the person in the position number 1 is served first. Then, if at time x a boy stands on the i-th position and a girl stands on the (i + 1)-th position, then at time x + 1 the i-th position will have a girl and the (i + 1)-th position will have a boy. The time is given in seconds.You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after t seconds.

The first line contains two integers n and t (1 ≤ n, t ≤ 50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.  The next line contains string s, which represents the schoolchildren's initial arrangement. If the i-th position in the queue contains a boy, then the i-th character of string s equals "B", otherwise the i-th character equals "G".

Print string a, which describes the arrangement after t seconds. If the i-th position has a boy after the needed time, then the i-th character a must equal "B", otherwise it must equal "G".

<?php
$input = trim(fgets(STDIN));
$string = trim(fgets(STDIN));

$arr_input = explode(" ",$input);

$jumlah = $arr_input[0];
$detik = $arr_input[1];

$arr_string = str_split($string);
for($x=0;$x<$detik;$x++)
{
	for($i=0;$i<(count($arr_string)-1);$i++)
	{
		$j = $i + 1;
		if($arr_string[$i] == "B" && $arr_string[$j] == "G")
		{
			$arr_string[$j] = "B";
			$arr_string[$i] = "G";
			$i++;
		}
	}
}
echo implode($arr_string);
?>

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

function put($r)
{
    echo $r;
}

$COUNT = 0;
foreach (input() as $line) {
    if ($COUNT == 0) {
        list($n, $s) = explode(' ', $line);
        ++$COUNT;
        continue;
    }
    $q = $line;

    for($i = 0; $i<$s; ++$i) {
        for($j = strlen($q)-1; $j>0; --$j) {
            if ( $q[$j] == 'G' && $q[$j-1] == 'B') {
                $z = $q[$j-1];
                $q[$j-1] = $q[$j];
                $q[$j] = $z;
                --$j;

            }

        }
    }

    put($q);

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

}

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

$COUNT = 0;
foreach (input() as $line) {
    if ($COUNT == 0) {
        list($n, $s) = explode(' ', $line);
        ++$COUNT;
        continue;
    }
    $q = $line;

    for($i = 0; $i<$s; ++$i) {
        for($j = strlen($q)-1; $j>0; --$j) {
            if ( $q[$j] == 'G' && $q[$j-1] == 'B') {
                $z = $q[$j-1];
                $q[$j-1] = $q[$j];
                $q[$j] = $z;
                --$j;
            }

        }
    }

    echo $q;

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

}

<?php

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

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

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

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

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

for ($i = 0; $i < $t; $i++) {
    for ($j = 0; $j < $n - 1; $j++) {
        if ($s[$j + 1] === 'G' && $s[$j] === 'B') {
            $s[$j] = 'G';
            $s[$j + 1] = 'B';
            $j++;
        }
    }
}

fwrite($output, $s);

<?php

$nt = array_map('intval', explode(' ', readline()));
$queue = str_split(readline());
$t = 0;
while($t < $nt[1]){
    $i = 0;
    while($i < $nt[0] -1){
        if($queue[$i] == 'B' && $queue[$i+1] == 'G'){
            $queue[$i] = 'G';
            $queue[$i+1] = 'B';
            $i = $i +2;
        }else{
            $i++;
        }
    }
    $t ++;
}

echo implode('', $queue);

<?php
$n = explode(" ",trim(fgets(STDIN)));
$line = str_split(trim(fgets(STDIN)),1);
for ($i=0;$i<$n[1];$i++)
{
    for ($j=1;$j<$n[0];$j++)
    {
        if (($line[$j]=="G")&&($line[$j])!=$line[$j-1])
        {
            $t=$line[$j];$line[$j]=$line[$j-1];$line[$j-1]=$t;$j++;
        }
    }
}
foreach ($line as $char)echo $char;

<?php
$n=trim(fgets(STDIN));
$n=explode(' ',$n);
$input=trim(fgets(STDIN));
$array=str_split($input);
$a=$n[1];
while($a>=1){
foreach ($array as $key => $value) {
   if(key_exists($key+1,$array)){
      if($value == 'B' and $array[$key+1] == 'G'){
      $x=$array[$key];
      $array[$key]=$array[$key+1];
      $array[$key+1]=$x;
      }
   }
}
$a--;
}
echo join('',$array);

<?php

$f = fopen('php://stdin', 'r');
//$f = fopen('5.txt', 'r');
$a = explode(" ",trim(fgets($f)));
$och = trim(fgets($f));

$t = $a[1];
$n = $a[0];

for($i=0;$i<$t;$i++){
    $och = str_replace("BG","GB",$och);
}

echo $och;

<?php
// 266B 	Очередь в школе

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

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

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

for ($i=1; $i <= $t; $i++) {
    for ($j=0; $j < $n; $j++) {
        if (($arr[$j] == 'B') and ($arr[$j+1]) == 'G') {
            $arr[$j] = 'G';
            $arr[$j+1] = 'B';
            $j++;
         }
    }
}

$out = '';
foreach ($arr as $key => $value) {
    $out .= $value;
}

echo $out;

?>

<?php

//  In the name of Allah, the most Gracious, the most Merciful

//  Copyright(c) 2009-2013, all rights reserved.
//  written by ZHUMAZHANOV ADLET.

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

for ($ti = 0; $ti < $t; $ti ++) {
	$length = strlen($q);
	for ($i = 0; $i < $length; $i ++) {
		if ($q[$i] == "G") continue;
		if ($i + 1 < $length && $q[$i+1] == "G") {
			$buf = $q[$i];
			$q[$i] = $q[$i+1];
			$q[$i+1] = $buf;
			$i ++;
		}
	}
}

printf("%s", $q);

?>

<?php

/**
 * @author Sunwarul
 */

list($n, $t) = explode(' ', fgets(STDIN));
$str         = trim(fgets(STDIN));
$arr         = str_split($str);
$t           = intval($t);

while ($t--) {
    for ($i = 1; $i < count($arr); ++$i) {
        if ($arr[$i] == 'G' && $arr[$i - 1] == 'B') {
            $arr[$i]     = 'B';
            $arr[$i - 1] = 'G';
            ++$i;
        }
    }
}

$res = implode('', $arr);
echo $res."\n";

<?php
//266B: Queue at the School
list($n, $t) = explode(" ", trim(fgets(STDIN))); //$n = 4; $t = 1;
$queue = trim(fgets(STDIN)); //$queue = "GGGB";
for ($i = 0; $i < $t; $i++) {
    $explode = explode("BG", $queue);
    $queue = implode("GB", $explode);
}
echo $queue;
?>

<?php
	list($n,$t) = explode(' ',trim(fgets(STDIN)));
	$var = trim(fgets(STDIN));
	for ($x=0;$x<$t;$x++) {
		$var = str_split($var);
		for($y=0;$y<count($var)-1;$y++) {
			if ($var[$y] == 'B' && $var[$y+1] == 'G') {
				$var[$y] = 'X';
				$var[$y+1] = 'Y';
			}
		}
		$var = implode('',$var);
		$var = str_replace('XY','GB',$var);
	}
	echo $var;

<?php
$input = trim(fgets($STDIN));
$string = trim(fgets($STDIN));

$arr_input = explode(" ",$input);

$jumlah = $arr_input[0];
$detik = $arr_input[1];

$arr_string = str_split($string);
for($x=0;$x<$detik;$x++)
{
	for($i=0;$i<(count($arr_string)-1);$i++)
	{
		$j = $i + 1;
		if($arr_string[$i] == "B" && $arr_string[$j] == "G")
		{
			$arr_string[$j] = "B";
			$arr_string[$i] = "G";
			$i++;
		}
	}
}
echo implode($arr_string);
?>

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

function put($r)
{
    echo $r . PHP_EOL;
}

$COUNT = 0;
foreach (input() as $line) {
    if ($COUNT == 0) {
        list($n, $s) = explode(' ', $line);
        ++$COUNT;
        continue;
    }
    $q = $line;

    for($i = 0; $i<$s; ++$i) {
        for($j = strlen($q)-1; $j>0; --$j) {
            if ( $q[$j] == 'G' && $q[$j-1] == 'B') {
                $z = $q[$j-1];
                $q[$j-1] = $q[$j];
                $q[$j] = $z;
            }
        }
    }

    put($q);

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

}

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

$arr=str_split($s);
$n=$n-1;
$temp1="";
$temp2="";
$j=0;
$baru;

while ( $j < $t) {
	while ($n >= 0) {
		$temp1=$arr[$n];
		$m=$n-1;
		$temp2=$arr[$m];
		if ($temp2 != $temp1) {
			$arr[$m] = $temp1;
			$arr[$n] = $temp2;
		}
		$n--;
	}
	$j++;
}
echo $arr;
?>

<?php
	list($n,$t) = explode(' ',trim(fgets(STDIN)));
	$var = str_split(trim(fgets(STDIN)));
	for ($x=0;$x<$t;$x++) {
		for($y=0;$y<count($var);$y++) {
			if ($var[$y] == 'B' && $var[$y+1] == 'G') {
				$var[$y] = 'G';
				$var[$y+1] = 'B';
			}
		}
	}
	echo implode('',$var);

<?php
	list($n,$t) = explode(' ',trim(fgets(STDIN)));
	$var = str_split(trim(fgets(STDIN)));
	for ($x=0;$x<$t;$x++) {
		for($y=0;$y<count($var);$y++) {
			if ($var[$y] == 'B' && $var[$y+1] == 'G') {
				$var[$y] = 'X';
				$var[$y+1] = 'X';
			}
		}
	}
	$var = implode('',$var);
	$var = str_replace('XX','GB',$var);
	echo $var;

<?php
	list($n,$t) = explode(' ',trim(fgets(STDIN)));
	$var = str_split(trim(fgets(STDIN)));
	for ($x=0;$x<$t;$x++) {
		for($y=count($var)-1;$y>0;$y--) {
			if ($var[$y] == 'G' && $var[$y-1] == 'B') {
				$var[$y] = 'B';
				$var[$y-1] = 'G';
			}
		}
	}
	echo implode('',$var);

<?php
	list($n,$t) = explode(fgets(STDIN));
	$var = str_split(fgets(STDIN));
	for ($x=0;$x<$t;$x++) {
		for($y=count($var)-1;$y>0;$y--) {
			if ($var[$y] == 'G' && $var[$y-1] == 'B') {
				$var[$y] = 'B';
				$var[$y-1] = 'G';
			}
		}
	}
	echo implode('',$var);