Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city A departs every a minutes and arrives to the city B in a ta minutes, and a bus from the city B departs every b minutes and arrives to the city A in a tb minutes.The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish.You know the time when Simion departed from the city A to the city B. Calculate the number of buses Simion will meet to be sure in his counting.

The first line contains two integers a, ta (1 ≤ a, ta ≤ 120) — the frequency of the buses from the city A to the city B and the travel time. Both values are given in minutes. The second line contains two integers b, tb (1 ≤ b, tb ≤ 120) — the frequency of the buses from the city B to the city A and the travel time. Both values are given in minutes. The last line contains the departure time of Simion from the city A in the format hh:mm. It is guaranteed that there are a bus from the city A at that time. Note that the hours and the minutes are given with exactly two digits.

Print the only integer z — the number of buses Simion will meet on the way. Note that you should not count the encounters in cities A and B.

NoteIn the first example Simion departs form the city A at 05:20 AM and arrives to the city B at 05:50 AM. He will meet the first 5 buses from the city B that departed in the period [05:00 AM - 05:40 AM]. Also Simion will meet a bus in the city B at 05:50 AM, but he will not count it.Also note that the first encounter will be between 05:26 AM and 05:27 AM (if we suggest that the buses are go with the sustained speed).

<?php

function debug($msg)
{
    $debug = false;
    // $debug = true;

    if ($debug)
    {
        echo $msg . PHP_EOL;
    }
}

$ts = 5 * 60;
$te = 24 * 60;

define ('FREQ', 0);
define ('DURING', 1);

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 1,
//     DURING => 1
//     );
// $tb_arr = array(
//     FREQ   => 1,
//     DURING => 1
//     );
// $ta_start = 23 * 60 + 59;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);

    debug(" check between time $tb_start and $ta_end. Initial count: $count" );

    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $count--;
    }

    return intval($count);
}

// get the most recent meetable bus start time
function get_start($start, $t_arr)
{
    global $ts;

    if ($start - $t_arr[DURING] > $ts)
    {
        $start_time = $start - $t_arr[DURING];

        if ( (($start_time - $ts) % $t_arr[FREQ]) == 0)
        {
            return $start_time;
        }
        else
        {
            return $ts + ceil(($start_time - $ts) / $t_arr[FREQ]) * $t_arr[FREQ];
        }
    }
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        debug("meet in station at time: $t, freq: $freq");
        return true;
    }
    else
        return false;
}

<?php

function debug($msg)
{
    $debug = false;
    // $debug = true;

    if ($debug)
    {
        echo $msg . PHP_EOL;
    }
}

$ts = 5 * 60;
$te = 23 * 60 + 59;

define ('FREQ', 0);
define ('DURING', 1);

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 1,
//     DURING => 1
//     );
// $tb_arr = array(
//     FREQ   => 1,
//     DURING => 1
//     );
// $ta_start = 23 * 60 + 59;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);

    debug(" check between time $tb_start and $ta_end. Initial count: $count" );

    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $count--;
    }

    return intval($count);
}

// get the most recent meetable bus start time
function get_start($start, $t_arr)
{
    global $ts;

    if ($start - $t_arr[DURING] > $ts)
    {
        $start_time = $start - $t_arr[DURING];

        if ( (($start_time - $ts) % $t_arr[FREQ]) == 0)
        {
            return $start_time;
        }
        else
        {
            return $ts + ceil(($start_time - $ts) / $t_arr[FREQ]) * $t_arr[FREQ];
        }
    }
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during <= $te)
        return $start + $during;
    else
        return $te + 1;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        debug("meet in station at time: $t, freq: $freq");
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

// freq, travel_time
$ta_arr = array(
    'freq'   => 60,
    'during' => 120
    );
$tb_arr = array(
    'freq'   => 24,
    'during' => 100
    );
$ta_start = 13 * 60 + 0;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr['during']);

    $ta_end = get_end($ta_start, $ta_arr['during']);

    $count = ceil(($ta_end - $tb_start) / $tb_arr['freq']);
    if ( (($ta_end - $tb_start) % $tb_arr['freq']) == 0)
        $count++;

    echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    if (is_station($ta_start-$tb_arr['during'], $tb_arr['freq']))
        $count--;

    if (is_station($ta_start+$ta_arr['during'], $tb_arr['freq']))
        $count--;

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

define ('FREQ', 0);
define ('DURING', 1);

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 30,
//     DURING => 60
//     );
// $tb_arr = array(
//     FREQ   => 60,
//     DURING => 60
//     );
// $ta_start = 22 * 60 + 30;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr[DURING]);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = intval(($ta_end - $tb_start) / $tb_arr[FREQ]);

    // echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    $b_station = false;
    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    // meet at arrived station
    if (is_station($ta_start+$ta_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    if ( (($ta_end - $tb_start) % $tb_arr[FREQ]) == 0 && $b_station == true)
    {
        // echo 'add 1' . PHP_EOL;
        $count++;
    }

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        // echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

define ('FREQ', 0);
define ('DURING', 1);

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 30,
//     DURING => 60
//     );
// $tb_arr = array(
//     FREQ   => 60,
//     DURING => 60
//     );
// $ta_start = 22 * 60 + 30;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr[DURING]);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);

    // echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    $b_station = false;
    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    // meet at arrived station
    if (is_station($ta_start+$ta_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    if ( (($ta_end - $tb_start) % $tb_arr[FREQ]) == 0 && $b_station == true)
    {
        // echo 'add 1' . PHP_EOL;
        $count++;
    }

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        // echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}

<?php

function debug($msg)
{
    $debug = false;

    if ($debug)
    {
        echo $msg . PHP_EOL;
    }
}

$ts = 5 * 60;
$te = 23 * 60 + 59;

define ('FREQ', 0);
define ('DURING', 1);

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 30,
//     DURING => 60
//     );
// $tb_arr = array(
//     FREQ   => 60,
//     DURING => 60
//     );
// $ta_start = 22 * 60 + 30;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);

    debug(" check between time $tb_start and $ta_end. Initial count: $count" );

    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $count--;
    }

    return intval($count);
}

// get the most recent meetable bus start time
function get_start($start, $t_arr)
{
    global $ts;

    if ($start - $t_arr[DURING] > $ts)
    {
        $start_time = $start - $t_arr[DURING];

        if ( (($start_time - $ts) % $t_arr[FREQ]) == 0)
        {
            return $start_time;
        }
        else
        {
            return $ts + ceil(($start_time - $ts) / $t_arr[FREQ]) * $t_arr[FREQ];
        }
    }
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        debug("meet in station at time: $t, freq: $freq");
        return true;
    }
    else
        return false;
}

<?php

function debug($msg)
{
    $debug = false;

    if ($debug)
    {
        echo $msg . PHP_EOL;
    }
}

$ts = 5 * 60;
$te = 23 * 60 + 59;

define ('FREQ', 0);
define ('DURING', 1);

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 30,
//     DURING => 60
//     );
// $tb_arr = array(
//     FREQ   => 60,
//     DURING => 60
//     );
// $ta_start = 22 * 60 + 30;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);

    debug(" check between time $tb_start and $ta_end. Initial count: $count" );

    $b_station = false;
    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    // // meet at arrived station
    // if (is_station($ta_start+$ta_arr[DURING], $tb_arr[FREQ]))
    // {
    //     $b_station = true;
    //     $count--;
    // }

    return $count;
}

// get the most recent meetable bus start time
function get_start($start, $t_arr)
{
    global $ts;

    if ($start - $t_arr[DURING] > $ts)
    {
        $start_time = $start - $t_arr[DURING];

        if ( (($start_time - $ts) % $t_arr[FREQ]) == 0)
        {
            return $start_time;
        }
        else
        {
            return $ts + ceil(($start_time - $ts) / $t_arr[FREQ]) * $t_arr[FREQ];
        }
    }
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        debug("meet in station at time: $t, freq: $freq");
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

// freq, travel_time
$ta_arr = array(
    'freq'   => 60,
    'during' => 120
    );
$tb_arr = array(
    'freq'   => 24,
    'during' => 100
    );
$ta_start = 13 * 60 + 0;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr['during']);

    $ta_end = get_end($ta_start, $ta_arr['during']);

    $count = ceil(($ta_end - $tb_start) / $tb_arr['freq']);
    if ( (($ta_end - $tb_start) % $tb_arr['freq']) == 0)
        $count++;

    // echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    if (is_station($ta_start-$tb_arr['during'], $tb_arr['freq']))
        $count--;

    if (is_station($ta_start+$ta_arr['during'], $tb_arr['freq']))
        $count--;

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        // echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

