After lessons Nastya decided to read a book. The book contains $$$n$$$ chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page.Yesterday evening Nastya did not manage to finish reading the book, so she marked the page with number $$$k$$$ as the first page which was not read (i.e. she read all pages from the $$$1$$$-st to the $$$(k-1)$$$-th).The next day Nastya's friend Igor came and asked her, how many chapters remain to be read by Nastya? Nastya is too busy now, so she asks you to compute the number of chapters she has not completely read yet (i.e. the number of chapters she has not started to read or has finished reading somewhere in the middle).

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of chapters in the book. There are $$$n$$$ lines then. The $$$i$$$-th of these lines contains two integers $$$l_i$$$, $$$r_i$$$ separated by space ($$$l_1 = 1$$$, $$$l_i \leq r_i$$$) — numbers of the first and the last pages of the $$$i$$$-th chapter. It's guaranteed that $$$l_{i+1} = r_i + 1$$$ for all $$$1 \leq i \leq n-1$$$, and also that every chapter contains at most $$$100$$$ pages. The $$$(n+2)$$$-th line contains a single integer $$$k$$$ ($$$1 \leq k \leq r_n$$$) — the index of the marked page.

Print a single integer — the number of chapters which has not been completely read so far.

NoteIn the first example the book contains $$$11$$$ pages and $$$3$$$ chapters — $$$[1;3]$$$, $$$[4;7]$$$ and $$$[8;11]$$$. Nastya marked the $$$2$$$-nd page, so she finished in the middle of the $$$1$$$-st chapter. So, all chapters has not been read so far, so the answer is $$$3$$$.The book in the second example contains $$$12$$$ pages and $$$3$$$ chapters too, but Nastya finished reading in the middle of the $$$2$$$-nd chapter, so that the answer is $$$2$$$.

<?php
$paragraphs = intval(trim(fgets(STDIN)));
$unreaded = $paragraphs;

while (STDIN && $paragraphs != 0) {
    $paragraph[] = explode(' ', trim(fgets(STDIN)));
    $paragraphs--;
}

$readed = intval(trim(fgets(STDIN)));

$i = 0;
foreach ($paragraph as $val) {
    if (filter_var(
        $readed,
        FILTER_VALIDATE_INT,
        array(
      'options' => array(
          'min_range' => $val[0],
          'max_range' => $val[1]
      )
    )
    )) {
        echo $unreaded - $i . PHP_EOL;
    } else {
        $i++;
    }
}

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

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $chaptersDescription[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
        // echo $inputArray[$i][0] . " : " . $inputArray[$i][1] . "\n";
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 2]);
    // echo $arr[count($arr) - 2] . "\n";
    // echo $unreadPageIndex . "\n";
    // exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

$n = trim(fgets(STDIN));

$r = [];

for($i = 0; $i<$n; $i++){
	$data = explode(' ', trim(fgets(STDIN)));
	$r[] = $data[1];
}

$k = trim(fgets(STDIN));
$c = 0;
for($i = 0; $i<$n; $i++){
	if($k > $r[$i]){
		$c++;
	}
}

fwrite(STDOUT, $n-$c);

?>

<?php
$n = fgets(STDIN);
$array;
for($i = 0; $i < $n; $i++){
    list($array[$i][0], $array[$i][1]) = explode(' ', fgets(STDIN));
}
$k = (int) fgets(STDIN);
for($i = 0; $i < $n; $i++){
    if($array[$i][0] <= $k && $array[$i][1] >= $k){
        $n = $n - $i;
        echo $n;
        return 0;
    }
}
?>

<?php
$n = fgets(STDIN);
$array;
$count = 0;
for($i = 0; $i < $n; $i++){
    list($array[$i][0], $array[$i][1]) = explode(' ', fgets(STDIN));
}
$k = fgets(STDIN);
for($i = 0; $i < $n; $i++){
    if($array[$i][0] <= $k && $array[$i][1] >= $k){
        echo $n - $i;
        return 0;
    }
}
?>

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim(end($arr));
    echo $unreadPageIndex;
    exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 1]);
    echo $unreadPageIndex;
    exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
        echo $inputArray[$i][0] . " : " . $inputArray[$i][1] . "\n";
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 2]);
    // echo $arr[count($arr) - 2] . "\n";
    // echo $unreadPageIndex . "\n";
    // exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    echo "Epta : '" . stream_get_contents($stdin) . "'";
    exit();

    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    $nrChapters = stream_get_contents($dir);
    // $nrChapters = (int)$nrChapters;

    fwrite($stdout, "Epta : '" . $nrChapters . "'");
    exit();

    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 1]);
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 2]);
    // echo $arr[count($arr) - 2] . "\n";
    // echo $unreadPageIndex . "\n";
    // exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    readline($nrChapters);
    readline($sec);
    // $nrChapters = (int)$nrChapters;

    fwrite($stdout, "Epta : '" . $nrChapters . "' | '$sec'");
    exit();

    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 1]);
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim(end($arr));
    echo end($arr) . "\n";
    echo $unreadPageIndex . "\n";
    exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    fread($stdin, $nrChapters);
    fread($stdin, $sec);
    // $nrChapters = (int)$nrChapters;

    fwrite($stdout, "Epta : '" . $nrChapters . "' | '$sec'");
    exit();

    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 1]);
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    fread($stdin, $nrChapters);
    $nrChapters = (int)$nrChapters;

    fwrite($stdout, "Epta : '" . $nrChapters . "'");
    exit();

    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    if ($nrChapters != $nrParams - 2) {
        echo "Wrong number of parameters!";
        exit();
    }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= $chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }

<?php

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

    // $input = $_GET['url'];
    // $inputArray = explode('/', $input);

    // $nrParams = count($inputArray);

    // $nrChapters = (int)$nrChapters;

    $input = stream_get_contents($stdin);

    $arr = preg_split("/\r\n|\n|\r/", $input);

    $nrChapters = (int)$arr[0];

    for($i = 1; $i <= $nrChapters; $i++) {
        $inputArray[$i] = array_map(function($val){ return (int)$val;}, explode(" ", trim($arr[$i])));
    }

    $unreadPageIndex = (int)trim($arr[count($arr) - 2]);
    echo $arr[count($arr) - 2] . "\n";
    echo $unreadPageIndex . "\n";
    exit();
    // for($i = 0; $i < $nrChapters; $i++) {

    // }

    // if ($nrParams < 3) {
    //     echo "There are less parameters than expected!";
    //     exit();
    // }

    // $nrChapters = $inputArray[0];
    // $nrLinesDescribingChapters = $nrParams - 2;
    // $unreadPageIndex = $inputArray[$nrParams - 1];

    // unset($inputArray[0], $inputArray[$nrParams - 1]);

    // if ($nrChapters != $nrParams - 2) {
    //     echo "Wrong number of parameters!";
    //     exit();
    // }

    $chaptersDescription = array_map(
        function ($value) {
            $array = explode(' ', $value);

            return $array;
        },
        $inputArray
    );

    foreach ($chaptersDescription as $index => $chapter) {
        if ($unreadPageIndex <= (int)$chapter[1]) {
            $chaptersRemained = $nrChapters - $index + 1;
            echo $chaptersRemained;
            exit();
        }

        if ($index == $nrChapters){
            echo "Wrong unread page index!";
            exit();
        }
    }


Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible.String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too.

First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≤ k ≤ 26).

Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible.

NoteIn the first test case string contains 6 different letters, so we don't need to change anything.In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}.In the third test case, it is impossible to make 7 different letters because the length of the string is 6.

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if(strlen($a) < $b)
{
     print "impossible";
}
else
{
     $c = array_unique(str_split($a));
     sort($c);
     if(count($c) >= $b)
     {
          print "0";
     }
     else
     {
          print $b - count($c);
     }
}
?>

<?php

$l = trim(fgets(STDIN));
$r = trim(fgets(STDIN));

// base case sanity check
if($r > strlen($l))
{
    echo "impossible";
    exit;
}

$cc = array();
foreach(str_split($l) as $c) {
    if (!isset($cc[$c]))
        $cc[$c] = true;
}

$rr = max(0, $r - sizeof($cc));
echo ($rr);

<?php
$p = fopen('php://stdin', 'r');
$s = trim(fgets($p));
$k = intval(fgets($p));
fclose($p);
if (strlen($s) < $k) {
    echo 'impossible', PHP_EOL; die;
}
$chars = str_split($s);
$distinctLength = count(array_unique($chars));
$missing = $k - $distinctLength;
if ($missing < 0) {
    echo 0, PHP_EOL;
} else {
    echo $missing, PHP_EOL;
}

<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
if(strlen($a) < $b)
{
     print "impossible";
}
else
{
     $c = array_unique(str_split($a));
     sort($c);
     $d = $b - count($c);
     print $d;
}
?>

<?php

$r = trim(fgets(STDIN));
$l = explode("", trim(fgets(STDIN)));

// base case sanity check
if($r > $l)
{
    echo "impossible";
    exit;
}

$cc = array();
foreach($l as $c) {
    if (!isset($cc[$c]))
        $cc[$c] = true;
}

echo ($r - sizeof($cc));

<?php

$l = trim(fgets(STDIN));
$r = trim(fgets(STDIN));

// base case sanity check
if($r > strlen($l))
{
    echo "impossible";
    exit;
}

$cc = array();
foreach(str_split($l) as $c) {
    if (!isset($cc[$c]))
        $cc[$c] = true;
}

echo ($r - sizeof($cc));


Let's call a binary string $$$T$$$ of length $$$m$$$ indexed from $$$1$$$ to $$$m$$$ paranoid if we can obtain a string of length $$$1$$$ by performing the following two kinds of operations $$$m-1$$$ times in any order : Select any substring of $$$T$$$ that is equal to 01, and then replace it with 1. Select any substring of $$$T$$$ that is equal to 10, and then replace it with 0.For example, if $$$T = $$$ 001, we can select the substring $$$[T_2T_3]$$$ and perform the first operation. So we obtain $$$T = $$$ 01.You are given a binary string $$$S$$$ of length $$$n$$$ indexed from $$$1$$$ to $$$n$$$. Find the number of pairs of integers $$$(l, r)$$$ $$$1 \le l \le r \le n$$$ such that $$$S[l \ldots r]$$$ (the substring of $$$S$$$ from $$$l$$$ to $$$r$$$) is a paranoid string.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of $$$S$$$. The second line of each test case contains a binary string $$$S$$$ of $$$n$$$ characters $$$S_1S_2 \ldots S_n$$$. ($$$S_i = $$$ 0 or $$$S_i = $$$ 1 for each $$$1 \le i \le n$$$) It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, output the number of pairs of integers $$$(l, r)$$$ $$$1 \le l \le r \le n$$$ such that $$$S[l \ldots r]$$$ (the substring of $$$S$$$ from $$$l$$$ to $$$r$$$) is a paranoid string.

NoteIn the first sample, $$$S$$$ already has length $$$1$$$ and doesn't need any operations.In the second sample, all substrings of $$$S$$$ are paranoid. For the entire string, it's enough to perform the first operation.In the third sample, all substrings of $$$S$$$ are paranoid except $$$[S_2S_3]$$$, because we can't perform any operations on it, and $$$[S_1S_2S_3]$$$ (the entire string).

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

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

function solve()
{
    $n = IO::getInt();
    $s = IO::getInt();
    $ans = $n;
    for($i=1; $i<$n; $i++) {
         if($s[$i] !=  $s[$i-1]) {
               $ans += $i;
         }
    }

     IO::pr($ans);
}

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

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

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

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

function solve()
{
    $n = IO::getInt();
    $s = IO::getInt();
    $ans = 0;
    $t0 = 0;
    $t1 = 0;
    for($i=0; $i<$n; $i++) {
         if($s[$i] == '0') {
              $t0++;
         } else {
             $t1++;
         }
    }
     $max = IO::getMaxValue($t0, $t1);
     $min = $n - $max;
     $ans = $n;
     if($min > 0) {
         $ans += pow($min, $max);

     }
     IO::pr($ans);
}

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

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

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

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

function solve()
{
    $n = IO::getInt();
    $s = IO::getInt();
    $ans = $n;
    while($n > 1) {
        $sN = '';
        $tt = $n;
         for($i=0; $i<$tt-1; $i++) {
              if($s[$i] == '0' && $s[$i+1] == '1') {
                    $sN .= '1';
                    $n--;
                    $i++;
              } elseif($s[$i] == '1' && $s[$i+1] == '0') {
                  $sN .= '0';
                  $n--;
                    $i++;
              } else {
                 $sN .= $s[$i];
              }
         }
         if($tt == $n) {
              break;
         } else {
              $ans += $tt - $n == 1 ? 1 : ($tt - $n) + 1 ;
              $s = $sN;
         }
    }

     IO::pr($ans);
}

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

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


You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s is a string slsl + 1sl + 2... sr, and its length equals to r - l + 1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring.You have to determine the length of the longest balanced substring of s.

The first line contains n (1 ≤ n ≤ 100000) — the number of characters in s. The second line contains a string s consisting of exactly n characters. Only characters 0 and 1 can appear in s.

If there is no non-empty balanced substring in s, print 0. Otherwise, print the length of the longest balanced substring.

NoteIn the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible.In the second example it's impossible to find a non-empty balanced substring.


The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.There are n stations in the subway. It was built according to the Bertown Transport Law:  For each station i there exists exactly one train that goes from this station. Its destination station is pi, possibly pi = i;  For each station i there exists exactly one station j such that pj = i. The President will consider the convenience of subway after visiting it. The convenience is the number of ordered pairs (x, y) such that person can start at station x and, after taking some subway trains (possibly zero), arrive at station y (1 ≤ x, y ≤ n).The mayor of Bertown thinks that if the subway is not convenient enough, then the President might consider installing a new mayor (and, of course, the current mayor doesn't want it to happen). Before President visits the city mayor has enough time to rebuild some paths of subway, thus changing the values of pi for not more than two subway stations. Of course, breaking the Bertown Transport Law is really bad, so the subway must be built according to the Law even after changes.The mayor wants to do these changes in such a way that the convenience of the subway is maximized. Help him to calculate the maximum possible convenience he can get!

The first line contains one integer number n (1 ≤ n ≤ 100000) — the number of stations. The second line contains n integer numbers p1, p2, ..., pn (1 ≤ pi ≤ n) — the current structure of the subway. All these numbers are distinct.

Print one number — the maximum possible value of convenience.

NoteIn the first example the mayor can change p2 to 3 and p3 to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3).In the second example the mayor can change p2 to 4 and p3 to 5.


Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat! Initially, Alice's cat is located in a cell $$$(x,y)$$$ of an infinite grid. According to Alice's theory, cat needs to move:   exactly $$$a$$$ steps left: from $$$(u,v)$$$ to $$$(u-1,v)$$$;  exactly $$$b$$$ steps right: from $$$(u,v)$$$ to $$$(u+1,v)$$$;  exactly $$$c$$$ steps down: from $$$(u,v)$$$ to $$$(u,v-1)$$$;  exactly $$$d$$$ steps up: from $$$(u,v)$$$ to $$$(u,v+1)$$$. Note that the moves can be performed in an arbitrary order. For example, if the cat has to move $$$1$$$ step left, $$$3$$$ steps right and $$$2$$$ steps down, then the walk right, down, left, right, right, down is valid.Alice, however, is worrying that her cat might get lost if it moves far away from her. So she hopes that her cat is always in the area $$$[x_1,x_2]\times [y_1,y_2]$$$, i.e. for every cat's position $$$(u,v)$$$ of a walk $$$x_1 \le u \le x_2$$$ and $$$y_1 \le v \le y_2$$$ holds.Also, note that the cat can visit the same cell multiple times.Can you help Alice find out if there exists a walk satisfying her wishes?Formally, the walk should contain exactly $$$a+b+c+d$$$ unit moves ($$$a$$$ to the left, $$$b$$$ to the right, $$$c$$$ to the down, $$$d$$$ to the up). Alice can do the moves in any order. Her current position $$$(u, v)$$$ should always satisfy the constraints: $$$x_1 \le u \le x_2$$$, $$$y_1 \le v \le y_2$$$. The staring point is $$$(x, y)$$$.You are required to answer $$$t$$$ test cases independently.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^3$$$) — the number of testcases.  The first line of each test case contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$0 \le a,b,c,d \le 10^8$$$, $$$a+b+c+d \ge 1$$$). The second line of the test case contains six integers $$$x$$$, $$$y$$$, $$$x_1$$$, $$$y_1$$$, $$$x_2$$$, $$$y_2$$$ ($$$-10^8 \le x_1\le x \le x_2 \le 10^8$$$, $$$-10^8 \le y_1 \le y \le y_2 \le 10^8$$$).