define ('FREQ', 0);
define ('DURING', 1);
// freq, travel_time
// $ta_arr = array(
//     FREQ   => 60,
//     DURING => 120
//     );
// $tb_arr = array(
//     FREQ   => 24,
//     DURING => 100
//     );
// $ta_start = 13 * 60 + 0;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr[DURING]);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = ceil(($ta_end - $tb_start) / $tb_arr[FREQ]);
    if ( (($ta_end - $tb_start) % $tb_arr[FREQ]) == 0)
        $count++;

    // echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
        $count--;

    if (is_station($ta_start+$ta_arr[DURING], $tb_arr[FREQ]))
        $count--;

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        // echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}

<?php

$ts = 5 * 60;
$te = 23 * 60 + 59;

$fh = fopen('php://stdin','r') or die('no input');
if ($s = fgets($fh,100) ) {
    $ta_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $tb_arr = explode(' ', $s);
}

if ($s = fgets($fh,100) ) {
    $ta_start_arr = explode(':', $s);
    $ta_start = $ta_start_arr[0] * 60 + $ta_start_arr[1];
}

define ('FREQ', 0);
define ('DURING', 1);

// freq, travel_time

// $ta_arr = array(
//     FREQ   => 30,
//     DURING => 60
//     );
// $tb_arr = array(
//     FREQ   => 60,
//     DURING => 60
//     );
// $ta_start = 22 * 60 + 30;

echo get_count($ta_arr, $tb_arr, $ta_start) . PHP_EOL;

function get_count($ta_arr, $tb_arr, $ta_start)
{
    $tb_start = get_start($ta_start, $tb_arr[DURING]);

    $ta_end = get_end($ta_start, $ta_arr[DURING]);

    $count = intval(($ta_end - $tb_start) / $tb_arr[FREQ]);

    // echo " check between time $tb_start and $ta_end. Initial count: $count" . PHP_EOL;

    $b_station = false;
    // meet at start staion
    if (is_station($ta_start-$tb_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    // meet at arrived station
    if (is_station($ta_start+$ta_arr[DURING], $tb_arr[FREQ]))
    {
        $b_station = true;
        $count--;
    }

    if ( (($ta_end - $tb_start) % $tb_arr[FREQ]) == 0)
    {
        // echo 'add 1' . PHP_EOL;
        $count++;
    }

    return $count;
}

function get_start($start, $during)
{
    global $ts;

    if ($start - $during > $ts)
        return $start - $during;
    else
        return $ts;
}

function get_end($start, $during)
{
    global $te;

    if ($start + $during < $te)
        return $start + $during;
    else
        return $te;
}

function is_station($t, $freq)
{
    global $ts, $te;

    if ($t<$ts || $t > $te)
        return false;

    if ((($t - $ts) % $freq) == 0)
    {
        // echo "meet one at station. time: $t, freq: $freq" . PHP_EOL;
        return true;
    }
    else
        return false;
}


Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take a picture of any axis-parallel rectangle in the orchestra. Count the number of possible pictures that Paul can take.Two pictures are considered to be different if the coordinates of corresponding rectangles are different.

The first line of input contains four space-separated integers r, c, n, k (1 ≤ r, c, n ≤ 3000, 1 ≤ k ≤ min(n, 10)) — the number of rows and columns of the string section, the total number of violas, and the minimum number of violas Paul would like in his photograph, respectively. The next n lines each contain two integers xi and yi (1 ≤ xi ≤ r, 1 ≤ yi ≤ c): the position of the i-th viola. It is guaranteed that no location appears more than once in the input.

Print a single integer — the number of photographs Paul can take which include at least k violas.

NoteWe will use '*' to denote violinists and '#' to denote violists.In the first sample, the orchestra looks as follows: *#** Paul can take a photograph of just the viola, the 1 × 2 column containing the viola, the 2 × 1 row containing the viola, or the entire string section, for 4 pictures total.In the second sample, the orchestra looks as follows: #**##* Paul must take a photograph of the entire section.In the third sample, the orchestra looks the same as in the second sample.


Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant.In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not.Help Vitya find out if a word $$$s$$$ is Berlanese.

The first line of the input contains the string $$$s$$$ consisting of $$$|s|$$$ ($$$1\leq |s|\leq 100$$$) lowercase Latin letters.

Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower).

NoteIn the first and second samples, a vowel goes after each consonant except "n", so the word is Berlanese.In the third sample, the consonant "c" goes after the consonant "r", and the consonant "s" stands on the end, so the word is not Berlanese.

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

$group = array("a", "i", "u", "e", "o");
fscanf(STDIN, "%s", $S);
$arrayS = str_split($S);
$countS = count($arrayS);

$answer = "YES";
for ($i = 0; $i < $countS; $i++) {
	if ($arrayS[$i] == "n") {
		continue;
	}

	if (in_array($arrayS[$i], $group) === false) {
		if (in_array($arrayS[$i + 1], $group) === false) {
			$answer = "NO";
		}
	}
}

echo $answer;

<?php
$str=trim(fgets(STDIN));
$len=strlen($str);
$vowel='aeioun';
$decision=false;
if (substr_count($vowel,$str[$len-1])==1)
{
	for ($i=0; $i <$len ; $i++)
	{
		if (substr_count($vowel,$str[$i])=='0'&&(substr_count($vowel,$str[$i+1])=='0'||$str[$i+1]=='n'))
		{
			$decision=false;
			break;
		}
		$decision=true;
	}
	//$decision=true;
}
echo $decision==true?'YES':'NO';

<?php

$a = trim(fgets(STDIN));
//$a = "codeforces";

$input = $a;
$input = str_split($input);
$ok = true;

for($i = 0; $i < sizeof($input); $i++){
    $value = $input[$i];
     if(!isVowel($value) && $value != 'n'){
         //if not n or vowel, have to check the next char
         if($i + 1 >= sizeof($input)){
             $ok = false;
             break;
         }else if(!isVowel($input[$i+1])){
             $ok = false;
             break;
         }
     }
}

echo $ok ? 'YES' : 'NO';

function isVowel($character){
    return $character == 'a'
    || $character == 'i'
    || $character == 'u'
    || $character == 'e'
    || $character == 'o';
}
?>

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

$group1 = array("a", "i", "u", "e", "o");
$group2 = array("a", "i", "u", "e", "o", "n");
fscanf(STDIN, "%s", $S);
$arrayS = str_split($S);
$countS = count($arrayS);

$answer = "YES";
for ($i = 0; $i < $countS; $i++) {
	if (in_array($arrayS[$i], $group2) === false) {
		if (in_array($arrayS[$i + 1], $group2) === false) {
			$answer = "NO";
		}
	}
}

echo $answer;

<?php
$str=trim(fgets(STDIN));
$len=strlen($str);
$vowel='aeioun';
$decision=false;
if (substr_count($vowel,$str[$len-1])==1)
{
	for ($i=0; $i <$len ; $i++)
	{
		if (substr_count($vowel,$str[$i])=='0'&&substr_count($vowel,$str[$i+1])=='0')
		{
			$decision=false;
			break;
		}
		$decision=true;
	}
	//$decision=true;
}
echo $decision==true?'YES':'NO';


A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are regular bracket sequences; "))" and ")((" are bracket sequences (but not regular ones), and "(a)" and "(1)+(1)" are not bracket sequences at all.You have a number of strings; each string is a bracket sequence of length $$$2$$$. So, overall you have $$$cnt_1$$$ strings "((", $$$cnt_2$$$ strings "()", $$$cnt_3$$$ strings ")(" and $$$cnt_4$$$ strings "))". You want to write all these strings in some order, one after another; after that, you will get a long bracket sequence of length $$$2(cnt_1 + cnt_2 + cnt_3 + cnt_4)$$$. You wonder: is it possible to choose some order of the strings you have such that you will get a regular bracket sequence? Note that you may not remove any characters or strings, and you may not add anything either.

The input consists of four lines, $$$i$$$-th of them contains one integer $$$cnt_i$$$ ($$$0 \le cnt_i \le 10^9$$$).

Print one integer: $$$1$$$ if it is possible to form a regular bracket sequence by choosing the correct order of the given strings, $$$0$$$ otherwise.

NoteIn the first example it is possible to construct a string "(())()(()((()()()())))", which is a regular bracket sequence.In the second example it is possible to construct a string "", which is a regular bracket sequence.

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

<?php

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

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

?>

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

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


Vasya likes to solve equations. Today he wants to solve $$$(x~\mathrm{div}~k) \cdot (x \bmod k) = n$$$, where $$$\mathrm{div}$$$ and $$$\mathrm{mod}$$$ stand for integer division and modulo operations (refer to the Notes below for exact definition). In this equation, $$$k$$$ and $$$n$$$ are positive integer parameters, and $$$x$$$ is a positive integer unknown. If there are several solutions, Vasya wants to find the smallest possible $$$x$$$. Can you help him?

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^6$$$, $$$2 \leq k \leq 1000$$$).

Print a single integer $$$x$$$ — the smallest positive integer solution to $$$(x~\mathrm{div}~k) \cdot (x \bmod k) = n$$$. It is guaranteed that this equation has at least one positive integer solution.