For each test case, output "YES" in a separate line, if there exists a walk satisfying her wishes. Otherwise, output "NO" in a separate line.  You can print each letter in any case (upper or lower).

NoteIn the first test case, one valid exercising walk is $$$$$$(0,0)\rightarrow (-1,0) \rightarrow (-2,0)\rightarrow (-2,1) \rightarrow (-2,2)\rightarrow (-1,2)\rightarrow(0,2)\rightarrow (0,1)\rightarrow (0,0) \rightarrow (-1,0)$$$$$$

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

    $t = intval(trim(fgets(STDIN))) ;
    while($t --)
    {
        $in_str = explode(" ", trim(fgets(STDIN))) ;

        for($i = 0; $i < 4; $i ++) $in_str[$i] = intval($in_str[$i]) ;
        list($a, $b, $c, $d) = $in_str ;

        $in_str = explode(" ", trim(fgets(STDIN))) ;
        for($i = 0; $i < 6; $i ++) $in_str[$i] = intval($in_str[$i]) ;

        list($x, $y, $x1, $y1, $x2, $y2) = $in_str ;

        if($a == $b && $b > 0 && $x == $x1 && $x == $x2)
        {
            echo "NO\n" ;
            continue ;
        }
        if($c == $d && $d > 0 && $y == $y1 && $y == $y2)
        {
            echo "NO\n" ;
            continue ;
        }

        $min_a = min($a, $b) ;
        $min_b = min($c, $d) ;

        $a -= $min_a ;
        $b -= $min_a ;

        $c -= $min_b ;
        $d -= $min_b ;

        if($a > 0 && $x - $a < $x1)
        {
            echo "NO\n" ;
            continue ;
        }
        if($b > 0 && $x + $b > $x2)
        {
            echo "NO\n" ;
            continue ;
        }
        if($c > 0 && $y - $c < $y1)
        {
            echo "NO\n" ;
            continue ;
        }
        if($d > 0 && $y + $d > $y2)
        {
            echo "NO\n" ;
            continue ;
        }
        echo "YES\n" ;
    }
?>


There was an electronic store heist last night.All keyboards which were in the store yesterday were numbered in ascending order from some integer number $$$x$$$. For example, if $$$x = 4$$$ and there were $$$3$$$ keyboards in the store, then the devices had indices $$$4$$$, $$$5$$$ and $$$6$$$, and if $$$x = 10$$$ and there were $$$7$$$ of them then the keyboards had indices $$$10$$$, $$$11$$$, $$$12$$$, $$$13$$$, $$$14$$$, $$$15$$$ and $$$16$$$.After the heist, only $$$n$$$ keyboards remain, and they have indices $$$a_1, a_2, \dots, a_n$$$. Calculate the minimum possible number of keyboards that have been stolen. The staff remember neither $$$x$$$ nor the number of keyboards in the store before the heist.

The first line contains single integer $$$n$$$ $$$(1 \le n \le 1\,000)$$$ — the number of  keyboards in the store that remained after the heist. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le 10^{9})$$$ — the indices of the remaining keyboards. The integers $$$a_i$$$ are given in arbitrary order and are pairwise distinct.

Print the minimum possible number of keyboards that have been stolen if the staff remember neither $$$x$$$ nor the number of keyboards in the store before the heist.

NoteIn the first example, if $$$x=8$$$ then minimum number of stolen keyboards is equal to $$$2$$$. The keyboards with indices $$$9$$$ and $$$11$$$ were stolen during the heist.In the second example, if $$$x=4$$$ then nothing was stolen during the heist.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = min($b);
$d = max($b);
$e = $d - $c + 1 - $a;
print $e;
?>

<?php
fscanf(STDIN, "%d", $N);
$a = explode(" ", trim(fgets(STDIN)));

$num = max($a) - min($a) + 1;

echo $num - $N;

<?php

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

$n = fgets($handle);

$list = array_map('intval', explode(' ', trim(fgets($handle))));

sort($list);

$value = 0;
for($i = 0; $i < $n - 1; $i++)
{
	if($list[$i] + 1 != $list[$i + 1])
	{
		$value+=($list[$i + 1] - $list[$i] - 1);
	}
}

echo $value;

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = min($b);
$d = max($b);
$e = range($c, $d - $c + $c);
$f = array_diff($e, $b);
print count($f);
?>

<?php

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

$n = fgets($handle);

$list = array_map('intval', explode(' ', trim(fgets($handle))));

sort($list);

$value = 0;
for($i = 0; $i < $n - 1; $i++)
{
	if($list[$i] + 1 != $list[$i + 1])
	{
		$value++;
	}
}

echo $value;


Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style.Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of consecutive characters in a string) in a given text makes our hero especially joyful. Recently he felt an enormous fit of energy while reading a certain text. So Volodya decided to count all powerful substrings in this text and brag about it all day long. Help him in this difficult task. Two substrings are considered different if they appear at the different positions in the text.For simplicity, let us assume that Volodya's text can be represented as a single string.

Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 106 characters.

Print exactly one number — the number of powerful substrings of the given string. 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.

NoteIn the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful.In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal".

<?php

function FindSubString($string){

    $heavy_positions = FindPosition($string, "heavy");
    $metal_positions = FindPosition($string, "metal");
    $substring       = 0;
    $j               = 0;
    $metal_length    = count($metal_positions);
    //print_r($heavy_positions);echo "\n";
    //print_r($metal_positions);
    for($i=0;$i<count($heavy_positions);$i++){
        if($metal_length>0){
            while ($metal_length>$j && $heavy_positions[$i]>$metal_positions[$j]){
                $j++;
            }
            if($metal_length>$j){
                if($heavy_positions[$i]<$metal_positions[$j]){
                    $substring += $metal_length-$j;
                }
            }
        }
    }
    return $substring;
}

function FindPosition($string,$needle){
    $lastPos = 0;
    $positions = array();

    while (($lastPos = strpos($string, $needle, $lastPos))!== false) {
        $positions[] = $lastPos;
        $lastPos = $lastPos + strlen($needle);
    }
    return $positions;
}

$string      = trim(fgets(STDIN));
echo FindSubString($string);

<?

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

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

$str = trim(fgets($handle));

//set_time_limit(3);

$c = 0;
$hh = 0;
$mm = 0;

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

    if (h($str, $i)) {
        $hh++;
    }

    if (m($str, $i)) {
        $mm++;
        $c += $hh;
    }
}

function h($str, $ind){
    $t = "heavy";
    for($i=0; $i<5; $i++) {

        if($t[$i] != $str[$i + $ind]) return false;
    }
    return true;
}

function m($str, $ind){
    $t = "metal";
    for($i=$ind; $i<$ind+5; $i++) if($t[$i-$ind]!=$str[$i]) return false;
    return true;
}

echo $c;

?>


Boboniu likes bit operations. He wants to play a game with you.Boboniu gives you two sequences of non-negative integers $$$a_1,a_2,\ldots,a_n$$$ and $$$b_1,b_2,\ldots,b_m$$$.For each $$$i$$$ ($$$1\le i\le n$$$), you're asked to choose a $$$j$$$ ($$$1\le j\le m$$$) and let $$$c_i=a_i\& b_j$$$, where $$$\&$$$ denotes the bitwise AND operation. Note that you can pick the same $$$j$$$ for different $$$i$$$'s.Find the minimum possible $$$c_1 | c_2 | \ldots | c_n$$$, where $$$|$$$ denotes the bitwise OR operation.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1\le n,m\le 200$$$). The next line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$0\le a_i < 2^9$$$). The next line contains $$$m$$$ integers $$$b_1,b_2,\ldots,b_m$$$ ($$$0\le b_i < 2^9$$$).

Print one integer: the minimum possible $$$c_1 | c_2 | \ldots | c_n$$$.

<?php
fscanf(STDIN,"%d %d", $n, $m);
$a = explode(' ', fgets(STDIN));
$b = explode(' ', fgets(STDIN));
for($i=0;$i<$n;++$i)$a[$i]=(int)$a[$i];
for($i=0;$i<$m;++$i)$b[$i]=(int)$b[$i];
function strtoint($s){
    return (int)$s;
}
for($i=0;$i<$n;++$i){
    $a[$i]=strtoint($a[$i]);
}
for($i=0;$i<$m;++$i){
    $b[$i]=strtoint($b[$i]);
}

for($t=0;$t<512;++$t){
    $ans=true;
    foreach($a as $x){
        $ok=false;
        foreach($b as $y){
            if(($x & $y & ~$t) == 0){
                $ok=true;
                break;
            }
        }
        if(!$ok){
            $ans=false;
            break;
        }
    }

    if($ans){
        echo "$t\n";
        return 0;
    }
}
?>

<?php
$in = fopen('php://stdin','r');
fscanf($in,"%d %d", $n, $m);
$a = explode(' ', fgets($in));
$b = explode(' ', fgets($in));

for($t=0;$t<512;++$t){
    $ans=true;
    foreach($a as $x){
        $ok=false;
        foreach($b as $y){
            if(($x & $y & ~$t) == 0){
                $ok=true;
                break;
            }
        }
        if(!$ok){
            $ans=false;
            break;
        }
    }

    if($ans){
        echo "$t\n";
        return 0;
    }
}
?>


Let's call a positive integer $$$n$$$ ordinary if in the decimal notation all its digits are the same. For example, $$$1$$$, $$$2$$$ and $$$99$$$ are ordinary numbers, but $$$719$$$ and $$$2021$$$ are not ordinary numbers.For a given number $$$n$$$, find the number of ordinary numbers among the numbers from $$$1$$$ to $$$n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. Each test case is characterized by one integer $$$n$$$ ($$$1 \le n \le 10^9$$$).

For each test case output the number of ordinary numbers among numbers from $$$1$$$ to $$$n$$$.

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

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

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

  if ($n < 10) { echo $n.PHP_EOL; }
  else {
    if ($n == 10) { echo '9'.PHP_EOL; }
    else {
      $len = strlen($n);
      if ($len >= 2) { $ans = 9 * ($len - 1); }

      $s = (string) $n;
      $f = $s[0];
      $m = '';
      for ($j = 0; $j < $len; $j++) { $m .= $f; }

      if ($m > $n) { $ans += $f - 1; }
      else { $ans += $f; }

      echo $ans.PHP_EOL;
    }
  }
}

?>

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }

    public static function res($res) {
        foreach ($res as $r) {
            echo $r . "\n";
        }
    }

    public static function dd($val){
        echo $val; exit;
    }
}

$nums = array(
    2 => 9,
    3 => 18,
    4 => 27,
    5 => 36,
    6 => 45,
    7 => 54,
    8 => 63,
    9 => 72,
    10 => 81,
    11 => 90,
);

$t = IO::str();

function makeDel($q)
{
    $s = '';
    while($q--) {
        $s .= '1';
    }
    return $s;
}
while($t--){
    $n = IO::str();

    if ($n < 10) {
        $res[] = $n;
        continue;
    }

    $s = $nums[strlen($n)];
    $del = makeDel(strlen($n));

    while($n >= $del) {
        $s++;
        $n = $n - $del;
    }

    $res[] = $s;
}

IO::res($res);

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
}

//$iQueryCount = 1;
$iQueryCount = IO::str();

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $l = strlen($n);
    $last = 1;
    $res = 0;
    for ($i = 1; $i < 10; $i++) {
        $r = '';
        for ($j = 0; $j < $l; $j++) {
            $r .= $i;
            if ((int)$r <= $n) {
                $res++;
                $last = (int)$r + 1;
            }
        }
    }

    IO::line($res);
}

?>

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

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

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

  if ($n < 10) { echo $n.PHP_EOL; }
  else {
    if ($n == 10) { echo '9'.PHP_EOL; }
    else {
      $len = strlen($n);
      if ($len >= 2) { $ans = 9 * ($len - 1); }

      $s = (string) $n;
      $f = $s[0];
      $m = '';
      for ($j = 0; $j < $len; $j++) { $m .= $f; }

      if ($m > $v[$i]) { $ans += $f - 1; }
      else { $ans += $f; }
      echo $ans.PHP_EOL;
    }
  }
}

?>

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

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

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

  if ($n < 10) { echo $n.PHP_EOL; }
  else {
    if ($n == 10) { echo '9'.PHP_EOL; }
    else {
      $len = strlen($n);
      if ($len > 2) { $ans = 9 * ($len - 1); }

      $s = (string) $n;
      $f = $s[0];
      $m = '';
      for ($j = 0; $j < $len; $j++) { $m .= $f; }

      if ($m > $v[$i]) { $ans += $f - 1; }
      else { $ans += $f; }
      echo $ans.PHP_EOL;
    }
  }
}

?>

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

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

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

  if ($n < 10) { echo $n.PHP_EOL; }
  else {
    $ans = 9;
    $len = strlen($n);
    if ($len > 2) { $ans += 9 * ($len - 2); }

    $s = (string) $n;
    $f = $s[0];
    $m = '';
    for ($j = 0; $j < $len; $j++) { $m .= $f; }

    if ($m > $v[$i]) { $ans += $f - 1; }
    else { $ans += $f; }
    echo $ans.PHP_EOL;
  }
}

?>

<?php
class IO {
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }

    public static function res($res) {
        foreach ($res as $r) {
            echo $r . "\n";
        }
    }

    public static function dd($val){
        echo $val; exit;
    }
}

$nums = array(
    2 => 9,
    3 => 18,
    4 => 27,
    5 => 36,
    6 => 45,
    7 => 54,
    8 => 63,
    9 => 72,
    10 => 81,
    11 => 90,
);

$t = IO::str();

function makeDel($q)
{
    $s = '';
    while($q--) {
        $s .= '1';
    }
    return $s;
}
while($t--){
    $n = IO::str();

    if ($n < 10) {
        $res[] = $n;
        continue;
    }

    $s = $nums[strlen($n)];
    $del = makeDel(strlen($n));

    while($n > $del) {
        $s++;
        $n = $n - $del;
    }

    $res[] = $s;
}

IO::res($res);