NoteThe result of integer division $$$a~\mathrm{div}~b$$$ is equal to the largest integer $$$c$$$ such that $$$b \cdot c \leq a$$$. $$$a$$$ modulo $$$b$$$ (shortened $$$a \bmod b$$$) is the only integer $$$c$$$ such that $$$0 \leq c < b$$$, and $$$a - c$$$ is divisible by $$$b$$$.In the first sample, $$$11~\mathrm{div}~3 = 3$$$ and $$$11 \bmod 3 = 2$$$. Since $$$3 \cdot 2 = 6$$$, then $$$x = 11$$$ is a solution to $$$(x~\mathrm{div}~3) \cdot (x \bmod 3) = 6$$$. One can see that $$$19$$$ is the only other positive integer solution, hence $$$11$$$ is the smallest one.

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

class Utils {
	/* Perform action N times. Can return values in array */
	static public 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. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

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

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

$ir = new InputReader();

/* TASK */

list($n, $k) = $ir->readArrayOfInt(2);
$xs = [];
foreach(PrimeUtils::divisors($n) as $divisor=>$v) {
	$l = $divisor;
	$m = intval($n/$l);
	//echo "$divisor, $l, $m, $k\n";

	if ($m<$k) {
		$xs[] = $k*$l + $m;
	}
}

if (empty($xs)) {
	echo $n*$k+1;
} else {
	echo min($xs);
}

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

class Utils {
	/* Perform action N times. Can return values in array */
	static public 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. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

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

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

$ir = new InputReader();

/* TASK */

list($n, $k) = $ir->readArrayOfInt(2);
$xs = [];
foreach(PrimeUtils::divisors($n) as $divisor=>$v) {
	$l = $divisor;
	$m = intval($n/$l);
	//echo "$divisor, $l, $m, $k\n";

	if ($m<$k) {
		$xs[] = $k*$l + $m;
	}
}
//var_dump($xs);
echo min($xs);


Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first n. He writes down the following sequence of numbers: firstly all odd integers from 1 to n (in ascending order), then all even integers from 1 to n (also in ascending order). Help our hero to find out which number will stand at the position number k.

The only line of input contains integers n and k (1 ≤ k ≤ n ≤ 1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.

Print the number that will stand at the position number k after Volodya's manipulations.

NoteIn the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.

<?php

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

$mod = ceil($n/2);

//echo("$k $mod\n");

if ($k<=$mod){
    echo ($k-1)*2+1;
    exit;
} else {
    echo ($k-$mod)*2;
}

<?

error_reporting(false);
//error_reporting(E_ALL);

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

if (file_exists("in.txt")) {
    $handle = fopen('in.txt', 'r');
    set_time_limit(2);
};

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

$nums =  ceil($n/2);

if ($k <= $nums) {

    printf("%.0f", $k * 2 - 1);
} else {
    printf("%.0f", ($k - $nums) * 2);
}

<?php
// 318A     Чет и нечет
$in = fopen("php://stdin", 'r');

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

$x = substr($n, strlen($n)-1, 1);
$countNech = bcdiv($n, '2', 0);

if (($x % 2) !== 0) {
    $countNech = bcadd($countNech, '1', 0);
}

if (bccomp($k, $countNech) == 1) {
    $k = bcsub($k, $countNech, 0);
    $out = bcmul($k, '2', 0);
} else {
    $out = bcmul($k, '2', 0);
    $out = bcsub($out, '1', 0);
}

echo $out;

?>

<?php

$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);

$arr=explode(" ", $n);
$n=$arr[0]; //max n
$k=$arr[1]; //position k

$tempArr=array();

$median=ceil($n/2);

if ($k<=$median)
{
print($k*2-1);
}
else{
print (($k-$median)*2);
}

?>

<?php

$stdin = fopen('php://stdin', 'r');
$data = explode(" ", trim(fgets($stdin)));
$n = $data[0]; $k = $data[1];
$part = ceil($n/2);
if($k > $part)
{
    echo 2 * ($k-$part);
}
 else {
    echo 2*($k-1)+1;
}

<?php
// Hi chaotic
$localtest = ini_get("display_errors"); // normally true, codeforces sets to false
if ($localtest) {echo "derp";}

if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = bcmod($n, 2);
$middle = bcdiv(bcadd($n, $parity), 2);

if (bccomp($k, $middle) != 1) {echo bcsub(bcmul(2, $k), 1);} else {echo bcmul(2, bcsub($k, $middle));}
?>

<?php
error_reporting("off");
//318A: Even Odds
list($n, $k) = explode(" ", trim(fgets(STDIN))); //$n = 7; $k = 7;
$oddnums = ceil($n / 2);

//first find out if $k lands in the even places or the odd places.
if ($k > $oddnums) {
    //if so, it's even. ith even number is 2i.
    $i = $k - $oddnums;
    echo 2 * $i;
} else {
    //it's odd. the ith odd number is 2(i-1) + 1.
    echo 2 * ($k - 1) + 1;
}
?>

<?php
	$input = trim(fgets(STDIN));
	$x = explode(" ", $input);
	$n = $x[0];
	$k = $x[1];
	$mid = ceil($n/2);
	if($k <= $mid)
		$result = (2*$k)-1;
	else
	{
		$y = $k - $mid;
		$result = 2 * $y;
	}
	echo $result;
?>

<?php
$localtest = false;

/* Module for retrieving input */

// If this is a local test (variable toggled above), open from localtest.txt instead of php://stdin (because I'm too lazy to supply the arguments by stdin)
if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

/* Imported functions from chaotic_iak's library */
// none

/* chaotic_iak's solution */
$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = bcmod($n, 2);
$middle = bcdiv(bcadd($n, $parity), 2);

if (bccomp($k, $middle) != 1) {echo bcsub(bcmul(2, $k), 1);} else {echo bcmul(2, bcsub($k, $middle));}
?>

<?php
list ($k,$n) = explode(" ",trim(fgets(STDIN)));
$n=$n-1;
if ($n<$k/2) echo intval($k/($k/2))*$n+1;
else echo 2+2*($n-round($k/2));

<?php
$count_even = $count_odds = $n = $k = $value = 0;
fscanf(STDIN, "%f%f", $n, $k);
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = ($n - 1)/2;
    $count_odds = ($n - 1)/2 + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php

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

$mod = ceil($n/2);

//echo("$k $mod\n");

if ($k<=$mod){
    echo ($k-1)*2+1;
    exit;
} else {
    echo ($k-$mod)*2;
}

<?php

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

$mod = ceil($n/2);

echo("$k $mod\n");

if ($k<=$mod){
    echo ($k-1)*2+1;
    exit;
} else {
    echo ($k-$mod)*2;
}

<?php

#fscanf(STDIN , "%lld%lld" , $n,$k);
list($n,$k) = explode(" " , trim(fgets(STDIN)));
if($n % 2 == 1) $n ++;
if($k <= $n / 2) echo 2* $k - 1;
else {
	$k -= $n / 2;
	echo 2 *  $k;
}

?>

<?

error_reporting(false);
//error_reporting(E_ALL);

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

if (file_exists("in.txt")) {
    $handle = fopen('in.txt', 'r');
    set_time_limit(2);
};

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

$nums =  intval(($n + 1)/2);

if ($k <= $nums) {

    $rtn =  $k * 2 - 1;
} else {
    $rtn = ($k - $nums) * 2;
}

printf("%u", $rtn);
//%u

?>

<?

error_reporting(false);
//error_reporting(E_ALL);

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

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

$nums =  intval(($n + 1)/2);

if ($k <= $nums) {

    echo  $k * 2 - 1;
} else {
    echo ($k - $nums) * 2;
}

?>

<?php
// 318A     Чет и нечет
$in = fopen("php://stdin", 'r');

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

$x = substr($n, strlen($n)-1, 1);
$countNech = bcdiv($n, '2', 0);

if (($x % 2) !== 0) {
    $countNech = bcadd($countNech, '1', 0);
}

if (bccomp($k, $countNech) >= 0) {
    $k = bcsub($k, $countNech, 0);
    $out = bcmul($k, '2', 0);
} else {
    $out = bcmul($k, '2', 0);
    $out = bcsub($out, '1', 0);
}

echo $out;

?>

<?php

$stdin = fopen('php://stdin', 'r');
$data = explode(" ", trim(fgets($stdin)));
$n = $data[0]; $k = $data[1];
$part = ceil($n/2);
if($k > $part)
{
    echo 2 * ($part-$k);
}
 else {
    echo 2*($k-1)+1;
}

<?php
// derp does this work the same as in Custom Test?
var_dump(ini_get("ONLINE_JUDGE"));
?>

<?php
	$input = trim(fgets(STDIN));
	$x = explode(" ", $input);
	$n = intval($x[0]);
	$k = intval($x[1]);
	$mid = ceil($n/2);
	if($k <= $mid)
		$result = (2*$k)-1;
	else
	{
		$y = $k - $mid;
		$result = 2 * $y;
	}
	echo $result;
?>

<?php
if (ONLINE_JUDGE !== true) {echo "derp";}

/* Module for retrieving input */

// If this is a local test (variable toggled above),
if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

/* Imported functions from chaotic_iak's library */
// none

/* chaotic_iak's solution */
$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = $n % 2;
$middle = ($n + $parity) / 2;

if ($k <= $middle) {echo 2*$k - 1;} else {echo 2*$k - $n - $parity;}
?>

<?php
if ((ONLINE_JUDGE !== "true") && (ONLINE_JUDGE !== true)) {echo "derp";}

$localtest = false;

/* Module for retrieving input */

// If this is a local test (variable toggled above), open from localtest.txt instead of php://stdin (because I'm too lazy to supply the arguments by stdin)
if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

/* Imported functions from chaotic_iak's library */
// none

/* chaotic_iak's solution */
$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = bcmod($n, 2);
$middle = bcdiv(bcadd($n, $parity), 2);

if (bccomp($k, $middle) != 1) {echo bcsub(bcmul(2, $k), 1);} else {echo bcmul(2, bcsub($k, $middle));}
?>

<?php
if (!(defined(ONLINE_JUDGE))) {echo "derp";}

/* Module for retrieving input */

// If this is a local test (variable toggled above),
if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

/* Imported functions from chaotic_iak's library */
// none

/* chaotic_iak's solution */
$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = $n % 2;
$middle = ($n + $parity) / 2;

if ($k <= $middle) {echo 2*$k - 1;} else {echo 2*$k - $n - $parity;}
?>

<?php
$localtest = false;

/* Module for retrieving input */

// If this is a local test (variable toggled above),
if ($localtest) {$stdin = fopen("localtest.txt", "r");} else {$stdin = fopen("php://stdin", "r");}
function g($num = -1) {
    global $stdin;
    $input = explode(" ", trim(fgets($stdin)));
    if ($num == -1) {return $input;} else {return $input[$num];}
}

/* Imported functions from chaotic_iak's library */
// none

/* chaotic_iak's solution */
$raw = g();
$n = $raw[0];
$k = $raw[1];

$parity = $n % 2;
$middle = ($n + $parity) / 2;

if ($k <= $middle) {echo 2*$k - 1;} else {echo 2*$k - $n - $parity;}
?>

<?php
list ($k,$n) = explode(" ",trim(fgets(STDIN)));
$n=$n-1;
if ($n<$k/2) echo intval($k/($k/2))*$n+1;
else echo 2+2*(round($k/2)-$n);

<?php

fscanf(STDIN, "%d%d", $n, $k);
$even = range(2,$n, 2);
$odd = range(1,$n, 2);
print_r($even);
print_r($odd);
for ($i = count($odd)-1; $i >= 0; $i--) {
    array_unshift($even, $odd[$i]);
}
print($even[$k-1]);

<?php
$input = array();
$count_even = $count_odds = $n = $k = $value = 0;
$input = explode(" ", (trim(fgets(STDIN))));
$n = $input[0];
$k = $input[1];
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php
$input = array();
$count_even = $count_odds = $n = $k = $value = 0;
$input = explode(" ", (trim(fgets(STDIN, 4096))));
$n = $input[0];
$k = $input[1];
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php

fscanf(STDIN, "%d%d", $n, $k);
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php
$count_even = $count_odds = $n = $k = $value = 0;
fscanf(STDIN, "%d%d", $n, $k);
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php
$count_even = $count_odds = $n = $k = $value = 0;
fscanf(STDIN, "%f%f", $n, $k);
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php

fscanf(STDIN, "%d%d", $n, $k);
$even = range(2,$n, 2);
$odd = range(1,$n, 2);
for ($i = count($odd)-1; $i >= 0; $i--) {
    array_unshift($even, $odd[$i]);
}
print($even[$k-1]);

<?php
$count_even = $count_odds = $n = $k = $value = 0;
fscanf(STDIN, "%F%F", $n, $k);
if ($n%2 == 0) {
    $count_even = $n/2;
    $count_odds = $n/2;
} else {
    $count_even = intdiv($n, 2);
    $count_odds = intdiv($n, 2) + 1;
}

if ($k <= $count_odds) {
    $value = $k * 2 - 1;
} else {
    $value = ($k - $count_odds) * 2;
}
print($value);

<?php

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

$mod = ceil($n/2);

//echo("$k $mod\n");

if ($k<$mod){
    echo ($k-1)*2+1;
    exit;
} else {
    echo ($k-$mod)*2;
}


A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....   The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.

The first line of input contains two integers a and b (1 ≤ a, b ≤ 100).  The second line contains two integers c and d (1 ≤ c, d ≤ 100).

Print the first time Rick and Morty will scream at the same time, or  - 1 if they will never scream at the same time.

NoteIn the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
list($c, $d) = explode(" ", trim(fgets(STDIN)));
$e = $b;
$f = $d;
$g = array($e);
$h = array($f);
for($x = 1; $x <= 10000; $x++)
{
     $e = $b + ($a * $x);
     $f = $d + ($c * $x);
     $g[$x] = $e;
     $h[$x] = $f;
}
$i = array_intersect($g, $h);
if(count($i) > 0)
{
     $j = current($i);
     print $j;
}
else
{
     print "-1";
}
?>

<?php
        //Enter your code here, enjoy!
    list($a, $b) = explode(" ", trim(fgets(STDIN)));
    list($c, $d) = explode(" ", trim(fgets(STDIN)));