You are given two arrays $$$a$$$ and $$$b$$$ of $$$n$$$ positive integers each. You can apply the following operation to them any number of times:  Select an index $$$i$$$ ($$$1\leq i\leq n$$$) and swap $$$a_i$$$ with $$$b_i$$$ (i. e. $$$a_i$$$ becomes $$$b_i$$$ and vice versa). Find the minimum possible value of $$$\max(a_1, a_2, \ldots, a_n) \cdot \max(b_1, b_2, \ldots, b_n)$$$ you can get after applying such operation any number of times (possibly zero).

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1\le n\le 100$$$) — the length of the arrays. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10\,000$$$) where $$$a_i$$$ is the $$$i$$$-th element of the array $$$a$$$. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 10\,000$$$) where $$$b_i$$$ is the $$$i$$$-th element of the array $$$b$$$.

For each test case, print a single integer, the minimum possible value of $$$\max(a_1, a_2, \ldots, a_n) \cdot \max(b_1, b_2, \ldots, b_n)$$$ you can get after applying such operation any number of times.

NoteIn the first test, you can apply the operations at indices $$$2$$$ and $$$6$$$, then $$$a = [1, 4, 6, 5, 1, 5]$$$ and $$$b = [3, 2, 3, 2, 2, 2]$$$, $$$\max(1, 4, 6, 5, 1, 5) \cdot \max(3, 2, 3, 2, 2, 2) = 6 \cdot 3 = 18$$$.In the second test, no matter how you apply the operations, $$$a = [3, 3, 3]$$$ and $$$b = [3, 3, 3]$$$ will always hold, so the answer is $$$\max(3, 3, 3) \cdot \max(3, 3, 3) = 3 \cdot 3 = 9$$$.In the third test, you can apply the operation at index $$$1$$$, then $$$a = [2, 2]$$$, $$$b = [1, 1]$$$, so the answer is $$$\max(2, 2) \cdot \max(1, 1) = 2 \cdot 1 = 2$$$.

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

  for($q=0; $q <$t; $q++) {
      $new = [];
      $n = trim(fgets(STDIN));
      $a = explode(' ', trim(fgets(STDIN)));
      $b = explode(' ', trim(fgets(STDIN)));
      //sort($a);
      $max = $a[0];
      $new = array_merge($a, $b);
      sort($new);

     $m = $n * 2 - 1;
     $m1 = $n-1;
     if($n > 2) {
         echo $new[$m] * $new[$n]. "\n";
     } else {
          echo $new[$m] * $new[$m1]. "\n";
     }

  }

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

  for($q=0; $q <$t; $q++) {
      $n = trim(fgets(STDIN));
      $a = explode(' ', trim(fgets(STDIN)));
      $b = explode(' ', trim(fgets(STDIN)));
      //sort($a);
      $max = $a[0];
      $new = array_merge($a, $b);
      sort($new);

      echo $new[$n * 2 -1] * $new[$n-1]. "\n";

  }


Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k.Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them.

The single line contains two integers, n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000).

Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them.

NoteIn the first sample the sum in the first row is 1 + 3 = 4, in the second row — 3 + 1 = 4, in the first column — 1 + 3 = 4 and in the second column — 3 + 1 = 4. There are other beautiful tables for this sample.In the second sample the sum of elements in each row and each column equals 7. Besides, there are other tables that meet the statement requirements.

<?php

$line = array_map('intval',explode(' ', trim(fgets(STDIN))));
$n = $line[0];
$k = $line[1];

for ($i = 0; $i < $n; $i++) {
	for ($j = 0; $j < $n; $j++) {
		if ($i == $j) {
			echo $k." ";
		}
		else {
			echo "0 ";
		}
	}
	echo "\n";
}


Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of tokens but he can't use it in any other day to get more money. If a worker gives back w tokens then he'll get  dollars. Mashmokh likes the tokens however he likes money more. That's why he wants to save as many tokens as possible so that the amount of money he gets is maximal possible each day. He has n numbers x1, x2, ..., xn. Number xi is the number of tokens given to each worker on the i-th day. Help him calculate for each of n days the number of tokens he can save.

The first line of input contains three space-separated integers n, a, b (1 ≤ n ≤ 105; 1 ≤ a, b ≤ 109). The second line of input contains n space-separated integers x1, x2, ..., xn (1 ≤ xi ≤ 109).

Output n space-separated integers. The i-th of them is the number of tokens Mashmokh can save on the i-th day.

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

list($n,$a,$b) = explode(' ', trim(fgets(MY_STDIN)));
$ww = explode(' ', trim(fgets(MY_STDIN)));
$res = array_fill(0, $n, 0);
for ($i = 0; $i < $n; $i++) {
    $wa = bcmul($ww[$i], $a);
    $x = bcdiv($wa, $b, 0);
    $xb = bcmul($x, $b);
    $r = bcsub($wa, $xb);
    $ws = bcdiv($r, $a, 0);
    $res[$i] = $ws;
}

echo join(' ', $res);

<?PHP

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

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

$n = $line[0];
$a = $line[1];
$b = $line[2];

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

for ($i = 0; $i < $n; ++$i) {
    fprintf($fileOUT, (int) (fmod($line[$i] * $a, $b) / $a) . " ");
}

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

?>

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

list($n,$a,$b) = explode(' ', trim(fgets(MY_STDIN)));
$x = explode(' ', trim(fgets(MY_STDIN)));
$res = array_fill(0, $n, 0);
for ($i = 0; $i < $n; $i++) {
    $aa = bcmod(bcmul($a, $x[$i]), $b);
    $res[$i] = $aa;
}

echo join(' ', $res);

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

list($n,$a,$b) = explode(' ', trim(fgets(MY_STDIN)));
$x = explode(' ', trim(fgets(MY_STDIN)));
$res = array_fill(0, $n, 0);
for ($i = 0; $i < $n; $i++) {
    $aa = bcmod($x[$i], $b);
    $res[$i] = $aa;
}

echo join(' ', $res);

<?PHP

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

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

$n = $line[0];
$a = $line[1];
$b = $line[2];

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

for ($i = 0; $i < $n; ++$i) {
    fprintf($fileOUT, ((int) ((int) $line[$i] * (int) $a) % (int) $b / (int) $a) . " ");
}

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

?>

<?PHP

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

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

$n = $line[0];
$a = $line[1];
$b = $line[2];

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

for ($i = 0; $i < $n; ++$i) {
    fprintf($fileOUT, floor((float) (($line[$i] * $a) % $b) / (int) $a) . " ");
}

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

?>

<?PHP

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

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

$n = $line[0];
$a = $line[1];
$b = $line[2];

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

for ($i = 0; $i < $n; ++$i) {
    fprintf($fileOUT, (int) ((int) ($line[$i] * $a) % (int) $b / (int) $a) . " ");
}

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

?>

<?PHP

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

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

$n = $line[0];
$a = $line[1];
$b = $line[2];

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

for ($i = 0; $i < $n; ++$i) {
    fprintf($fileOUT, (($line[$i] * $a) % $b / $a) . " ");
}

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

?>


«Next please», — the princess called and cast an estimating glance at the next groom.The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous ones added together, she exclaims «Wow!» (no «Oh...» in this case). At the sight of the first groom the princess stays calm and says nothing.The fortune of each groom is described with an integer between 1 and 50000. You know that during the day the princess saw n grooms, said «Oh...» exactly a times and exclaimed «Wow!» exactly b times. Your task is to output a sequence of n integers t1, t2, ..., tn, where ti describes the fortune of i-th groom. If several sequences are possible, output any of them. If no sequence exists that would satisfy all the requirements, output a single number -1.

The only line of input data contains three integer numbers n, a and b (1 ≤ n ≤ 100, 0 ≤ a, b ≤ 15, n > a + b), separated with single spaces.

Output any sequence of integers t1, t2, ..., tn, where ti (1 ≤ ti ≤ 50000) is the fortune of i-th groom, that satisfies the given constraints. If no sequence exists that would satisfy all the requirements, output a single number -1.

NoteLet's have a closer look at the answer for the first sample test.   The princess said «Oh...» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.  The princess exclaimed «Wow!» (highlighted in bold): 5 1 3 6 16 35 46 4 200 99.

<?php
class Token {
	private $token;
	private $tok;

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

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$n = $Token->nextInt();
	$a = $Token->nextInt();
	$b = $Token->nextInt();

	if ($a === $n - 1 && $n != 1) {
		printf("%d",-1);
		return;
	} elseif ($b === 0 && $a !== 0) {
		$array_a = array(1, 1,);
		for ($i = 2; $i < $a + 2; $i++) {
			$array_a[] = $i;
		}

		$num = $n - count($array_a);
		//$array_a = array_fill(count($array_a) - 1, $n - $a - 2, (int)1);
		//for ($i = 0; $i < $n - count($array_a); $i++) {
		for ($i = 0; $i < $num; $i++) {
			$array_a[] = 1;
		}
		array_printf($array_a);
		return;
	}
	//this is for more reading.really array() is not useful.
	$arr = array();
	$arr[] = 1;
	for ($i = 0; $i < $b; $i++) {
		$arr[] = array_sum($arr) + 1;
	}
	//for ($i = 1; $i <= $a; $i++) {
	//array_pop not get, pop.so number - 1.
	//$begin = array_pop(&$arr);

//test coding
//printf("%d\n",(int)$arr[count($arr)]);
//printf("%d\n",(int)null);

	$begin = $arr[count($arr) - 1];
	for ($i = $begin + 1; $i < $a + $begin + 1; $i++) {
		//$arr[] = $i + 1;
		$arr[] = $i;
	}
	//for ($i = 0; $i < $b - 1; $i++) {
		//$arr[] = array_sum($arr) + 1;
	//}
	for ($i = 0; $i < $n - ($a + $b + 1); $i++) {
		$arr[] = 1;
	}
	array_printf($arr);
}

function run(){
	solve();
}

ob_end_clean();
run();
?>

<?php
class Token {
	private $token;
	private $tok;

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

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$n = $Token->nextInt();
	$a = $Token->nextInt();
	$b = $Token->nextInt();

	if ($a === $n - 1) {
		printf("%d",-1);
		return;
	} elseif ($b === 0 && $a !== 0) {
		$array_a = array(1, 1,);
		for ($i = 2; $i < $a + 2; $i++) {
			$array_a[] = $i;
		}

		$num = $n - count($array_a);
		//$array_a = array_fill(count($array_a) - 1, $n - $a - 2, (int)1);
		//for ($i = 0; $i < $n - count($array_a); $i++) {
		for ($i = 0; $i < $num; $i++) {
			$array_a[] = 1;
		}
		array_printf($array_a);
		return;
	}
	//this is for more reading.really array() is not useful.
	$arr = array();
	$arr[] = 1;
	for ($i = 0; $i < $b; $i++) {
		$arr[] = array_sum($arr) + 1;
	}
	//for ($i = 1; $i <= $a; $i++) {
	//array_pop not get, pop.so number - 1.
	//$begin = array_pop(&$arr);

//test coding
//printf("%d\n",(int)$arr[count($arr)]);
//printf("%d\n",(int)null);

	$begin = $arr[count($arr) - 1];
	for ($i = $begin + 1; $i < $a + $begin + 1; $i++) {
		//$arr[] = $i + 1;
		$arr[] = $i;
	}
	//for ($i = 0; $i < $b - 1; $i++) {
		//$arr[] = array_sum($arr) + 1;
	//}
	for ($i = 0; $i < $n - ($a + $b + 1); $i++) {
		$arr[] = 1;
	}
	array_printf($arr);
}

function run(){
	solve();
}

ob_end_clean();
run();
?>

<?php
class Token {
	private $token;
	private $tok;

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$n = $Token->nextInt();
	$a = $Token->nextInt();
	$b = $Token->nextInt();

	//this is for more reading.really array() is not useful.
	$arr = array();
	$arr[] = 1;
	//for ($i = 1; $i <= $a; $i++) {
	for ($i = 1; $i < $a + 2; $i++) {
		$arr[] = $i + 1;
	}
	for ($i = 0; $i < $b - 1; $i++) {
		$arr[] = array_sum($arr) + 1;
	}
	for ($i = 0; $i < $n - ($a + $b + 1); $i++) {
		$arr[] = 1;
	}
	$message = "";
	foreach ($arr as $value) {
		$message .= "$value" . " ";
	}
	$message = rtrim($message);
	printf('%s', $message);
}

function run(){
	solve();
}

ob_end_clean();
run();
?>

<?php
class Token {
	private $token;
	private $tok;

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$n = $Token->nextInt();
	$a = $Token->nextInt();
	$b = $Token->nextInt();

	//this is for more reading.really array() is not useful.
	$arr = array();
	$arr[] = 1;
	//for ($i = 1; $i <= $a; $i++) {
	for ($i = 2; $i <= ($a + 1); $i++) {
		$arr[] = $i + 1;
	}
	for ($i = 0; $i < $b; $i++) {
		$arr[] = array_sum($arr) + 1;
	}
	for ($i = 0; $i < $n - ($a + $b); $i++) {
		$arr[] = 1;
	}
	$message = "";
	foreach ($arr as $value) {
		$message .= "$value" . " ";
	}
	$message = rtrim($message);
	printf('%s', $message);
}

function run(){
	solve();
}

ob_end_clean();
run();
?>

<?php
class Token {
	private $token;
	private $tok;

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$n = $Token->nextInt();
	$a = $Token->nextInt();
	$b = $Token->nextInt();

	//this is for more reading.really array() is not useful.
	$arr = array();
	$arr[] = 1;
	for ($i = 1; $i <= $a; $i++) {
		$arr[] = $i + 1;
	}
	for ($i = 0; $i < $b; $i++) {
		$arr[] = array_sum($arr) + 1;
	}
	for ($i = 0; $i < $n - ($a + $b); $i++) {
		$arr[] = 1;
	}
	$message = "";
	foreach ($arr as $value) {
		$message .= "$value" . " ";
	}
	$message = rtrim($message);
	printf('%s', $message);
}

function run(){
	solve();
}

ob_end_clean();
run();
?>

<?php
class Token {
	private $token;
	private $tok;

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$n = $Token->nextInt();
	$a = $Token->nextInt();
	$b = $Token->nextInt();

	//this is for more reading.really array() is not useful.
	$arr = array();
	$arr[] = 1;
	//for ($i = 1; $i <= $a; $i++) {
	for ($i = 2; $i <= ($a + 2); $i++) {
		$arr[] = $i + 1;
	}
	for ($i = 0; $i < $b - 1; $i++) {
		$arr[] = array_sum($arr) + 1;
	}
	for ($i = 0; $i < $n - ($a + $b); $i++) {
		$arr[] = 1;
	}
	$message = "";
	foreach ($arr as $value) {
		$message .= "$value" . " ";
	}
	$message = rtrim($message);
	printf('%s', $message);
}

function run(){
	solve();
}

ob_end_clean();
run();
?>

<?php
class Token {
	private $token;
	private $tok;

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$n = $Token->nextInt();
	$a = $Token->nextInt();
	$b = $Token->nextInt();

	//this is for more reading.really array() is not useful.
	$arr = array();
	$arr[] = 1;
	for ($i = 0; $i < $b; $i++) {
		$arr[] = array_sum($arr) + 1;
	}
	//for ($i = 1; $i <= $a; $i++) {
	$begin = array_sum($arr);
	for ($i = $begin; $i < $a + $begin; $i++) {
		$arr[] = $i + 1;
	}
	//for ($i = 0; $i < $b - 1; $i++) {
		//$arr[] = array_sum($arr) + 1;
	//}
	for ($i = 0; $i < $n - ($a + $b + 1); $i++) {
		$arr[] = 1;
	}
	$message = "";
	foreach ($arr as $value) {
		$message .= "$value" . " ";
	}
	$message = rtrim($message);
	printf('%s', $message);
}