    $aa = array();
    $cc = array();
    for($i = 0; $i < 5000; $i++)
    {
        $aa[$i] = $b + ($a * $i);
        $cc[$i] = $d + ($c * $i);
    }

    $ee = array_intersect($aa, $cc);
    if( sizeof($ee) > 0)
    {
        reset($ee);
        echo current($ee);
    } else {
        echo "-1";
    }

    echo PHP_EOL;

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

$i = 0;
while($i < 1000) {
    if($b == $d) {
        echo $b;
        exit;
    }
    else if($b > $d) {
        $d += $c;
    }
    else {
        $b += $a;
    }
    $i++;
}
echo -1;


You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied:   the i-th letter occurs in the string no more than ai times;  the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once.

The first line of the input contains a single integer n (2  ≤  n  ≤  26) — the number of letters in the alphabet. The next line contains n integers ai (1 ≤ ai ≤ 109) — i-th of these integers gives the limitation on the number of occurrences of the i-th character in the string.

Print a single integer — the maximum length of the string that meets all the requirements.

NoteFor convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".

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

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


During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals.Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough.Right now there are A yellow and B blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls.

The first line features two integers A and B (0 ≤ A, B ≤ 109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers x, y and z (0 ≤ x, y, z ≤ 109) — the respective amounts of yellow, green and blue balls to be obtained.

Print a single integer — the minimum number of crystals that Grisha should acquire in addition.

NoteIn the first sample case, Grisha needs five yellow and four blue crystals to create two yellow balls, one green ball, and one blue ball. To do that, Grisha needs to obtain two additional crystals: one yellow and one blue.

<?php

// ურბან მეორე, ეს იყო ღვთაება. მე მაგისი.. ჯვაროსნების ლაშქრობას მაგან მისცა ბიძგი. თან დიდი.

$urbanTheSecond = 0;

list($a,$b) = explode(" ",trim(fgets(STDIN)));
list($yellow,$green,$blue) = explode(" ", trim(fgets(STDIN)));

$a1 = 2*$yellow + $green;
$b1 = $green + 3*$blue;

if($a - $a1 < 0)
    $urbanTheSecond+=$a1-$a;

if($b - $b1 < 0)
    $urbanTheSecond+= $b1 - $b;

echo $urbanTheSecond;

?>


Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?

The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.

In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).

NoteIn the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa.

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

<?php
error_reporting("off");
//433A: Kitahara Haruki's Gift
$n = trim(fgets(STDIN)); //$n = 4;
$apples = explode(" ", trim(fgets(STDIN))); //$apples = explode(" ", "100 100 100 200");
$count = array_count_values($apples);
$totalweight = $count[100] * 100 + $count[200] * 200;
$half = $totalweight / 100; //getting rid of two zeros for the number of hundreds
if ($half % 2 !== 0) {
    echo "NO";
} else {
    $halfreally = $half / 2;
    if ($halfreally % 2 == 0) {
        echo "YES";
    } else {
        if ($count[100] == 0) {
            echo "NO";
        } else {
            echo "YES";
        }
    }
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
array_unshift($d, " ");
unset($d[0]);
$e = array_search("5", $d);
$f = array_unique($b);
if(($e == TRUE) || ($a == 1) || ((count($f) == 1) && ((count($b) % 2) != 0)))
{
    print "NO";
}
else
{
    print "YES";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
array_unshift($d, " ");
unset($d[0]);
$e = array_search("5", $d);
if(($e == TRUE) || ($a == 1))
{
    print "NO";
}
else
{
    print "YES";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
array_unshift($d, " ");
unset($d[0]);
$e = array_search("5", $d);
$f = array_unique($b);
if(($e == TRUE) || ($a == 1) || (count($f) == 1))
{
    print "NO";
}
else
{
    print "YES";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
if($d[1] != 0)
{
    print "NO";
}
else
{
    print "YES";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
array_unshift($d, " ");
unset($d[0]);
$e = array_search("5", $d);
$f = array_unique($d);
if(($e == TRUE) || ($a == 1) || (count($f) == 1))
{
    print "NO";
}
else
{
    print "YES";
}
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = array_sum($b) / 2;
$d = str_split($c);
array_unshift($d, " ");
unset($d[0]);
$e = array_search("5", $d);
if($e == TRUE)
{
    print "NO";
}
else
{
    print "YES";
}
?>

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

<?php
error_reporting("off");
//433A: Kitahara Haruki's Gift
$n = trim(fgets(STDIN)); //$n = 4;
$apples = explode(" ", trim(fgets(STDIN))); //$apples = explode(" ", "100 100 100 200");
$count = array_count_values($apples);
$totalweight = $count[100] * 100 + $count[200] * 200;
$half = $totalweight / 100; //getting rid of two zeros for the number of hundreds
if ($half % 2 !== 0) {
    echo "NO";
} else {
    echo "YES";
}
?>

<?php
error_reporting("off");
//433A: Kitahara Haruki's Gift
$n = trim(fgets(STDIN)); $n = 4;
$apples = explode(" ", trim(fgets(STDIN))); $apples = explode(" ", "100 100 100 200");
$count = array_count_values($apples);
$totalweight = $count[100] * 100 + $count[200] * 200;
$half = $totalweight / 100; //getting rid of two zeros for the number of hundreds
if ($half % 2 !== 0) {
    echo "NO";
} else {
    echo "YES";
}
?>


Vasya studies music. He has learned lots of interesting stuff. For example, he knows that there are 12 notes: C, C#, D, D#, E, F, F#, G, G#, A, B, H. He also knows that the notes are repeated cyclically: after H goes C again, and before C stands H. We will consider the C note in the row's beginning and the C note after the H similar and we will identify them with each other. The distance between the notes along the musical scale is measured in tones: between two consecutive notes there's exactly one semitone, that is, 0.5 tone. The distance is taken from the lowest tone to the uppest one, that is, the distance between C and E is 4 semitones and between E and C is 8 semitonesVasya also knows what a chord is. A chord is an unordered set of no less than three notes. However, for now Vasya only works with triads, that is with the chords that consist of exactly three notes. He can already distinguish between two types of triads — major and minor.Let's define a major triad. Let the triad consist of notes X, Y and Z. If we can order the notes so as the distance along the musical scale between X and Y equals 4 semitones and the distance between Y and Z is 3 semitones, then the triad is major. The distance between X and Z, accordingly, equals 7 semitones.A minor triad is different in that the distance between X and Y should be 3 semitones and between Y and Z — 4 semitones.For example, the triad "C E G" is major: between C and E are 4 semitones, and between E and G are 3 semitones. And the triplet "C# B F" is minor, because if we order the notes as "B C# F", than between B and C# will be 3 semitones, and between C# and F — 4 semitones.Help Vasya classify the triad the teacher has given to him.

The only line contains 3 space-separated notes in the above-given notation.

Print "major" if the chord is major, "minor" if it is minor, and "strange" if the teacher gave Vasya some weird chord which is neither major nor minor. Vasya promises you that the answer will always be unambiguous. That is, there are no chords that are both major and minor simultaneously.


Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?

The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers x1, x2, ..., xn (0 ≤ xi ≤ 100).

Output a single integer — the minimal possible number of piles.

NoteIn example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
for($x = 1; $x <= 100; $x++)
{
    sort($b);
    $c = array();
    array_push($c, $b[0]);
    unset($b[0]);
    for($y = 1; $y <= 100; $y++)
    {
        if($b[$y] == 0)
        {
            continue;
        }
        elseif($b[$y] >= count($c))
        {
            array_push($c, $b[$y]);
            unset($b[$y]);
        }
        elseif($b[$y] < count($c))
        {
            continue;
        }
    }
    if(count($b) == 0)
    {
        break;
    }
}
print $x;
?>

<?php

$n = trim(fgets(STDIN));
$arr = explode(" ", trim(fgets(STDIN)));

sort($arr);
$s=0;
for($i=0;$i<$n;$i++){
    if($s*$arr[$i]+$s<=$i)$s++;

}

echo $s.PHP_EOL;


Natasha is planning an expedition to Mars for $$$n$$$ people. One of the important tasks is to provide food for each participant.The warehouse has $$$m$$$ daily food packages. Each package has some food type $$$a_i$$$.Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.Formally, for each participant $$$j$$$ Natasha should select his food type $$$b_j$$$ and each day $$$j$$$-th participant will eat one food package of type $$$b_j$$$. The values $$$b_j$$$ for different participants may be different.What is the maximum possible number of days the expedition can last, following the requirements above?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$, $$$1 \le m \le 100$$$) — the number of the expedition participants and the number of the daily food packages available. The second line contains sequence of integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the type of $$$i$$$-th food package.

Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.

NoteIn the first example, Natasha can assign type $$$1$$$ food to the first participant, the same type $$$1$$$ to the second, type $$$5$$$ to the third and type $$$2$$$ to the fourth. In this case, the expedition can last for $$$2$$$ days, since each participant can get two food packages of his food type (there will be used $$$4$$$ packages of type $$$1$$$, two packages of type $$$2$$$ and two packages of type $$$5$$$).In the second example, there are $$$100$$$ participants and only $$$1$$$ food package. In this case, the expedition can't last even $$$1$$$ day.


Polycarpus has got n candies and m friends (n ≥ m). He wants to make a New Year present with candies to each friend. Polycarpus is planning to present all candies and he wants to do this in the fairest (that is, most equal) manner. He wants to choose such ai, where ai is the number of candies in the i-th friend's present, that the maximum ai differs from the least ai as little as possible.For example, if n is divisible by m, then he is going to present the same number of candies to all his friends, that is, the maximum ai won't differ from the minimum one.

The single line of the input contains a pair of space-separated positive integers n, m (1 ≤ n, m ≤ 100;n ≥ m) — the number of candies and the number of Polycarpus's friends.

Print the required sequence a1, a2, ..., am, where ai is the number of candies in the i-th friend's present. All numbers ai must be positive integers, total up to n, the maximum one should differ from the minimum one by the smallest possible value.

NotePrint ai in any order, separate the numbers by spaces.

#!/usr/bin/php
<?php

$s = fopen("php://stdin", 'r');
$n = fgets($s);
$dum = explode(" " , $n);
$candiesNum = $dum[0];
$friendsNum = $dum[1];

$division = intval($candiesNum / $friendsNum);
$difference = $candiesNum % $friendsNum;
$result = NULL;
for($n = 0; $n < $friendsNum - $difference; $n++)
{
     $result .= $division . ' ';
}
for($n = 0; $n < $difference; $n++)
{
     $result .= $division+1 . ' ';
}
echo substr($result , 0 , -1);

#!/usr/bin/php
<?php

$candiesNum = $argv[1];
$friendsNum = $argv[2];

$division = intval($candiesNum / $friendsNum);
$difference = $candiesNum % $friendsNum;
$result = NULL;
for($n = 0; $n < $friendsNum - $difference; $n++)
{
     $result .= $division . ' ';
}
for($n = 0; $n < $difference; $n++)
{
     $result .= $division+1 . ' ';
}
echo substr($result , 0 , -1);


Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop.In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of r burles (1 ≤ r ≤ 9).What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of r burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.

The single line of input contains two integers k and r (1 ≤ k ≤ 1000, 1 ≤ r ≤ 9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".  Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.

Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.

NoteIn the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.In the second example it is enough for Polycarp to buy one shovel.In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.

<?php

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

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

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

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

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

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

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

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

function getAnswer($is_test = false, $f = false) {
	if ($is_test)
		$stream = $f;
	else
		$stream = STDIN;
	/* begin body */
	list($price, $r) = readStringExplodeNum($stream, ' ', true);
	for ($i = 1; $i <= 10; $i++) {
		$amount = $i * $price;

		if ($amount % 10 == $r || $amount % 10 == 0) {
			echo $i;
			break;
		}
	}

	/* / end body */
}

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

<?php
list($oneshovel, $coin)=explode(" ", trim(fgets(STDIN)));
$x=1;
while (TRUE) {

     if (($oneshovel * $x) % 10 == 0 or (($oneshovel * $x) - $coin) % 10 == 0) {

          break;
     }else $x++;

}
echo $x;
?>

<?php

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

fscanf($stdin, "%d %d", $k , $r ) ;

$count = 1 ;
$temp = $k ;

while( true )
{
     if( $k % 10 == 0 )
     {
          break ;
     }
     if( $k % 10 == $r )
     {
          break ;
     }
     $count++ ;
     $k = $count * $temp ;
}
echo $count ;

fwrite($stdout);

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

?>

<?php

$stdin = fopen('php://stdin', 'r');
$string = explode(" ", trim(fgets($stdin)));
$value = $string[0];
$coin = $string[1];
$count = 1;
$summ = $value;
while ($summ % 10 != 0 && $summ % 10 != $coin) {
    $summ = $summ + $value;
    $count++;
}
printf('%.0f', $count);

<?php
$data = fgets(STDIN);
//$gestor = @fopen("data.in", "r");
//$data = fgets($gestor);
$data = explode(" ", $data);
$n = $data[0];
$k = $data[1];
$c = 1;
$flag = true;
while ($flag) {
    $aux = ($n * $c);
    if ($aux % 10 == 0 || ($aux - $k) % 10 == 0) {
        echo $c;
        $flag = false;
    }
    $c++;
}
?>

<?php
function shovel(int $cost, int $coin): int
{
    for ($i = 1; $i < 10; $i++) {
        $result = (int)((string)($cost * $i))[-1];
        if ($result === 0 || $result === $coin) {
            break;
        }
    }
    return $i;
}
[$cost, $coin] = explode(' ', file_get_contents('php://stdin'));
echo shovel($cost, $coin);

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
function dividable($n){
	$s = (string) $n;
	if(substr($s, strlen($s)-1) == "0") return true;
	return false;
}
function calculate_min($k, $n){
	$allow = true;
	$c = 0;
	$num = $k-$n;
	if(dividable($num)) return "1";
	for($i=0;$i<=10; $i++){
		$c++;
		if(dividable(($c)*$k - $n)) return $c;
		if(dividable(($c)*$k)) return $c;
	}
	return "undefined";
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite( $handle, $data );
	fclose( $handle );
}

function calculate_min($k, $n){
	$allow = true;
	$c = 1;
	$s = $k;
	$coin = $n;
	while($allow){
		if(($s-$n)%10 == 0){
			$allow = false;
			break;
		}
		$s += $k;
		$c++;
	}
	return $c;
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
function dividable($n){
	$s = (string) $n;
	if(substr($s, strlen($s)-1) == "0" && strlen($s)>1) return true;
	return false;
}
function calculate_min($k, $n){
	$allow = true;
	$c = 1;
	$num = $k-$n;
	if(dividable($num)) return $c;
	for($i=0;$i<=10; $i++){
		$c++;
		if(dividable(($c-1)*$k - $n)) return $c-1;
		if(dividable(($c-1)*$k)) return $c-1;
	}
	return "undefined";
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
function dividable($n){
	$s = (string) $n;
	if(substr($n, strlen($n)-1) == "0" && strlen($n)>1) return true;
	return false;
}
function calculate_min($k, $n){
	$allow = true;
	$c = 1;
	$num = $k-$n;
	if(dividable($num)) return $c;
	for($i=0;$i<=10; $i++){
		$c++;
		if(dividable(($c-1)*$k)) return $c-1;
		if(dividable(($c-1)*$k - $n)) return $c-1;
	}
	return "undefined";
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
function dividable($n){
	$s = (string) $n;
	if(substr($n, strlen($n)-1) == "0" && strlen($n)>1) return true;
	return false;
}
function calculate_min($k, $n){
	$allow = true;
	$c = 1;
	$num = $k-$n;
	if(dividable($num)) return $c;
	for($i=0;$i<=10; $i++){
		$c++;
		if(dividable(($c-1)*$k - $n)) return $c-1;
		if(dividable(($c-1)*$k)) return $c-1;
	}
	return "undefined";
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return readfile('php://stdin');
}
function put($data){
	file_put_contents('php://stdout', $data);
}

function calculate_min($k, $n){
	$allow = true;
	$c = 1;
	$s = $k;
	$coin = $n;
	while($allow){
		if(($s-$n)%10 == 0){
			$allow = false;
			break;
		}
		$s += $k;
		$c++;
	}
	echo $c;
}
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>

<?php
function read(){
	return file_get_contents('php://stdin');
}
function put($data){
	$f = fopen('php://stdout' , "w");
	fwrite($f, $data);
	fclose($f);
}
function dividable($n){
	$s = (string) $n;
	if(substr($s, strlen($s)-1) == "0") return true;
	return false;
}
function calculate_min($k, $n){
	$allow = true;
	$c = 0;
	$num = $k-$n;
	if(dividable($num)) return "1";
	for($i=0;$i<=10; $i++){
		$c++;
		if(dividable(($c)*$k - $n)) return $c;
		if(dividable(($c)*$k)) return $c;
	}
	return "undefined";
}
echo(calculate_min(1, 1));
die();
$read = read();

list($k, $n) = explode(" ", $read);
put(calculate_min($k, $n));
?>


There are n cities in Bearland, numbered 1 through n. Cities are arranged in one long row. The distance between cities i and j is equal to |i - j|.Limak is a police officer. He lives in a city a. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city.Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city a. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal.You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.

The first line of the input contains two integers n and a (1 ≤ a ≤ n ≤ 100) — the number of cities and the index of city where Limak lives. The second line contains n integers t1, t2, ..., tn (0 ≤ ti ≤ 1). There are ti criminals in the i-th city.

Print the number of criminals Limak will catch.

NoteIn the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.  Using the BCD gives Limak the following information:  There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city.  There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city.  There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city.  There are zero criminals for every greater distance. So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total.In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$cards = explode(" ",$s);
$cities_cnt=$cards[0];
$limak_city=$cards[1]-1;
$s =  trim(fgets($stdin));
$crims = explode(" ",$s);
$catched=0;
if($limak_city>($cities_cnt/2)){
for ($i=0;$i<($limak_city);$i++){

	$r = abs($limak_city-$i);
	//echo $r;
	if(($cities_cnt-($limak_city+$r)<=0)||(($limak_city-$r)<0)){
	   // echo "!".$crims[$limak_city-$r]."!\n";
		if(((int)$crims[$limak_city+$r])>0||((int)$crims[$limak_city-$r])>0){
			$catched+=1;
		}
	}else{
	   // echo "+".($limak_city+$r);
		if(((int)$crims[$limak_city+$r])>0&&((int)$crims[$limak_city-$r])>0){
			$catched+=2;
		}

	}
	//echo $catched." ";
}
}else{
	for ($i=$cities_cnt;$i>($limak_city);$i--){

	$r = abs($limak_city-$i);
//	echo $r;
	if(($cities_cnt-($limak_city+$r)<=0)||(($limak_city-$r)<0)){
		if(((int)$crims[$limak_city+$r])>0||((int)$crims[$limak_city-$r])>0){
			$catched+=1;

		}
	}else{
		if(((int)$crims[$limak_city+$r])>0&&((int)$crims[$limak_city-$r])>0){
			$catched+=2;
		}

	}
//	echo $catched." ";
}

}
if($crims[$limak_city]>0){
	$catched+=1;
}
echo $catched;

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$cards = explode(" ",$s);
$cities_cnt=$cards[0];
$limak_city=$cards[1]-1;
$s =  trim(fgets($stdin));
$crims = explode(" ",$s);
$catched=0;
if($limak_city>($cities_cnt/2)){
for ($i=0;$i<($limak_city);$i++){

	$r = abs($limak_city-$i);
	if(($cities_cnt-($limak_city+$r)<0)||($cities_cnt>=($limak_city+$r))){
		if(((int)$crims[$limak_city+$r])>0||((int)$crims[$limak_city-$r])>0){
			$catched+=1;
		}
	}else{
		if(((int)$crims[$limak_city+$r])>0&&((int)$crims[$limak_city-$r])>0){
			$catched+=2;
		}

	}
}
}else{
	for ($i=$cities_cnt;$i>($limak_city);$i--){

	$r = abs($limak_city-$i);
	if(($cities_cnt-($limak_city+$r)<0)||($cities_cnt>=($limak_city+$r))){
		if(((int)$crims[$limak_city+$r])>0||((int)$crims[$limak_city-$r])>0){
			$catched+=1;
		}
	}else{
		if(((int)$crims[$limak_city+$r])>0&&((int)$crims[$limak_city-$r])>0){
			$catched+=2;
		}

	}
}

}
if($crims[$limak_city]>0){
	$catched+=1;
}
echo $catched;

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$cards = explode(" ",$s);
$cities_cnt=$cards[0];
$limak_city=$cards[1]-1;
$s =  trim(fgets($stdin));
$crims = explode(" ",$s);
$catched=0;
if($limak_city>($cities_cnt/2)){
for ($i=0;$i<($limak_city);$i++){

	$r = abs($limak_city-$i);
	if(($cities_cnt-($limak_city+$r)<0)||($cities_cnt>=($limak_city+$r))){
		if(((int)$crims[$limak_city+$r])>0||((int)$crims[$limak_city-$r])>0){
			$catched+=1;
		}
	}elseif($cities_cnt-($r+$r)>=0){
		if(((int)$crims[$limak_city+$r])>0&&((int)$crims[$limak_city-$r])>0){
			$catched+=2;
		}

	}
}
}else{
	for ($i=$cities_cnt;$i>($limak_city);$i--){

	$r = abs($limak_city-$i);
	if(($cities_cnt-($limak_city+$r)<0)||($cities_cnt>=($limak_city+$r))){
		if(((int)$crims[$limak_city+$r])>0||((int)$crims[$limak_city-$r])>0){
			$catched+=1;
		}
	}else{
		if(((int)$crims[$limak_city+$r])>0&&((int)$crims[$limak_city-$r])>0){
			$catched+=2;
		}

	}
}

}
if($crims[$limak_city]>0){
	$catched+=1;
}
echo $catched;

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$cards = explode(" ",$s);
$cities_cnt=$cards[0];
$limak_city=$cards[1]-1;
$s =  trim(fgets($stdin));
$crims = explode(" ",$s);
$catched=0;
if($limak_city>($cities_cnt/2)){
for ($i=0;$i<($limak_city);$i++){

	$r = abs($limak_city-$i);
	if(($cities_cnt-($limak_city+$r)<0)||($cities_cnt>($limak_city+$r))){
		if(((int)$crims[$limak_city+$r])>0||((int)$crims[$limak_city-$r])>0){
			$catched+=1;
		}
	}elseif($cities_cnt-($r+$r)>=0){
		if(((int)$crims[$limak_city+$r])>0&&((int)$crims[$limak_city-$r])>0){
			$catched+=2;
		}

	}
}
}else{
	for ($i=$cities_cnt;$i>($limak_city);$i--){

	$r = abs($limak_city-$i);
	if(($cities_cnt-($limak_city+$r)<0)||($cities_cnt>($limak_city+$r))){
		if(((int)$crims[$limak_city+$r])>0||((int)$crims[$limak_city-$r])>0){
			$catched+=1;
		}
	}else{
		if(((int)$crims[$limak_city+$r])>0&&((int)$crims[$limak_city-$r])>0){
			$catched+=2;
		}

	}
}

}
if($crims[$limak_city]>0){
	$catched+=1;
}
echo $catched;

<?

$stdin = fopen('php://stdin', 'r');
$s =  trim(fgets($stdin));
$cards = explode(" ",$s);
$cities_cnt=$cards[0];
$limak_city=$cards[1]-1;
$s =  trim(fgets($stdin));
$crims = explode(" ",$s);
$catched=0;
if($limak_city>($cities_cnt/2)){
for ($i=0;$i<($limak_city);$i++){

	$r = abs($limak_city-$i);
	if(($cities_cnt-($limak_city+$r)<=0)||($cities_cnt>=($limak_city+$r))){
		if(((int)$crims[$limak_city+$r])>0||((int)$crims[$limak_city-$r])>0){
			$catched+=1;
		}
	}else{
		if(((int)$crims[$limak_city+$r])>0&&((int)$crims[$limak_city-$r])>0){
			$catched+=2;
		}

	}
}
}else{
	for ($i=$cities_cnt;$i>($limak_city);$i--){

	$r = abs($limak_city-$i);
	if(($cities_cnt-($limak_city+$r)<=0)||($cities_cnt>=($limak_city+$r))){
		if(((int)$crims[$limak_city+$r])>0||((int)$crims[$limak_city-$r])>0){
			$catched+=1;
		}
	}else{
		if(((int)$crims[$limak_city+$r])>0&&((int)$crims[$limak_city-$r])>0){
			$catched+=2;
		}

	}
}

}
if($crims[$limak_city]>0){
	$catched+=1;
}
echo $catched;


Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.To obfuscate the code, Kostya first looks at the first variable name used in his program and replaces all its occurrences with a single symbol a, then he looks at the second variable name that has not been replaced yet, and replaces all its occurrences with b, and so on. Kostya is well-mannered, so he doesn't use any one-letter names before obfuscation. Moreover, there are at most 26 unique identifiers in his programs.You are given a list of identifiers of some program with removed spaces and line breaks. Check if this program can be a result of Kostya's obfuscation.

In the only line of input there is a string S of lowercase English letters (1 ≤ |S| ≤ 500) — the identifiers of a program with removed whitespace characters.

If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO".

NoteIn the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program: replace all occurences of number with a, the result would be "a string a character a string a", replace all occurences of string with b, the result would be "a b a character a b a", replace all occurences of character with c, the result would be "a b a c a b a", all identifiers have been replaced, thus the obfuscation is finished.

<?php
$a = str_split(trim(fgets(STDIN)));
$b = array_unique($a);
$c = array_keys($b);
$d = array();
for($x = 0; $x < count($b); $x++)
{
     $d[$x] = $b[$c[$x]];
}
$e = implode($d);
$f = "abcdefghijklmnopqrstuvwxyz";
$g = substr($f, 0, strlen($e));
if($e == $g)
{
     print "YES";
}
else
{
     print "NO";
}
?>

#!/usr/bin/php
<?php

$string = trim(fgets(STDIN));
$current = 0;

for ($i = 0; $i < strlen($string); $i++) {
	if (ord($string[$i]) <= ($current + ord('a') - 1)) {

	} else if (ord($string[$i]) == ($current + ord('a'))) {
		$current++;
	} else {
		echo "NO";
		exit();
	}
}

echo "YES";
exit();

<?php

error_reporting(0);

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

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

$alfabeto = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z");

$str=$linhas[0];

$l=sizeof($alfabeto);

for($i=0;$i<$l;$i++) {

$firstLetter = $alfabeto[$i];

if($str[0]==$firstLetter) {

	$str = str_replace($firstLetter, "", $str);

	if(strlen($str) == 0) {
		die("YES");
	}

	continue;

}

else die("NO");

}

?>

<?php
    $word = trim(fgets(STDIN));
    $arr = str_split($word);
    $used = array();

    for($i=sizeof($arr)-1; $i>=0; $i--)
    {
        $flag = false;
        if($arr[$i]!='a')
        {
            for($j=$i-1; $j>=0; $j--)
            {
                $buffer = $arr[$j];
                ++$buffer;

                if( $arr[$i] == $buffer)
                {
                    $flag = true;
                    break;
                }
            }
            if(!$flag)
            {
                $ans = 'no';
                break;
            }
        }
    }

    echo ($ans == 'no') ? "NO\n" : "YES\n";
?>

#!/usr/bin/php
<?php

$string = trim(fgets(STDIN));
$current = 0;

for ($i = 0; $i < strlen($string); $i++) {
	if (ord($string[$i]) <= ($current + ord('a'))) {

	} else if (ord($string[$i]) == ($current + ord('a') + 1)) {
		$current++;
	} else {
		echo "NO";
		exit();
	}
}

echo "YES";
exit();

<?php

error_reporting(0);

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

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

$n=$linhas[0];
$home=$linhas[1];
$i=1;

while($i<$n) {

	$line2 = trim(fgets(STDIN));
	$i++;

}

if($n%2==0) {

echo "home";

}

else echo "contest";

?>


Let's write all the positive integer numbers one after another from $$$1$$$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...Your task is to print the $$$k$$$-th digit of this sequence.

The first and only line contains integer $$$k$$$ ($$$1 \le k \le 10000$$$) — the position to process ($$$1$$$-based index).

Print the $$$k$$$-th digit of the resulting infinite sequence.

<?php
# 1177b
$stdin = STDIN;

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

<?php

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

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

echo $str[$d];

<?php
# 1177b
$k = trim(fgets(STDIN));
if ($k < 10) {
    echo $k;
} else {
    $powers =[0,0];
    $powCount = $digitCount = 0.0;

    for ($i = 0; $i < 12; $i++) {
        $powCount += 10 ** $i * 9;
        $digitCount += 10 ** $i * 9 * ($i + 1);
        if ($digitCount > $k) {
            break;
        }
        $powers = [$i+2, $powCount, $digitCount];
    }

    [$size, $powCount, $digitCount] = $powers;
    $shift = floor(($k - $digitCount) / $size);
    $shift_x = ceil(($k - $digitCount) / $size);
    $key = sprintf('%.0f', $k - $digitCount - ($shift * $size + 1));
    echo (sprintf('%.0f', $powCount + $shift_x))[$key];
}

<?php

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

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

echo $str[$d];

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

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

echo $str[$d];

<?php
# 1177b
$k = trim(fgets(STDIN));
if ($k < 10) {
    echo $k;
} else {
    $powers =[0,0];
    $powCount = $digitCount = 0;

    for ($i = 0; $i < 12; $i++) {
        $powCount += 10 ** $i * 9;
        $digitCount += 10 ** $i * 9 * ($i + 1);
        if ($digitCount > $k) {
            break;
        }
        $powers = [$i+2, $powCount, $digitCount];
    }

    [$size, $powCount, $digitCount] = $powers;
    $shift = (int)floor(($k - $digitCount) / $size);
    $shift_x = (int)ceil(($k - $digitCount) / $size);
    echo (sprintf('%.0f', $powCount + $shift_x))[$k - $digitCount - ($shift * $size + 1)];
}

<?php
# 1177b

$k = trim(fgets(STDIN));
if ($k < 10) {
    echo $k;
} else {
    $powers =[0,0];
    $powCount = $digitCount = 0;

    for ($i = 0; $i < 12; $i++) {
        $powCount += 10 ** $i * 9;
        $digitCount += 10 ** $i * 9 * ($i + 1);
        if ($digitCount > $k) {
            break;
        }
        $powers = [$i+2, $powCount, $digitCount];
    }

    [$size, $powCount, $digitCount] = $powers;
    $shift = (int)floor(($k - $digitCount) / $size);
    $shift_x = (int)ceil(($k - $digitCount) / $size);
    echo ((string)($powCount + $shift_x))[$k - $digitCount - ($shift * $size + 1)];
}

<?php
# 1177b
$k = trim(fgets(STDIN));
$powers =[0,0];
$powCount = $digitCount = 0;

for ($i = 0; $i < 12; $i++) {
    $powCount += 10 ** $i * 9;
    $digitCount += 10 ** $i * 9 * ($i + 1);
    if ($digitCount > $k) {
        break;
    }
    $powers = [$i+2, $powCount, $digitCount];
}

[$size, $powCount, $digitCount] = $powers;
$shift = (int)floor(($k - $digitCount) / $size);
$shift_x = (int)ceil(($k - $digitCount) / $size);
echo ((string)($powCount + $shift_x))[$k - $digitCount - ($shift * $size + 1)];


Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.

The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.

Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».

NoteDot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.

<?php
$fh=trim(fgets(STDIN));
list($y,$w)=explode(" ",$fh);
function fmax($a, $b){
	if ($a > $b)return $a;
    else return $b;
}

function gcd($a,$b) {
	if ($b == 0)
		return $a;
	return gcd($b, $a % $b);
}
$r=6-fmax($y,$w)+1;
$g=gcd($r,6);
$a1=$r/$g;
$a2=6/$g;
echo(${a1}."/".${a2});
?>

<?php
$line=trim(fgets(STDIN));
$eyes=explode(" ",$line);
$max=0;
for($i=0;$i<2;$i+=1){
   if($max < 0+$eyes[$i]){
     $max=0+$eyes[$i];
   }
}
$amari=6-$max+1;
$max=6;
$sosu=array(2,3);
for($i=0;$i<2;$i+=1){
   if($amari % $sosu[$i] == 0){
     $amari=$amari/$sosu[$i];
     $max=$max/$sosu[$i];
   }
}
print($amari."/".$max);
?>

<?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 nod($a, $b) {
	while ($a <> 0 && $b <> 0) {
		if ($a > $b)
			$a = $a % $b;
		else
			$b = $b % $a;
		$nod = $a + $b;
	}
	return $nod;
}

function getAnswer($is_test = false, $f = false) {
	if ($is_test === false) {
		$f = STDIN;
	}
	/* begin body */
	list($n1, $n2) = readStringExplodeNum($f, ' ', true);

	$goodCnt = 6 - max($n1, $n2) + 1;
	$nod = nod($goodCnt, 6);
	$base = 6;
	$goodCnt/=$nod;
	$base/=$nod;

	echo "{$goodCnt}/{$base}";
	/* / end body */
}

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

<?php

function debug($data, $die = true) {
    echo '<pre>';

    if (is_array($data)) {
        print_r($data);
    } else {
        var_dump($data);
    }

    if ($die) {
        die();
    }

    echo '</pre>';
}

$stdin = @fopen('data.txt', 'r');
if (!$stdin) {
    $stdin = fopen('php://stdin', 'r');
}

function g() {
    global $stdin;
    return trim(fgets($stdin));
}

/****************************************************** Solving block *****************************************************/
list($a, $b) = explode(' ', g());
$max = $a > $b ? $a : $b;
$max--;
$points = 6 - $max;

switch($points) {
    case 0: echo '0/1'; break;
    case 1: echo '1/6'; break;
    case 2: echo '1/3'; break;
    case 3: echo '1/2'; break;
    case 4: echo '2/3'; break;
    case 5: echo '5/6'; break;
    case 6: echo '1/1'; break;
}

?>

<?php

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

fscanf($stdin, "%d %d" , $y , $w ) ;

$arr = [ "1/6" , "1/3" , "1/2" , "2/3" , "5/6" , "1/1" ] ;

$num = max( $y , $w ) ;

$probability = 6 - $num ;

echo $arr[ $probability ] ;

fwrite($stdout);

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

?>

<?php

$line = trim(fgets(STDIN));
$points = explode(" ", $line);

$maximum = max($points);

$P = (7 - $maximum)/6;

switch ($P) {
    case 0:
        $P = '0/1';
        break;
    case 1:
        $P = '1/1';
        break;
    case 1/6:
        $P = '1/6';
        break;
    case 2/6:
        $P = '1/3';
        break;
    case 3/6:
        $P = '1/2';
        break;
    case 4/6:
        $P = '2/3';
        break;
    case 5/6:
        $P = '5/6';
        break;
}

echo $P;
?>

<?php

	$stdin = fopen('php://stdin', 'r');;
	$data = trim(fgets($stdin));
    $arr = explode(" ", $data);
    $chance = max($arr);
    switch($chance){
        case 1: echo '1/1'; break;
        case 2: echo '5/6'; break;
        case 3: echo '2/3'; break;
        case 4: echo '1/2'; break;
        case 5: echo '1/3'; break;
        case 6: echo '1/6'; break;
    }

<?
$arr=explode(' ',trim(fgets(STDIN)));
$max[]=max($arr);
function gcd($a,$b) {
    while ($b) {
        $a%=$b;
        $a^=$b^=$a^=$b;
    }
    return $a;
}
for($i=$max[0];$i<6;$i++){
    $max[]=$i+1;
}
$size=sizeof($max);
$gcd=gcd($size,6);
echo $size/$gcd."/".(6/$gcd);
?>

<?php
list($y, $w) = explode(' ',trim(fgets(STDIN)));
if($y > $w) $m = $y; else $m = $w;
switch($m){
 case 1: print '1/1'; break;
 case 2: print '5/6'; break;
 case 3: print '2/3'; break;
 case 4: print '1/2'; break;
 case 5: print '1/3'; break;
 case 6: print '1/6'; break;
}
?>

<?
$fp=fopen('php://stdin', 'r');
$lines=stream_get_contents($fp);
$lines = trim($lines);
$nums=explode(" ", $lines);
$good=6-max($nums)+1;
$all=6;

for ($i=2; $i<=6; $i++)
if ($good%$i==0 and $all%$i==0)
{
    $good/=$i;
    $all/=$i;
}

$res="$good/$all";
echo $res;
?>

<?php
	$fr = fopen("php://stdin","r");
	$input = fgets($fr);
	list( $y, $w ) = explode(' ', $input);
	fclose ($fr);

	$dice = 6;
	$r = min( $dice-$y, $dice-$w ) + 1;
	foreach ( array(2,3,4,5,6) as $d )
		if ( ($r % $d) == 0 )
		{
			$r /= $d;
			$dice /= $d;
		}
	echo $r.'/'.$dice;
?>

<?php
	$fr = fopen("php://stdin","r");
	$input = fgets($fr);
	list( $y, $w ) = explode(' ', $input);
	fclose ($fr);

	$dice = 6;
	$r = min( $dice-$y, $dice-$w ) + 1;
	if ( $r == 1 )
		die('0/1');
	foreach ( array(2,3,5) as $d )
	{
		while ( ($r % $d) == 0 )
		{
			$r /= $d;
			$dice /= $d;
		}
	}
	echo $r.'/'.$dice;
?>

<?php

$line = trim(fgets(STDIN));
$points = explode(" ", $line);

$maximum = max($points);

$P = (7 - $maximum)/6;

switch ($P) {
    case 0:
        $P = '0/0';
        break;
    case 1:
        $P = '1/1';
        break;
    case 1/6:
        $P = '1/6';
        break;
    case 2/6:
        $P = '2/6';
        break;
    case 3/6:
        $P = '3/6';
        break;
    case 4/6:
        $P = '4/6';
        break;
    case 5/6:
        $P = '5/6';
        break;
}

echo $P;
?>

<?php

$line = trim(fgets(STDIN));
$points = explode(" ", $line);

$maximum = max($points);

$P = (7 - $maximum)/6;

switch ($P) {
    case 0:
        $P = '0/1';
        break;
    case 1:
        $P = '1/1';
        break;
    case 1/6:
        $P = '1/6';
        break;
    case 2/6:
        $P = '2/6';
        break;
    case 3/6:
        $P = '3/6';
        break;
    case 4/6:
        $P = '4/6';
        break;
    case 5/6:
        $P = '5/6';
        break;
}

echo $P;
?>