function run(){
	solve();
}

ob_end_clean();
run();
?>

<?php
class Token {
	private $token;
	private $tok;

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$n = $Token->nextInt();
	$a = $Token->nextInt();
	$b = $Token->nextInt();

	//this is for more reading.really array() is not useful.
	$arr = array();
	//$arr[] = 1;
	$arr[] = 2;
	//for ($i = 1; $i <= $a; $i++) {
	for ($i = 2; $i <= ($a + 1); $i++) {
		$arr[] = $i + 1;
	}
	for ($i = 0; $i < $b; $i++) {
		$arr[] = array_sum($arr) + 1;
	}
	for ($i = 0; $i < $n - ($a + $b); $i++) {
		$arr[] = 1;
	}
	$message = "";
	foreach ($arr as $value) {
		$message .= "$value" . " ";
	}
	$message = rtrim($message);
	printf('%s', $message);
}

function run(){
	solve();
}

ob_end_clean();
run();
?>

<?php
class Token {
	private $token;
	private $tok;

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$n = $Token->nextInt();
	$a = $Token->nextInt();
	$b = $Token->nextInt();

	//this is for more reading.really array() is not useful.
	$arr = array();
	$arr[] = 1;
	for ($i = 0; $i < $b; $i++) {
		$arr[] = array_sum($arr) + 1;
	}
	//for ($i = 1; $i <= $a; $i++) {
	//array_pop not get, pop.so number - 1.
	//$begin = array_pop(&$arr);

//test coding
//printf("%d\n",(int)$arr[count($arr)]);
//printf("%d\n",(int)null);

	$begin = $arr[count($arr) - 1];
	for ($i = $begin + 1; $i < $a + $begin + 1; $i++) {
		//$arr[] = $i + 1;
		$arr[] = $i;
	}
	//for ($i = 0; $i < $b - 1; $i++) {
		//$arr[] = array_sum($arr) + 1;
	//}
	for ($i = 0; $i < $n - ($a + $b + 1); $i++) {
		$arr[] = 1;
	}
	$message = "";
	foreach ($arr as $value) {
		$message .= "$value" . " ";
	}
	$message = rtrim($message);
	printf('%s', $message);
}

function run(){
	solve();
}

ob_end_clean();
run();
?>

<?php
class Token {
	private $token;
	private $tok;

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

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

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

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

function solve(){

/* basic coding (this code is not best, because changing token and float is not good)
	$vp = (float)strtok(rtrim(fgets(STDIN, 10), "\n"), " ");
	$vd = (float)strtok(" ");
	$t = (float)strtok(" ");
	$f = (float)strtok(" ");
	$c = (float)strtok(" ");
*/
	//use Token class(advatage of using this class is changing token and float is more easy)
	//$Token = new Token(rtrim(fgets(STDIN, 5), "\n"), " ");
	$Token = new Token(rtrim(fgets(STDIN), "\n"), " ");
	$n = $Token->nextInt();
	$a = $Token->nextInt();
	$b = $Token->nextInt();

	if ($b === 0 && $a !== 0) {
		printf("%d",-1);
		return;
	}
	//this is for more reading.really array() is not useful.
	$arr = array();
	$arr[] = 1;
	for ($i = 0; $i < $b; $i++) {
		$arr[] = array_sum($arr) + 1;
	}
	//for ($i = 1; $i <= $a; $i++) {
	//array_pop not get, pop.so number - 1.
	//$begin = array_pop(&$arr);

//test coding
//printf("%d\n",(int)$arr[count($arr)]);
//printf("%d\n",(int)null);

	$begin = $arr[count($arr) - 1];
	for ($i = $begin + 1; $i < $a + $begin + 1; $i++) {
		//$arr[] = $i + 1;
		$arr[] = $i;
	}
	//for ($i = 0; $i < $b - 1; $i++) {
		//$arr[] = array_sum($arr) + 1;
	//}
	for ($i = 0; $i < $n - ($a + $b + 1); $i++) {
		$arr[] = 1;
	}
	$message = "";
	foreach ($arr as $value) {
		$message .= "$value" . " ";
	}
	$message = rtrim($message);
	printf('%s', $message);
}

function run(){
	solve();
}

ob_end_clean();
run();
?>


You are given an array $$$a$$$ of length $$$n$$$. We define the equality of the array as the number of indices $$$1 \le i \le n - 1$$$ such that $$$a_i = a_{i + 1}$$$. We are allowed to do the following operation:  Select two integers $$$i$$$ and $$$x$$$ such that $$$1 \le i \le n - 1$$$ and $$$1 \le x \le 10^9$$$. Then, set $$$a_i$$$ and $$$a_{i + 1}$$$ to be equal to $$$x$$$. Find the minimum number of operations needed such that the equality of the array is less than or equal to $$$1$$$.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10 ^ 5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10 ^ 5$$$

For each test case, print the minimum number of operations needed.

NoteIn the first test case, we can select $$$i=2$$$ and $$$x=2$$$ to form $$$[1, 2, 2, 1, 1]$$$. Then, we can select $$$i=3$$$ and $$$x=3$$$ to form $$$[1, 2, 3, 3, 1]$$$.In the second test case, we can select $$$i=3$$$ and $$$x=100$$$ to form $$$[2, 1, 100, 100, 2]$$$.

<?php

//take input from user of test cast t
$t = (int)fgets(STDIN);

// while test case

while($t--){
    // take input n
    $n = (int)fgets(STDIN);
    // take input array
    $arr = explode(" ", trim(fgets(STDIN)));
    //print the array

    $f=$n;
    $l=0;

    for($i=1;$i<$n;$i++){
        if($arr[$i]==$arr[$i-1]){
            $f=$i;
            break;
        }
    }

    for($i=$n-1;$i>=1;$i--){
        if($arr[$i]==$arr[$i-1]){
            $l=$i;
            break;
        }
    }

    if($l-$f>0){
        if($l-$f==1){ echo "1\n";}
        else{
            $z=$l-$f-1;
            echo $z."\n";
        }
    }else{
        echo "0\n";
    }
}


Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: An 'L' indicates he should move one unit left.  An 'R' indicates he should move one unit right.  A 'U' indicates he should move one unit up.  A 'D' indicates he should move one unit down.But now Memory wants to end at the origin. To do this, he has a special trident. This trident can replace any character in s with any of 'L', 'R', 'U', or 'D'. However, because he doesn't want to wear out the trident, he wants to make the minimum number of edits possible. Please tell Memory what is the minimum number of changes he needs to make to produce a string that, when walked, will end at the origin, or if there is no such string.

The first and only line contains the string s (1 ≤ |s| ≤ 100 000) — the instructions Memory is given.

If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1.

NoteIn the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change s to "LDUR". This string uses 1 edit, which is the minimum possible. It also ends at the origin.

<?php

// "მე ამის პირობა ვერ გავიგე, მეხი არი რამე?"

$in = trim(fgets(STDIN));

$a = 0;
$b = 0;

for($i=0;$i<strlen($in);$i++)
    if($in[$i]=='L')
        $a++;
    else if($in[$i]=='R')
        $a--;
    else if($in[$i]=='U')
        $b--;
    else if($in[$i]=='D')
        $b++;

    $ortave = abs($a) + abs($b);

    if($ortave&1)
        echo -1;
    else
        echo $ortave>>1;

?>

<?php

// "მე ამის პირობა ვერ გავიგე, მეხი არი რამე?"

$in = fgets(STDIN);

$a = 0;
$b = 0;

for($i=0;$i<strlen($in);$i++)
    if($in[$i]=='L')
        $a--;
    else if($in[$i]=='R')
        $a--;
    else if($in[$i]=='U')
        $b--;
    else
        $b++;

    $ortave = abs($a) + abs($b);

    if($ortave&1)
        echo -1;
    else
        echo $ortave>>1;

?>

<?php

// "მე ამის პირობა ვერ გავიგე, მეხი არი რამე?"

$in = fgets(STDIN);

$a = 0;
$b = 0;

for($i=0;$i<strlen($in);$i++)
    if($in[$i]=='L')
        $a--;
    elseif($in[$i]=='R')
        $a--;
    elseif($in[$i]=='U')
        $b--;
    else
        $b++;

    $ortave = abs($a) + abs($b);

    if($ortave%2==1)
        echo -1;
    else
        echo $ortave/2;

?>

<?php

// "მე ამის პირობა ვერ გავიგე, მეხი არი რამე?"

$in = trim(fgets(STDIN));

$a = 0;
$b = 0;

for($i=0;$i<strlen($in);$i++)
    if($in[$i]=='L')
        $a--;
    else if($in[$i]=='R')
        $a--;
    else if($in[$i]=='U')
        $b--;
    else
        $b++;

    $ortave = abs($a) + abs($b);

    if($ortave&1)
        echo -1;
    else
        echo $ortave>>1;

?>

<?php

// "მე ამის პირობა ვერ გავიგე, მეხი არი რამე?"

$in = fgets(STDIN);

$a = 0;
$b = 0;

for($i=0;$i<strlen($in);$i++)
    if($in[$i]=='L')
        $a--;
    elseif($in[$i]=='R')
        $a--;
    elseif($in[$i]=='U')
        $b--;
    else
        $b++;

    $ortave = abs($a) + abs($b);

    if($ortave&1)
        echo -1;
    else
        echo $ortave>>1;

?>


Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions. There are m days left to the birthday. The height of the i-th flower (assume that the flowers in the row are numbered from 1 to n from left to right) is equal to ai at the moment. At each of the remaining m days the beaver can take a special watering and water w contiguous flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?

The first line contains space-separated integers n, m and w (1 ≤ w ≤ n ≤ 105; 1 ≤ m ≤ 105). The second line contains space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Print a single integer — the maximum final height of the smallest flower.

NoteIn the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It's impossible to get height 3 in this test.


Kuroni has $$$n$$$ daughters. As gifts for them, he bought $$$n$$$ necklaces and $$$n$$$ bracelets:  the $$$i$$$-th necklace has a brightness $$$a_i$$$, where all the $$$a_i$$$ are pairwise distinct (i.e. all $$$a_i$$$ are different),  the $$$i$$$-th bracelet has a brightness $$$b_i$$$, where all the $$$b_i$$$ are pairwise distinct (i.e. all $$$b_i$$$ are different). Kuroni wants to give exactly one necklace and exactly one bracelet to each of his daughters. To make sure that all of them look unique, the total brightnesses of the gifts given to each daughter should be pairwise distinct. Formally, if the $$$i$$$-th daughter receives a necklace with brightness $$$x_i$$$ and a bracelet with brightness $$$y_i$$$, then the sums $$$x_i + y_i$$$ should be pairwise distinct. Help Kuroni to distribute the gifts.For example, if the brightnesses are $$$a = [1, 7, 5]$$$ and $$$b = [6, 1, 2]$$$, then we may distribute the gifts as follows:  Give the third necklace and the first bracelet to the first daughter, for a total brightness of $$$a_3 + b_1 = 11$$$. Give the first necklace and the third bracelet to the second daughter, for a total brightness of $$$a_1 + b_3 = 3$$$. Give the second necklace and the second bracelet to the third daughter, for a total brightness of $$$a_2 + b_2 = 8$$$. Here is an example of an invalid distribution:   Give the first necklace and the first bracelet to the first daughter, for a total brightness of $$$a_1 + b_1 = 7$$$. Give the second necklace and the second bracelet to the second daughter, for a total brightness of $$$a_2 + b_2 = 8$$$. Give the third necklace and the third bracelet to the third daughter, for a total brightness of $$$a_3 + b_3 = 7$$$. This distribution is invalid, as the total brightnesses of the gifts received by the first and the third daughter are the same. Don't make them this upset!

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$)  — the number of daughters, necklaces and bracelets. The second line of each test case contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 1000$$$)  — the brightnesses of the necklaces. The third line of each test case contains $$$n$$$ distinct integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 1000$$$)  — the brightnesses of the bracelets.

For each test case, print a line containing $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$, representing that the $$$i$$$-th daughter receives a necklace with brightness $$$x_i$$$. In the next line print $$$n$$$ integers $$$y_1, y_2, \dots, y_n$$$, representing that the $$$i$$$-th daughter receives a bracelet with brightness $$$y_i$$$. The sums $$$x_1 + y_1, x_2 + y_2, \dots, x_n + y_n$$$ should all be distinct. The numbers $$$x_1, \dots, x_n$$$ should be equal to the numbers $$$a_1, \dots, a_n$$$ in some order, and the numbers $$$y_1, \dots, y_n$$$ should be equal to the numbers $$$b_1, \dots, b_n$$$ in some order.  It can be shown that an answer always exists. If there are multiple possible answers, you may print any of them.

NoteIn the first test case, it is enough to give the $$$i$$$-th necklace and the $$$i$$$-th bracelet to the $$$i$$$-th daughter. The corresponding sums are $$$1 + 8 = 9$$$, $$$8 + 4 = 12$$$, and $$$5 + 5 = 10$$$.The second test case is described in the statement.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     $d = explode(" ", trim(fgets(STDIN)));
     sort($c);
     sort($d);
     print implode(" ", $c) . "\n";
     print implode(" ", $d) . "\n";
}
?>

<?php

$t = readline();

for ($j = 0; $j < $t; $j++)
{
    $n = readline();
    $a = readline();
    $a = explode(' ', $a);
    $b = readline();
    $b = explode(' ', $b);

    sort($a);
    sort($b);

    $output[$j]['a'] = implode(' ', $a);
    $output[$j]['b'] = implode(' ', $b);
}

foreach ($output as $value)
{
    echo $value['a'] . "\n";
    echo $value['b'] . "\n";
}

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t= trim(fgets($handle));
for($k=0;$k<$t;$k++)
{
    $n= trim(fgets($handle));
    $a= trim(fgets($handle));
    $a=explode(' ',$a);
    $b= trim(fgets($handle));
    $b=explode(' ',$b);
    sort($b);
    sort($a);
    for($i=0;$i<$n;$i++)
    {
        echo $a[$i]." ";
    }
    echo "\n";
    for($i=0;$i<$n;$i++)
    {
        echo $b[$i]." ";
    }
    echo "\n";
}

<?php

function formGifts(array $necklaces, array $bracelets) {
	asort($necklaces);
	asort($bracelets);

	return [
		$necklaces,
		$bracelets
	];
}

function pringGiftSets(array $giftSets) {
	foreach ($giftSets as $gifts) {
		$necklaces = $gifts[0];
		echo implode(' ', $necklaces) . PHP_EOL;

		$bracelets = $gifts[1];
		echo implode(' ', $bracelets) . PHP_EOL;
	}
}

$giftSets = [];

$setsCount = intval(readline());
for ($i = 0; $i < $setsCount; $i++) {
	$counter = intval(readline());
	$necklaces = array_values(explode(' ', readline()));
	$bracelets = array_values(explode(' ', readline()));

	$giftSets[] = formGifts($necklaces, $bracelets);
}

pringGiftSets($giftSets);

<?php
$server = "php://stdin";
$handle = fopen($server, "r");
$t= trim(fgets($handle));
for($k=0;$k<$t;$k++)
{
    $n= trim(fgets($handle));
    $a= trim(fgets($handle));
    $a=explode(' ',$a);
    $b= trim(fgets($handle));
    $b=explode(' ',$b);
    rsort($b);
    for($i=0;$i<$n;$i++)
    {
        echo $a[$i]." ";
    }
    echo "\n";
    for($i=0;$i<$n;$i++)
    {
        echo $b[$i]." ";
    }
    echo "\n";
}