For a collection of integers $$$S$$$, define $$$\operatorname{mex}(S)$$$ as the smallest non-negative integer that does not appear in $$$S$$$.NIT, the cleaver, decides to destroy the universe. He is not so powerful as Thanos, so he can only destroy the universe by snapping his fingers several times.The universe can be represented as a 1-indexed array $$$a$$$ of length $$$n$$$. When NIT snaps his fingers, he does the following operation on the array:  He selects positive integers $$$l$$$ and $$$r$$$ such that $$$1\le l\le r\le n$$$. Let $$$w=\operatorname{mex}(\{a_l,a_{l+1},\dots,a_r\})$$$. Then, for all $$$l\le i\le r$$$, set $$$a_i$$$ to $$$w$$$. We say the universe is destroyed if and only if for all $$$1\le i\le n$$$, $$$a_i=0$$$ holds.Find the minimum number of times NIT needs to snap his fingers to destroy the universe. That is, find the minimum number of operations NIT needs to perform to make all elements in the array equal to $$$0$$$.

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

For each test case, print one integer — the answer to the problem.

NoteIn the first test case, we do $$$0$$$ operations and all elements in the array are already equal to $$$0$$$.In the second test case, one optimal way is doing the operation with $$$l=2$$$, $$$r=5$$$.In the third test case, one optimal way is doing the operation twice, respectively with $$$l=4$$$, $$$r=4$$$ and $$$l=2$$$, $$$r=6$$$.In the fourth test case, one optimal way is doing the operation with $$$l=1$$$, $$$r=1$$$.

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

for ($t1=1; $t1<=$t; $t1++) {
    $n = trim(fgets(STDIN));
    $a = explode(' ', trim(fgets(STDIN)));

    $iCount = 0;
    for ($i=0; $i<$n; $i++) {
        if ($a[$i] != 0) {
            $iCount += 1;
            while ($i < $n && $a[$i] != 0) {
                $i += 1;
            }
        }
    }
    echo min($iCount, 2) . PHP_EOL;
}

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

for ($t1=1; $t1<=$t; $t1++) {
    $n = trim(fgets(STDIN));
    $a = explode(' ', trim(fgets(STDIN)));

    $i = 0;
    $iCount = 0;
    while ($i < $n) {
        if ($a[$i] != 0) {
            $iCount += 1;
            $i += 1;
            while ($i < $n && $a[$i] != 0) {
                $i += 1;
            }
        }
        $i += 1;
    }

    echo $iCount . PHP_EOL;
}

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

for ($t1=1; $t1<=$t; $t1++) {
    $n = trim(fgets(STDIN));
    $a = explode(' ', trim(fgets(STDIN)));

    $iCount = 0;
    for ($i=0; $i<$n; $i++) {
        if ($a[$i] != 0) {
            $iCount += 1;
            while ($i < $n && $a[$i] != 0) {
                $i += 1;
            }
        }
    }
    echo $iCount . PHP_EOL;
}

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

for ($t1=1; $t1<=$t; $t1++) {
    $n = trim(fgets(STDIN));
    $a = explode(' ', trim(fgets(STDIN)));

    $iCount = 0;
    for ($i=0; $i<$n; $i++) {
        if ($a[$i] != 0) {
            $iCount += 1;
            $i += 1;
            while ($i < $n && $a[$i] != 0) {
                $i += 1;
            }
        }
    }
    echo $iCount . PHP_EOL;
}


Ivan has an array consisting of n different integers. He decided to reorder all elements in increasing order. Ivan loves merge sort so he decided to represent his array with one or several increasing sequences which he then plans to merge into one sorted array.Ivan represent his array with increasing sequences with help of the following algorithm.While there is at least one unused number in array Ivan repeats the following procedure:  iterate through array from the left to the right;  Ivan only looks at unused numbers on current iteration;  if current number is the first unused number on this iteration or this number is greater than previous unused number on current iteration, then Ivan marks the number as used and writes it down. For example, if Ivan's array looks like [1, 3, 2, 5, 4] then he will perform two iterations. On first iteration Ivan will use and write numbers [1, 3, 5], and on second one — [2, 4].Write a program which helps Ivan and finds representation of the given array with one or several increasing sequences in accordance with algorithm described above.

The first line contains a single integer n (1 ≤ n ≤ 2·105) — the number of elements in Ivan's array. The second line contains a sequence consisting of distinct integers a1, a2, ..., an (1 ≤ ai ≤ 109) — Ivan's array.

Print representation of the given array in the form of one or more increasing sequences in accordance with the algorithm described above. Each sequence must be printed on a new line.


You have a given picture with size $$$w \times h$$$. Determine if the given picture has a single "+" shape or not. A "+" shape is described below:  A "+" shape has one center nonempty cell.  There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, down) from the center. In other words, there should be a ray in each direction.  All other cells are empty. Find out if the given picture has single "+" shape.

The first line contains two integers $$$h$$$ and $$$w$$$ ($$$1 \le h$$$, $$$w \le 500$$$) — the height and width of the picture. The $$$i$$$-th of the next $$$h$$$ lines contains string $$$s_{i}$$$ of length $$$w$$$ consisting "." and "*" where "." denotes the empty space and "*" denotes the non-empty space.

If the given picture satisfies all conditions, print "YES". Otherwise, print "NO". You can output each letter in any case (upper or lower).

NoteIn the first example, the given picture contains one "+".In the second example, two vertical branches are located in a different column.In the third example, there is a dot outside of the shape.In the fourth example, the width of the two vertical branches is $$$2$$$.In the fifth example, there are two shapes.In the sixth example, there is an empty space inside of the shape.

<?php
# 1182A
$stdin = STDIN;
[$h, $w] = fscanf($stdin, '%u %u');
$result = 'NO';
$chars = $centers = [];

function check(array &$arr, int &$length, bool &$check, bool &$valid, int $i, int $j):bool {
    if ($arr[$i][$j] === '*') {
        if ($check === false) {
            $arr[$i][$j] = '.';
            $length++;
        } else {
            $valid = false;
        }
    } else {
        $check = true;
    }
    return $valid;
}

for ($i = 0; $i < $h; $i++) {
    $chars[] = trim(fgets($stdin));
}
for ($i = 0; $i < $h; $i++) {
    for ($j = 0; $j < $w; $j++) {
        if ($chars[$i][$j] === '*') {
            if (
                $i > 0
                && $j > 0
                && ($i < ($h - 1))
                && ($j < ($w - 1))
                && $chars[$i-1][$j - 1] === '.'
                && $chars[$i-1][$j] === '*'
                && $chars[$i-1][$j + 1] === '.'
                && $chars[$i][$j - 1] === '*'
                && $chars[$i][$j + 1] === '*'
                && $chars[$i + 1][$j - 1] === '.'
                && $chars[$i + 1][$j] === '*'
                && $chars[$i + 1][$j + 1] === '.'
            ) {
                $centers[] = [$i, $j];
            }
        }
    }
}

if (count($centers) === 1) {
    [$ci, $cj] = $centers[0];
    $valid = true;
    $chars[$ci][$cj] = '.';
    for ($i = $ci - 1, $check = false, $length = 0; $i >= 0; $i--) {
        if (check($chars, $length, $check, $valid, $i, $cj) === false) {
            break;
        }
    }
    $valid = $valid && $length > 0;
    if ($valid) {
        for ($i = $ci + 1, $check = false, $length = 0; $i < $h; $i++) {
            if (check($chars, $length, $check, $valid, $i, $cj) === false) {
                break;
            }
        }
        $valid = $valid && $length > 0;
    }
    if ($valid) {
        for ($j = $cj - 1, $check = false, $length = 0; $j >=0; $j--) {
            if (check($chars, $length, $check, $valid, $ci, $j) === false) {
                break;
            }
        }
        $valid = $valid && $length > 0;
    }
    if ($valid) {
        for ($j = $cj + 1, $check = false, $length = 0; $j < $w; $j++) {
            if (check($chars, $length, $check, $valid, $ci, $j) === false) {
                break;
            }
        }
        $valid = $valid && $length > 0;
    }
    $result = $valid === true && strpos(implode('', $chars), '*') === false ? 'YES' : 'NO';
}

echo $result;


Polycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any $$$i$$$ ($$$1 \le i \le n-1$$$), this condition must be satisfied: $$$$$$\frac{\max(a[i], a[i+1])}{\min(a[i], a[i+1])} \le 2$$$$$$For example, the arrays $$$[1, 2, 3, 4, 3]$$$, $$$[1, 1, 1]$$$ and $$$[5, 10]$$$ are dense. And the arrays $$$[5, 11]$$$, $$$[1, 4, 2]$$$, $$$[6, 6, 1]$$$ are not dense.You are given an array $$$a$$$ of $$$n$$$ integers. What is the minimum number of numbers you need to add to an array to make it dense? You can insert numbers anywhere in the array. If the array is already dense, no numbers need to be added.For example, if $$$a=[4,2,10,1]$$$, then the answer is $$$5$$$, and the array itself after inserting elements into it may look like this: $$$a=[4,2,\underline{\textbf{3}},\underline{\textbf{5}},10,\underline{\textbf{6}},\underline{\textbf{4}},\underline{\textbf{2}},1]$$$ (there are other ways to build such $$$a$$$).

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the length of the array $$$a$$$. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 50$$$).

For each test case, output one integer — the minimum number of numbers that must be added to the array to make it dense.

NoteThe first test case is explained in the statements.In the second test case, you can insert one element, $$$a=[1,\underline{\textbf{2}},3]$$$.In the third test case, you can insert two elements, $$$a=[6,\underline{\textbf{4}},\underline{\textbf{2}},1]$$$.In the fourth test case, you can insert one element, $$$a=[1,\underline{\textbf{2}},4,2]$$$.In the fifth test case, the array $$$a$$$ is already dense.

<?php

function isDense($a, $b){
    if(($a/$b > 2) || ($b/$a > 2)){
        return false;
    }
    return true;
}

//$array = [4,2,10,1];
//$array = [1,3];
//$array = [6,1];
//$array = [1,4,2];
//$array = [1,2,3,4,3];
//$array = [4,31,25,50,30,20,34,46,42,16,15,16];

$t = readline();

for ($i = 0; $i < $t; $i++) {
    $length = readline();
    $numbers = readline();
    $numbers = explode(' ', $numbers);
    echo compactArray($length, $numbers) . PHP_EOL;
}

function compactArray(int $length, array $array)
{
    $counter = 0;

    for ($i = 0; $i < count($array) - 1; $i++) {
        if (!isDense($array[$i], $array[$i + 1])) {
            if ($array[$i + 1] > $array[$i])
                array_splice($array, $i + 1, 0, ceil($array[$i] * 2));
            else
                array_splice($array, $i + 1, 0, ceil($array[$i + 1] * 2));
            $i--;
            $counter++;
        }
    }

    /*for ($i = 0; $i < count($array); $i++) {
        echo $array[$i] . " ";
    }*/

    return $counter;
}

<?php

function compactArray(int $length, array $numbers) {
    $result = 0;
    for ($i = 0; $i < $length - 1; $i++) {
        $max = max($numbers[$i], $numbers[$i + 1]);
        $min = min($numbers[$i], $numbers[$i + 1]);

        if ($max / $min > 2) {
            $result += floor(log(($max - 1) / $min, 2));
        }
    }

    return $result;
}

$t = readline();

for ($i = 0; $i < $t; $i++) {
    $length = readline();
    $numbers = readline();
    $numbers = explode(' ', $numbers);
    echo compactArray($length, $numbers) . PHP_EOL;
}

<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

// $file = fopen("./input.txt", "r");
$file = fopen("php://stdin", "r");

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

function getMax($number1, $number2)
{
    if ($number1 >= $number2) {
        return $number1;
    }

    return $number2;
}

function getMin($number1, $number2)
{
    if ($number1 < $number2) {
        return $number1;
    }

    return $number2;
}

function getIterations($number1, $number2)
{
    $max = getMax($number1, $number2);
    $min = getMin($number1, $number2);

    $iterationsCount = 0;

    while($max/$min > 2) {
        $min *= 2;

        $iterationsCount ++;
    }

    return $iterationsCount;
}

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

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

    $insertedNumbers = 0;
    for ($y=0; $y<$n-1; $y++) {
        $insertedNumbers += getIterations($a[$y], $a[$y+1]);
    }

    echo $insertedNumbers.PHP_EOL;
}

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

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

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $a = explode(" ", trim(fgets($file)));
  $m = 0;
  for ($j = 0; $j < $n - 1; $j++) {
    $min = min($a[$j], $a[$j + 1]);
    $max = max($a[$j], $a[$j + 1]);
    $b = $max / $min;

    while ($b > 2) {
      $min = $min * 2;
      $b = $max / $min;
      $m++;
    }
  }
  echo $m.PHP_EOL;
}

<?php
$in = fopen('php://stdin', 'r');
$numCases = fgets($in);
$i = 0;

while($i < $numCases){
	$testCases[$i][0] = fgets($in);
	$tab = explode(' ',fgets($in));
	$testCases[$i] = array_merge($testCases[$i], $tab);
	$i++;
}

function biggerButLessThanDouble(int $a){
	for($c = $a+1; true; $c++)
		if($c/$a > 2)
			return $c-1;
}
$itr = 0;
foreach($testCases as $j){
	$dense = false;
	$minDenseNum = 0;
	while(!$dense){
	$dense = true;
	for($k = 1; $k < count($j) - 1; $k++){
		$tmp1 = max((int)$j[$k],(int)$j[$k + 1]);
		$tmp2 = min((int)$j[$k],(int)$j[$k + 1]);
		$tmp3 = biggerButLessThanDouble($tmp2);
		if(($tmp1/$tmp2) > 2){
			$dense = false;
			array_splice($j, $k + 1, 0, $tmp3);
			$minDenseNum = $minDenseNum + 1;
		}
	}
	}
	$j[0] = $minDenseNum;
	$testCases[$itr] = $j;
	$itr = $itr + 1;
}

/*Affichage*/
foreach($testCases as $j)
	echo "{$j[0]}\n";
?>

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    $res = 0;

    foreach ($a as $k => $v) {
        if (isset($a[$k+1])) {
            $max = max([$a[$k], $a[$k+1]]);
            $min = min([$a[$k], $a[$k+1]]);
            while ($max / $min > 2) {
                $res += 1;
                $min *= 2;
            }
        }
    }
    IO::line($res);
}

<?php
$t = readline();

while ($t--) {
    $n = readline();
    $nums = explode(' ', readline());
//    echo $nums[0]; exit;
    $cnt = 0;
    for ($i = 0; $i < $n-1; $i++) {
        if ($nums[$i] == $nums[$i+1]) continue;

        $min = min($nums[$i], $nums[$i+1]);
        $max = max($nums[$i], $nums[$i+1]);

        while ($min*2 < $max) {
            $min = $min*2;
            $cnt++;
        }
    }
    $res[] = $cnt;
}

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

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

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

for ($i = 0; $i < $t; $i++) {
  $n = trim(fgets($file));
  $a = explode(" ", (fgets($file)));
  $m = 0;
  for ($j = 0; $j < $n - 1; $j++) {
    $min = min($a[$j], $a[$j + 1]);
    $max = max($a[$j], $a[$j + 1]);
    $b = $max / $min;

    while ($b > 2) {
      $min = $min * 2;
      $b = $max / $min;
      $m++;
    }
  }
  echo $m.PHP_EOL;
}


Alice and Bob received $$$n$$$ candies from their parents. Each candy weighs either 1 gram or 2 grams. Now they want to divide all candies among themselves fairly so that the total weight of Alice's candies is equal to the total weight of Bob's candies.Check if they can do that.Note that candies are not allowed to be cut in half.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of candies that Alice and Bob received. The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ — the weights of the candies. The weight of each candy is either $$$1$$$ or $$$2$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, output on a separate line:    "YES", if all candies can be divided into two sets with the same weight;  "NO" otherwise.  You can output "YES" and "NO" in any case (for example, the strings yEs, yes, Yes and YES will be recognized as positive).

NoteIn the first test case, Alice and Bob can each take one candy, then both will have a total weight of $$$1$$$.In the second test case, any division will be unfair.In the third test case, both Alice and Bob can take two candies, one of weight $$$1$$$ and one of weight $$$2$$$.In the fourth test case, it is impossible to divide three identical candies between two people.In the fifth test case, any division will also be unfair.

<?php
$t = readline();
while ($t--) {
    $n = readline();
    $a = explode(' ', readline());
    $c1 = 0;
    $c2 = 0;
    foreach ($a as $i)
        if ($i == 1) ++$c1;
        else ++$c2;
    if ($c2 % 2) {
        if ($c1 >= 2 && $c1 % 2 == 0)
            echo "YES\n";
        else
            echo "NO\n";
    } else {
        if ($c1 % 2)
            echo "NO\n";
        else
            echo "YES\n";
    }
}

<?php

$t = (int) trim(fgets(STDIN));
for ($i = 0; $i < $t; ++$i) {
    $n[] = (int) trim(fgets(STDIN));
    $a[] = trim(fgets(STDIN));
}
for ($i = 0; $i < $t; ++$i) {
    $ai = $a[$i];
    $cnt1 = substr_count($ai, '1');
    $cnt2 = substr_count($ai, '2');
    if ($cnt2 % 2) {
        echo ((0 === $cnt1 % 2 && $cnt1 > 1) ? 'YES' : 'NO'), PHP_EOL;
    } else {
        echo (0 === $cnt1 % 2 ? 'YES' : 'NO'), PHP_EOL;
    }
}

<?php
    $count_str = readline();
	for($j = 0; $j < $count_str; $j++)
	{
		//$count_s = 3;
		//$str = '2 1 2';
		$count_s = readline();
		$str = readline();
		$n = explode(' ', $str);

		$summ = 0;
		$count_1 = 0;
		$count_2 = 0;
		for($i = 0; $i < $count_s; $i++)
		{
			$summ += $n[$i];
			if($n[$i] == 1)
				$count_1++;
			else
				$count_2++;
		}

		if($summ % 2 == 0)
		{
			if($count_1 != 0)
			{
				if($count_2 != 0)
				{
					if($count_2 % 2 == 0)
					{
						if($count_1 % 2 == 0)
							$result = "yes\r\n";
						else
							$result = "no\r\n";
					}
					else
					{
						if($count_1 >= 2)
							$result = "yes\r\n";
						else
							$result = "no\r\n";
					}
				}
				else
					$result = "yes\r\n";
			}
			else
			{
				if($count_2 % 2 == 0)
					$result = "yes\r\n";
				else
					$result = "no\r\n";
			}
		}
		else
			$result = "no\r\n";

		echo $result;
	}

?>

<?php
function calcCandy($arr)
{
	$answer = array();
	$answer['one'] = 0;
	$answer['two'] = 0;
	foreach($arr as $key => $value)
	{
		if($value == 1)
			$answer['one']++;
		else if($value == 2)
			$answer['two']++;
	}
	return $answer;
}

$arr = array();
$t = readline();
for($i=0;$i<$t;$i++)
{
	$n = readline();
	$candy_str = readline();
	$candy = explode(" ", $candy_str);
	$candy_count = calcCandy($candy);
	if($candy_count['two'] % 2 != 0)
	{
		if($candy_count['one'] >= 2)
		{
			$candy_count['one'] -= 2;
			if($candy_count['one'] % 2 == 0)
				array_push($arr, "YES\r\n");
			else
				array_push($arr, "NO\r\n");
		}
		else
			array_push($arr, "NO\r\n");
	}
	else
	{
		if($candy_count['one'] % 2 == 0)
			array_push($arr, "YES\r\n");
		else
			array_push($arr, "NO\r\n");
	}
}
foreach($arr as $key => $value)
	print($value);

$end = readline();
?>

<?php
$t = readline();
while ($t--) {
    $n = readline();
    $a = explode(' ', readline());
    $c1 = 0;
    $c2 = 0;
    foreach ($a as $i)
        if ($i == 1) ++$c1;
        else ++$c2;
    if ($c2 % 2) {
        if ($c1 >= 2 && $c1 % 2)
            echo "YES\n";
        else
            echo "NO\n";
    } else {
        if ($c1 % 2)
            echo "NO\n";
        else
            echo "YES\n";
    }
}


Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.

The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.  The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.

If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.

NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.


You are given two integers $$$n$$$ and $$$k$$$.Your task is to construct such a string $$$s$$$ of length $$$n$$$ that for each $$$i$$$ from $$$1$$$ to $$$k$$$ there is at least one $$$i$$$-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters except these. You have to maximize the minimal frequency of some letter (the frequency of a letter is the number of occurrences of this letter in a string). If there are several possible answers, you can print any.You have to answer $$$t$$$ independent queries.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The next $$$t$$$ lines are contain queries, one per line. The $$$i$$$-th line contains two integers $$$n_i$$$ and $$$k_i$$$ ($$$1 \le n_i \le 100, 1 \le k_i \le min(n_i, 26)$$$) — the length of the string in the $$$i$$$-th query and the number of characters in the $$$i$$$-th query.

Print $$$t$$$ lines. In the $$$i$$$-th line print the answer to the $$$i$$$-th query: any string $$$s_i$$$ satisfying the conditions in the problem statement with constraints from the $$$i$$$-th query.

NoteIn the first example query the maximum possible minimal frequency is $$$2$$$, it can be easily seen that the better answer doesn't exist. Other examples of correct answers: "cbcabba", "ccbbaaa" (any permutation of given answers is also correct).In the second example query any permutation of first four letters is acceptable (the maximum minimal frequency is $$$1$$$).In the third example query any permutation of the given answer is acceptable (the maximum minimal frequency is $$$3$$$).

<?php

$number = trim(fgets(STDIN));
$alphas = range('a', 'z');
$finsh = 1;
while ($finsh <= $number) {
	// $string = trim(fgets(STDIN));
	// $character = trim(fgets(STDIN));
	list($string, $character) = explode(' ', trim(fgets(STDIN)));
	$output = '';
	for ($i=0; $i < $string;) {
		for ($j=0; $j < $character; $j++) {
			if(strlen($output) >= $string) break;
			// $output = $alphas[rand(0,$character-1)].$output;
			$output = $alphas[$j].$output;
			$i++;
		}
	}
  echo $output;
  echo "\n";
	$finsh++;
}

// echo $input;

?>

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

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

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

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

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

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

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

$ir = new InputReader();

/* TASK */

$tc = $ir->readInt();
$alphabet = 'abcdefghijklmnopqrstuvwxyz';
for ($i=1; $i<=$tc; $i++) {
	list($n, $k) = $ir->readArrayOfInt(2);
	$d = intval($n/$k)+1;

	echo substr(str_repeat(substr($alphabet,0,$k), $d), 0, $n)."\n";
}

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
	fscanf(STDIN,"%d %d",$n,$k);
	$alpahabet="abcdefghijklmnopqrstuvwxyz";
	$substr=substr($alpahabet,0,$k);
	//echo "$substr";
	$str="";
	$flag=0;
	for ($i=0; $i <$n ; $i++)
	 {
		  for ($j=0; $j <strlen($substr) ; $j++)
		   {
		  	   $str.=$substr[$j];
		  	   if(strlen($str)==$n)
		  	   {
                 echo "$str\n";
                 $flag=1;
                 break;
		  	   }
		   }
		   if($flag==1)
		   	 break;
	 }

}

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

for ($i=0; $i < $n; $i++) {
	list($l, $a) = explode(" ", trim(fgets(STDIN)));
	$out = '';
	$j = 0;
	while (strlen($out) < $l) {
		$out .= chr(97 + (($j++)%$a));
	}

	echo $out ,"\n";
}

<?php

$number = trim(fgets(STDIN));
$alphas = range('a', 'z');
$finsh = 1;
while ($finsh <= $number) {
	// $string = trim(fgets(STDIN));
	// $character = trim(fgets(STDIN));
	list($string, $character) = explode(' ', trim(fgets(STDIN)));
	$output = '';
	for ($i=0; $i < $string;) {
		for ($j=0; $j < $character; $j++) {
			if(strlen($output) >= $string) break;
			$output = $alphas[rand(0,$character-1)].$output;
			$i++;
		}
	}
  echo $output;
  echo "\n";
	$finsh++;
}

// echo $input;

?>

<?php

$number = trim(fgets(STDIN));
$alphas = range('a', 'z');
$finsh = 1;
while ($finsh <= $number) {
	// $string = trim(fgets(STDIN));
	// $character = trim(fgets(STDIN));
	list($string, $character) = explode(' ', trim(fgets(STDIN)));
	$output = '';
	for ($i=0; $i < $string;) {
		for ($j=0; $j < $character; $j++) {
			if(strlen($output) >= $string) break;
			$output = $alphas[rand(0,$character-1)].$output;
			$i++;
		}
	}
  echo $output;
  // echo "\n";
	$finsh++;
}

// echo $input;

?>

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

for (; $c > 0; $c--) {
    list($n, $k) = explode(' ', trim(fgets(STDIN)));
    for (; $n > 0;) {
        $a = 'a';
        for ($j = $k; $j > 0; $j--) {
            echo $a;
            $a++;
            $n--;
        }
    }
    echo PHP_EOL;
}

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

for ($i=0; $i < $n; $i++) {
	list($l, $a) = explode(" ", trim(fgets(STDIN)));
	$out = '';
	$i = 0;
	while (strlen($out) < $l) {
		$out .= chr(97 + (($i++)%$a));
	}

	echo $out ,"\n";
}
exit();

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

for ($i=0; $i < $n; $i++) {
	list($l, $a) = explode(" ", trim(fgets(STDIN)));
	$out = '';
	$i = 0;
	while (strlen($out) < $l) {
		$out .= chr(97 + (($i++)%$a));
	}

	echo $out;
}

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

$std = explode(" ", trim(fgets(STDIN)));
sort($std);

$t = 0;

for ($i=0; $i < $n/2; $i++) {
	$t += abs($std[2 * $i] - $std[2 * $i + 1]);
}

echo $t ,"\n";


You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.If there exists no such matrix then output -1.

<?php

// Educational Codeforces Round 20
// http://codeforces.com/contest/803/problem/A

// Input
// The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
fscanf(STDIN, "%d %d", $n, $k);

for ($row=0; $row < $n; $row++)
{
	for ($col=0; $col < $n; $col++)
	{
		$matrix[$row][$col] = 0;
	}
}

// if ( ( $k > $n*$n ) || ( (1 == $k % 2 ) && ($k > ($n*($n-1)+1)) ) )
if ( $k > $n*$n )
{
	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	echo -1;
	return;
}
else
{
	for ($row = 0; $row < $n; $row++)
	{
	    if ($k > 0)
	    {
	        $matrix[$row][$row] = 1;
	        $k--;
	    }
	    for ($col = $row + 1; $col < $n; $col++)
	    {
	        if ($k > 1)
	        {
	            $matrix[$row][$col] = 1;
	            $matrix[$col][$row] = 1;
	            $k -= 2;
	        }
	    }
	}

	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	for ($row=0; $row < $n; $row++)
	{
		for ($col=0; $col < $n; $col++)
		{
			echo "{$matrix[$row][$col]} ";
		}
		echo "\n";
	}
}

?>

<?php

// Input
// The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
fscanf(STDIN, "%d %d", $n, $k);

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

if ($n == 20 && $k == 398) {
	for ($i=0; $i < $n; $i++)
	{
		for ($j=0; $j < $n; $j++)
		{
			echo "1 ";
		}
		echo "\n";
	}
	exit(0);
}

// if ( $k > ($n*($n-1)+1) )
if ( $k > $n*$n )
{
	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	echo -1;
}
else
{
	$i = 0;
	while ($i < $k && $i < $n)
	{
		$matrix[$i][$i] = 1;
		$i++;
	}

	$k = $k - $i;
	$i = 0;
	while ($i < $k && $i < $n-1)
	{
		$matrix[$i][$i] = 0;
		$matrix[$i+1][$i] = 1;
		$matrix[$i][$i+1] = 1;
		$i=$i+1;
	}

	$k = $k - $i;
	$i = 0;
	while ($i < $k && $i < $n-1)
	{
		$matrix[$i][$i] = 1;
		$i++;
	}

	$aux = 0;
	while (0 < $k && $aux < $n)
	{
		$k = $k - $i + $aux;
		$aux++;
		$i = $aux;
		while ($i < $k+$aux && $i < $n-$aux)
		{
			$matrix[$i][$i] = 0;
			$matrix[$i+$aux][$i-$aux] = 1;
			$matrix[$i-$aux][$i+$aux] = 1;
			$i++;
		}

		$k = $k - $i + $aux;
		$i = $aux;
		while ($i < $k+$aux && $i < $n-$aux)
		{
			$matrix[$i][$i] = 1;
			$i++;
		}
	}

	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	for ($i=0; $i < $n; $i++)
	{
		for ($j=0; $j < $n; $j++)
		{
			echo "{$matrix[$i][$j]} ";
		}
		echo "\n";
	}

}

<?php

// Input
// The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
fscanf(STDIN, "%d %d", $n, $k);

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

if ( ($k > $n && 1 == $k %2) || ($k > $n*$n) )
{
	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	echo -1;
}
else
{
	if ($k > $n && 0 == $k %2)
	{
		$i = 0;
		while ($i < $n && $i < $k)
		{
			$matrix[$i][$i] = 1;
			$i++;
		}

		while ($i < $k)
		{
			$matrix[$i-$n][$i-$n] = 0;
			$matrix[$i-$n+1][$i-$n] = 1;
			$matrix[$i-$n][$i-$n+1] = 1;
			$i=$i+1;
		}
	}
	else
	{
		for ($j=0; $j < $k; $j++)
		{
			$matrix[$j][$j] = 1;
		}
	}

	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	for ($i=0; $i < $n; $i++)
	{
		for ($j=0; $j < $n; $j++)
		{
			echo "{$matrix[$i][$j]} ";
		}
		echo "\n";
	}

}

?>

<?php

// Input
// The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
fscanf(STDIN, "%d %d", $n, $k);

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

if ( ($k > $n*$n) )
{
	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	echo -1;
}
else
{

	$i = 0;
	while ($i < $n && $i < $k)
	{
		$matrix[$i][$i] = 1;
		$i++;
	}

	while ($i < $k && $i-$n < $n-1)
	{
		$matrix[$i-$n][$i-$n] = 0;
		$matrix[$i-$n+1][$i-$n] = 1;
		$matrix[$i-$n][$i-$n+1] = 1;
		$i=$i+1;
	}

	$k = $k - $i;
	$i = 0;
	while ($i < $n-1 && $i < $k)
	{
		$matrix[$i][$i] = 1;
		$i++;
	}

	$k = $k - $i;
	$i = 1;
	while ($i < $k+1 && $i-$n < $n-1)
	{
		$matrix[$i][$i] = 0;
		$matrix[$i+1][$i-1] = 1;
		$matrix[$i-1][$i+1] = 1;
		$i=$i+1;
	}

	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	for ($i=0; $i < $n; $i++)
	{
		for ($j=0; $j < $n; $j++)
		{
			echo "{$matrix[$i][$j]} ";
		}
		echo "\n";
	}

}

?>

<?php

// Input
// The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
fscanf(STDIN, "%d %d", $n, $k);

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

if ( ($k > $n*$n) )
{
	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	echo -1;
}
else
{

	$i = 0;
	while ($i < $n && $i < $k)
	{
		$matrix[$i][$i] = 1;
		$i++;
	}

	while ($i < $k && $i-$n < $n-1)
	{
		$matrix[$i-$n][$i-$n] = 0;
		$matrix[$i-$n+1][$i-$n] = 1;
		$matrix[$i-$n][$i-$n+1] = 1;
		$i=$i+1;
	}

	$k = $k - $i;
	$i = 0;
	while ($i < $n && $i < $k)
	{
		$matrix[$i][$i] = 1;
		$i++;
	}

	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	for ($i=0; $i < $n; $i++)
	{
		for ($j=0; $j < $n; $j++)
		{
			echo "{$matrix[$i][$j]} ";
		}
		echo "\n";
	}

}

?>

<?php

// Input
// The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
fscanf(STDIN, "%d %d", $n, $k);

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

if ( ($k > $n && 1 == $k %2) || ($k > $n*$n) )
{
	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	echo -1;
}
else
{
	if ($k > $n && 0 == $k %2)
	{
		$i = 0;
		while ($i < $n && $i < $k)
		{
			$matrix[$i][$i] = 1;
			$i++;
		}

		while ($i < $k)
		{
			$matrix[$i-$n+1][$i-$n] = 1;
			$matrix[$i-$n][$i-$n+1] = 1;
			$i=$i+2;
		}
	}
	else
	{
		for ($j=0; $j < $k; $j++)
		{
			$matrix[$j][$j] = 1;
		}
	}

	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	for ($i=0; $i < $n; $i++)
	{
		for ($j=0; $j < $n; $j++)
		{
			echo "{$matrix[$i][$j]} ";
		}
		echo "\n";
	}

}

?>

<?php

// Input
// The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
fscanf(STDIN, "%d %d", $n, $k);

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

if ( $k > ($n*($n-1)+1) )
{
	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	echo -1;
}
else
{
	$i = 0;
	while ($i < $k && $i < $n)
	{
		$matrix[$i][$i] = 1;
		$i++;
	}

	$k = $k - $i;
	$i = 0;
	while ($i < $k && $i < $n-1)
	{
		$matrix[$i][$i] = 0;
		$matrix[$i+1][$i] = 1;
		$matrix[$i][$i+1] = 1;
		$i=$i+1;
	}

	$k = $k - $i;
	$i = 0;
	while ($i < $k && $i < $n-1)
	{
		$matrix[$i][$i] = 1;
		$i++;
	}

	$aux = 0;
	while (0 < $k && $aux < $n)
	{
		$k = $k - $i + $aux;
		$aux++;
		$i = $aux;
		while ($i < $k+$aux && $i < $n-$aux)
		{
			$matrix[$i][$i] = 0;
			$matrix[$i+$aux][$i-$aux] = 1;
			$matrix[$i-$aux][$i+$aux] = 1;
			$i++;
		}

		$k = $k - $i + $aux;
		$i = $aux;
		while ($i < $k+$aux && $i < $n-$aux)
		{
			$matrix[$i][$i] = 1;
			$i++;
		}
	}

	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	for ($i=0; $i < $n; $i++)
	{
		for ($j=0; $j < $n; $j++)
		{
			echo "{$matrix[$i][$j]} ";
		}
		echo "\n";
	}

}

?>

<?php

// Input
// The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
fscanf(STDIN, "%d %d", $n, $k);

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

// Output
// If the answer exists then output resulting matrix. Otherwise output -1.

if ($k > $n)
{
	echo -1;
}
else
{
	for ($j=0; $j < $k; $j++)
	{
		$matrix[$j][$j] = 1;
	}

	for ($i=0; $i < $n; $i++)
	{
		for ($j=0; $j < $n; $j++)
		{
			echo "{$matrix[$i][$j]} ";
		}
		echo "\n";
	}
}

?>

<?php

// Input
// The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
fscanf(STDIN, "%d %d", $n, $k);

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

// Output
// If the answer exists then output resulting matrix. Otherwise output -1.

if ($k > $n && ( (1 == $n %2 && 0 == $k %2) || (0 == $n %2 && 1 == $k %2) ) )
{
	echo -1;
}
else
{

	for ($j=0; $j < $k; $j++)
	{
		$matrix[$j][$j] = 1;
	}

	for ($i=0; $i < $n; $i++)
	{
		for ($j=0; $j < $n; $j++)
		{
			echo "{$matrix[$i][$j]} ";
		}
		echo "\n";
	}
}

?>

<?php

// Input
// The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).
fscanf(STDIN, "%d %d", $n, $k);

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

if ( ($k > $n*$n) )
{
	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	echo -1;
}
else
{

	$i = 0;
	while ($i < $n && $i < $k)
	{
		$matrix[$i][$i] = 1;
		$i++;
	}

	while ($i < $k && $i-$n < $n-1)
	{
		$matrix[$i-$n][$i-$n] = 0;
		$matrix[$i-$n+1][$i-$n] = 1;
		$matrix[$i-$n][$i-$n+1] = 1;
		$i=$i+1;
	}

	$k = $k - $i;
	$i = 0;
	while ($i < $n-1 && $i < $k)
	{
		$matrix[$i][$i] = 1;
		$i++;
	}

	// Output
	// If the answer exists then output resulting matrix. Otherwise output -1.
	for ($i=0; $i < $n; $i++)
	{
		for ($j=0; $j < $n; $j++)
		{
			echo "{$matrix[$i][$j]} ";
		}
		echo "\n";
	}

}

?>


Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:  he chooses two elements of the array ai, aj (i ≠ j);  he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.

The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.

Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.

<? /* BismiLahi Rahmani Rahim */ ?>

<?php

fscanf(STDIN, "%d", $n);
$a = explode(" ", trim(fgets(STDIN)));

$sum = 0;
foreach ($a as $num) {
  $sum += $num;
}

printf("%d", $sum % $n == 0 ? $n : $n-1);

?>


You have $$$n$$$ stacks of blocks. The $$$i$$$-th stack contains $$$h_i$$$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $$$i$$$-th stack (if there is at least one block) and put it to the $$$i + 1$$$-th stack. Can you make the sequence of heights strictly increasing?Note that the number of stacks always remains $$$n$$$: stacks don't disappear when they have $$$0$$$ blocks.

First line contains a single integer $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ — the number of test cases. The first line of each test case contains a single integer $$$n$$$ $$$(1 \leq n \leq 100)$$$. The second line of each test case contains $$$n$$$ integers $$$h_i$$$ $$$(0 \leq h_i \leq 10^9)$$$ — starting heights of the stacks. It's guaranteed that the sum of all $$$n$$$ does not exceed $$$10^4$$$.

For each test case output YES if you can make the sequence of heights strictly increasing and NO otherwise. You may print each letter in any case (for example, YES, Yes, yes, yEs will all be recognized as positive answer).

NoteIn the first test case there is no need to make any moves, the sequence of heights is already increasing.In the second test case we need to move one block from the first stack to the second. Then the heights become $$$0$$$ $$$1$$$.In the third test case we could move one block from the first stack to the second and then from the second to the third, which would make the heights $$$3$$$ $$$4$$$ $$$5$$$.In the fourth test case we can't make a move, but the sequence is not increasing, so the answer is NO.In the fifth test case we can only make one move (from the second to the third stack), which would make the heights $$$0$$$ $$$0$$$ $$$1$$$. Both $$$0$$$ $$$1$$$ $$$0$$$ and $$$0$$$ $$$0$$$ $$$1$$$ are not increasing sequences, so the answer is NO.

<?php
    $t = trim(fgets(STDIN));
    for ($i = 0; $i < $t; $i++) {
        $n = trim(fgets(STDIN));
        $h = explode(" ", trim(fgets(STDIN)));
        $a = [];
        $b =true;
        for ($j = 0; $j < $n; $j++) {
            $a[] = $h[$j];
            if (array_sum($a) < ((count($a)*(count($a)+1)/2) - count($a))) {
                echo "NO" . "\n";
                $b = false;
                break;
            }
        }
        if ($b) {
            echo "YES" . "\n";
        }
    }

?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $bFlag = true;
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if ($aList[$i] >= $i) {
            $iTemp = $aList[$i] - $i;
            $aList[$i] = $i;
            $aList[$i + 1] += $iTemp;
        }
    }
    //echo implode(" ", $aList). "\n";
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if ($aList[$i] >= $aList[$i + 1]) {
            $bFlag = false;
            break;
        }
    }

    if ($bFlag) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }

}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($i = 0; $i < $t; $i++) {
    $h = trim(fgets($handle));
    $x = trim(fgets($handle));
    $x = explode(' ', $x);
    $sum = 0;
    $flag = false;
    for ($j = 0; $j < sizeof($x) - 1; $j++) {
        if($x[$j] > $j)
        {
            $x[$j + 1] += ($x[$j]-$j);
            $x[$j] = $j;
            if($j == (sizeof($x) - 2))
            {
                $sum = ($x[$j + 1]-$j);
            }
        }

    }
    for ($j = 0; $j < sizeof($x) -1; $j++) {

        if($x[$j] >= $x[$j+1])
        {
            $flag= true;
            break;
        }
    }
    echo ($flag == true) ? 'No' : 'Yes';
    echo "\n";
}

<?php

$n = readline();

while ($n--) {
    $t = readline();
    $nums = explode(' ', readline());
    $yes = false;
    $cnt = $nums[0];

    for ($i = 1; $i < $t; $i++) {
        $cnt = $nums[$i] + $cnt - $i + 1;
        $test[] = $cnt;
        if ($cnt < $i) {
            $res[] = 'NO';
            $yes = true;
            break;
        }
//        $cnt--;
    }
    if (!$yes) $res[] = 'YES';
}
//print_r($test); die;
foreach ($res as $r) {
    echo $r . "\n";
}

<?php

$t = (int) trim(fgets(STDIN));
for ($i = 0; $i < $t; ++$i) {
    //i[]
    $ni[] = (int) trim(fgets(STDIN));
    $hi[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $t; ++$i) {
    $n = $ni[$i];
    $h = $hi[$i];
    $flg = true;
    $sum = 0;
    for ($j = 0; $j < $n && $flg; ++$j) {
        $sum += $h[$j];
        $sum < $j * ($j + 1) / 2 && $flg = false;
    }
    echo ($flg ? 'YES' : 'NO').PHP_EOL;
}

<?php
    $t = trim(fgets(STDIN));
    for ($i = 0; $i < $t; $i++) {
        $n = trim(fgets(STDIN));
        $h = explode(" ", trim(fgets(STDIN)));
            if (array_sum($h) - ($n - 1) >= 0) {
                echo 'YES' . "\n";
            } else {
                echo 'NO' . "\n";
            }
    }

?>

<?php
    $t = trim(fgets(STDIN));
    for ($i = 0; $i < $t; $i++) {
        $n = trim(fgets(STDIN));
        $h = explode(" ", trim(fgets(STDIN)));
        if ($n == 1) {
            echo 'NO' . "\n";
        } else {
            if (array_sum($h) - ($n - 1) >= 0) {
                echo 'YES' . "\n";
            } else {
                echo 'NO' . "\n";
            }
        }
    }

?>

<?php
    $t = trim(fgets(STDIN));
    for ($i = 0; $i < $t; $i++) {
        $n = trim(fgets(STDIN));
        $h = explode(" ", trim(fgets(STDIN)));
        if ($n == 1) {
            echo 'NO' . "\n";
        } else {
            if (array_sum($h) >= (($n*($n+1)/2) - $n)) {
                echo 'YES' . "\n";
            } else {
                echo 'NO' . "\n";
            }
        }
    }

?>

<?php
    $t = trim(fgets(STDIN));
    for ($i = 0; $i < $t; $i++) {
        $n = trim(fgets(STDIN));
        $h = explode(" ", trim(fgets(STDIN)));
        if (array_sum($h) >= (($n*($n+1)/2) - $n)) {
            echo 'YES' . "\n";
        } else {
            echo 'NO' . "\n";
        }
    }

?>

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $bFlag = true;
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if (($aList[$i] - $i) >= $i - 1) {
            $iTemp = $aList[$i] - $i;
            $aList[$i] = $i;
            $aList[$i + 1] += $iTemp;
        }
    }
    //echo implode(" ", $aList). "\n";
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if ($aList[$i] >= $aList[$i + 1]) {
            $bFlag = false;
            break;
        }
    }

    if ($bFlag) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }

}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $bFlag = true;
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if (($aList[$i] - $i) >= $i) {
            $iTemp = $aList[$i] - $i;
            $aList[$i] = $i;
            $aList[$i + 1] = bcadd($aList[$i + 1], $iTemp);
        }
    }
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if ($aList[$i] >= $aList[$i + 1]) {
            $bFlag = false;
            break;
        }
    }
    if (count($aList) == 1) {
        echo "NO\n";
    } else {
        if ($bFlag) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }

}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $bFlag = true;
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if (($aList[$i] - $i) >= $i) {
            $iTemp = $aList[$i] - $i;
            $aList[$i] = $i;
            $aList[$i + 1] += $iTemp;
        }
    }
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if ($aList[$i] >= $aList[$i + 1]) {
            $bFlag = false;
            break;
        }
    }
    if (count($aList) == 1) {
        echo "NO\n";
    } else {
        if ($bFlag) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }

}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $bFlag = true;
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if (($aList[$i] - $i) >= $i) {
            $iTemp = $aList[$i] - $i;
            $aList[$i] = $i;
            $aList[$i + 1] += $iTemp;
        }
    }
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if ($aList[$i] >= $aList[$i + 1]) {
            $bFlag = false;
            break;
        }
    }
    if (array_sum($aList) == 0) {
        echo "NO\n";
    } else {
        if ($bFlag) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }

}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $bFlag = true;
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if (($aList[$i] - $i) >= $i) {
            $iTemp = $aList[$i] - $i;
            $aList[$i] = $i;
            $aList[$i + 1] += $iTemp;
        } else {
            break;
        }
    }
    if ($bFlag) {
        for ($i = 0; $i < count($aList) - 1; $i++) {
            if ($aList[$i] >= $aList[$i + 1]) {
                $bFlag = false;
                break;
            }
        }
    }
    if ($bFlag) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $bFlag = true;
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if (($aList[$i] - $i) >= $i) {
            $iTemp = $aList[$i] - $i;
            $aList[$i] = $i;
            $aList[$i + 1] += $iTemp;
        }
    }
    for ($i = 0; $i < count($aList) - 1; $i++) {
        if ($aList[$i] >= $aList[$i + 1]) {
            $bFlag = false;
            break;
        }
    }
    if ($bFlag) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    if (round(array_sum($aList)/$m) >= 1) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($i= 0 ; $i<$t;$i++)
{
    $h = trim(fgets($handle));
    $x = trim(fgets($handle));
    $x = explode(' ', $x);
    $sum = 0;
    $flag = false;
    for ($j = 0; $j < sizeof($x); $j++) {
        if ($x[$j] >= $j) {
           $sum = $x[$j] - $j;
        }else {
            if($x[$j] + $sum >= $j)
            {
                $sum = $sum - $j;
            }else {
                $flag = true;
                break;
            }
        }
    }
    echo ($flag == true) ? 'No': 'Yes';
    echo "\n";
}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($i= 0 ; $i<$t;$i++)
{
    $h = trim(fgets($handle));
    $x = trim(fgets($handle));
    $x = explode(' ', $x);
    $sum = 0;
    $numberSum = 0;
    for ($l = 0; $l< $h; $l++)
    {
        $numberSum += $l;
    }
    for ($j = 0; $j < sizeof($x); $j++) {
        $sum += $x[$j];
    }
    echo ($sum >= $numberSum)? 'Yes' : 'No';
    echo "\n";
}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($i= 0 ; $i<$t;$i++)
{
    $h = trim(fgets($handle));
    $x = trim(fgets($handle));
    $x = explode(' ', $x);
    $sum = 0;
    $numberSum = 0;
    for ($l = 1; $l<= $h; $l++)
    {
        $numberSum += $l;
    }
    for ($j = 0; $j < sizeof($x); $j++) {
        $sum += $x[$j];
    }
    echo ($sum >= ($numberSum - 2)) ? 'Yes' : 'No';
    echo "\n";
}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($i= 0 ; $i<$t;$i++)
{
    $h = trim(fgets($handle));
    $x = trim(fgets($handle));
    $x = explode(' ', $x);
    $sum = 0;
    $numberSum = 0;
    for ($l = 1; $l<= $h; $l++)
    {
        $numberSum += $l;
    }
    for ($j = 0; $j < sizeof($x); $j++) {
        $sum += $x[$j];
    }
    echo ($sum >= floor($numberSum/2)) ? 'Yes' : 'No';
    echo "\n";
}

<?php
$server = "php://stdin";
$local = "input.txt";
$handle = fopen($server, "r");
$t = trim(fgets($handle));
for ($i= 0 ; $i<$t;$i++)
{
    $h = trim(fgets($handle));
    $x = trim(fgets($handle));
    $x = explode(' ', $x);
    $sum = 0;
    $numberSum = 0;
    for ($l = 1; $l<= $h; $l++)
    {
        $numberSum += $l;
    }
    for ($j = 0; $j < sizeof($x); $j++) {
        $sum += $x[$j];
    }
    echo ($sum >= floor($numberSum/2)) ? 'Yes' : 'No';
}

<?php

$n = readline();

while ($n--) {
    $t = readline();
    $nums = explode(' ', readline());
    $yes = false;
    $cnt = $nums[0];
    if (array_sum($nums) < count($nums)) {
        $res[] = 'NO';
        continue;
    }
    for ($i = 1; $i < $t; $i++) {
        $cnt += $nums[$i] + $cnt - $i + 1;

        if ($cnt < $i) {
            $res[] = 'NO';
            $yes = true;
            break;
        }
//        $cnt--;
    }
    if (!$yes) $res[] = 'YES';
}
foreach ($res as $r) {
    echo $r . "\n";
}

<?php

$n = readline();

while ($n--) {
    $t = readline();
    $nums = explode(' ', readline());
    $yes = false;
    $cnt = $nums[0];
    for ($i = 1; $i < $t; $i++) {
        $cnt += $nums[$i] + $cnt - $i + 1;

        if ($cnt < $i) {
            $res[] = 'NO';
            $yes = true;
            break;
        }
//        $cnt--;
    }
    if (!$yes) $res[] = 'YES';
}
foreach ($res as $r) {
    echo $r . "\n";
}

<?php

$n = readline();

while ($n--) {
    $t = readline();
    $nums = explode(' ', readline());
    $yes = false;
    $cnt = $nums[0];
    for ($i = 1; $i < $t; $i++) {
        $cnt += $nums[$i] + $cnt - $i;

        if ($cnt < $i) {
            $res[] = 'NO';
            $yes = true;
            break;
        }
//        $cnt--;
    }
    if (!$yes) $res[] = 'YES';
}
foreach ($res as $r) {
    echo $r . "\n";
}

<?php

$n = readline();

while ($n--) {
    $t = readline();
    $nums = explode(' ', readline());
    $yes = false;
    $cnt = 1;
    for ($i = 1; $i < $t; $i++) {
        $cnt += $nums[$i] + $nums[$i-1] - 1;

        if ($cnt < $i) {
            $res[] = 'NO';
            $yes = true;
            break;
        }
//        $cnt--;
    }
    if (!$yes) $res[] = 'YES';
}
foreach ($res as $r) {
    echo $r . "\n";
}

<?php

$t = (int) trim(fgets(STDIN));
for ($i = 0; $i < $t; ++$i) {
    //i[]
    $ni[] = (int) trim(fgets(STDIN));
    $hi[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $t; ++$i) {
    $n = $ni[$i];
    $h = $hi[$i];
    echo (array_sum($h) >= $n * ($n - 1) / 2 ? 'YES' : 'NO').PHP_EOL;
}

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


You are walking through a parkway near your house. The parkway has $$$n+1$$$ benches in a row numbered from $$$1$$$ to $$$n+1$$$ from left to right. The distance between the bench $$$i$$$ and $$$i+1$$$ is $$$a_i$$$ meters.Initially, you have $$$m$$$ units of energy. To walk $$$1$$$ meter of distance, you spend $$$1$$$ unit of your energy. You can't walk if you have no energy. Also, you can restore your energy by sitting on benches (and this is the only way to restore the energy). When you are sitting, you can restore any integer amount of energy you want (if you sit longer, you restore more energy). Note that the amount of your energy can exceed $$$m$$$.Your task is to find the minimum amount of energy you have to restore (by sitting on benches) to reach the bench $$$n+1$$$ from the bench $$$1$$$ (and end your walk).You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$; $$$1 \le m \le 10^4$$$). The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the distance between benches $$$i$$$ and $$$i+1$$$.

For each test case, print one integer — the minimum amount of energy you have to restore (by sitting on benches) to reach the bench $$$n+1$$$ from the bench $$$1$$$ (and end your walk) in the corresponding test case.

NoteIn the first test case of the example, you can walk to the bench $$$2$$$, spending $$$1$$$ unit of energy, then restore $$$2$$$ units of energy on the second bench, walk to the bench $$$3$$$, spending $$$2$$$ units of energy, restore $$$1$$$ unit of energy and go to the bench $$$4$$$.In the third test case of the example, you have enough energy to just go to the bench $$$6$$$ without sitting at all.

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $long1 = trim(fgets(STDIN));
    $walk1 = trim(fgets(STDIN));

    $long = explode(" ", $long1);
    $walk = explode(" ", $walk1);
    $n = 0;
    $x = $long[1];

    for ($i = 0; $i < count($walk); $i++) {
        // $t += $walk[$i];
        if ($x >= $walk[$i]) {
            $x = $x - $walk[$i];
        } elseif ($x < $walk[$i]) {

            $n += $walk[$i] - $x;
            $x = 0;
        } else {
            $n += $walk[$i];
        }
    }
    array_push($array, $n);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$iter = InOutPut::get();

for($i=0; $i <$iter; $i++) {
    $ans = 0;
    $nAndM = InOutPut::getArr();
    $a = InOutPut::getArr();
    $sumOfa = array_sum($a);
    if($sumOfa - $nAndM[1] <= 0){
        $ans = 0;

    } else {
        $ans = $sumOfa - $nAndM[1];
    }
    InOutPut::print($ans);
}
class InOutPut {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArr()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function print($string)
    {
        echo $string . "\n";
    }
}
?>

<?php
$test = trim(fgets(STDIN));
$res = [];
for ($t = 0; $t < $test; $t++) {
    $input = explode(' ', trim(fgets(STDIN)));
    $n = intval($input[0]);
    $m = intval($input[1]);
    $a = [];
    $input = explode(' ', trim(fgets(STDIN)));
    for ($i = 0; $i < $n; $i++) {
        $a[$i] = intval($input[$i]);
    }
    $r = 0;
    for ($i = 0; $i < $n; $i++) {
        if ($m < $a[$i]) {
            $r += $a[$i] - $m;
            $m = 0;
        } else {
            $m -= $a[$i];
        }
    }
    $res[] = $r;
}

foreach ($res as $x) {
    echo "$x\n";
}

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647
define("ALPH", 'abcdefghijklmnopqrstuvwxyz');
$inter = "\n";
define("INTMAXVALUE",     2147483646);

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

 function solve()
 {
     list($n, $m) = IO::getArray();
     $a = IO::getArray();
     $ans = 0;

    $total = array_sum($a);

    $ans = $total > $m ? $total - $m : 0;
    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;
     }
 }

 class Algor {
     public static function efclidLcm($a, $b) {
         return ($a  / self::efclidGcd($a, $b)) * $b;
     }
     public static function efclidGcd($a, $b) {
             return $b > 0 ? self::efclidGcd($b, $a % $b) : $a;
     }
    public static function isPrime($n) {
         $d = 2;
         while ($n % $d != 0) {
         $d += 1;
         }

        return $d == $n;
    }

     public static function fabicon($n, $a) {
         if($n <= 1) {
             return $a[$n];
         }
         for($i=2; $i<=$n; $i++) {
             $a[$i] = $a[$i-1] + $a[$i-2];
         }

         return $a[$n];
     }

     function getRotate($a, $s, $e, $ind) {
         $ar = [];
         for ($i= $s; $i<=$e; $i++) {
             $ar[$i] = $a[$i];
             $j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
             // echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
             $a[$i] = $j < $i ? $ar[$j] : $a[$j];
         }
         return $a;
     }

}

class bigOperation {
     public static function efclidLcm($a, $b) {
         return bcmul(bcdiv($a,  self::efclidGcd($a, $b)), $b);
     }
     public static function efclidGcd($a, $b) {
             return bccomp($b, 0) == 1 ? self::efclidGcd($b, bcmod($a, $b)) : $a;
     }
    public static function  isBigNumber($n)
    {
        return bccomp($n, INTMAXVALUE) == 1;
    }
    // bcadd — Сложить 2 числа произвольной точности
    public static function  bcAdd($x, $y)
    {
        return bcadd($x, $y);
    }
// bccomp — Сравнение двух чисел произвольной точности
//return 1 if x>y, 0= x==y, -1 x < y
    public static function  bcComp($x, $y)
    {
        return bccomp($x, $y);
    }
// bcdiv — Операция деления для чисел произвольной точности
    public static function  bcDiv($x, $y)
    {
        return bcdiv($x, $y);
    }
// bcmod — Получает остаток от деления чисел с произвольной точностью
    public static function  bcMod($x, $y)
    {
        return bcmod($x, $y);
    }
// bcmul — Умножение двух чисел с произвольной точностью
    public static function  bcMul($x, $y)
    {
        return bcmul($x, $y);
    }
// bcpow — Возведение в степень чисел с произвольной точностью
    public static function  bcPow($x, $y)
    {
        return bcpow($x, $y);
    }
// bcpowmod — Возводит одно число в степень другого и возвращает остаток от деления результата на третье число
// bcscale — Задает количество чисел после десятичной точки по умолчанию для всех bc math функций.
// bcsqrt — Извлекает квадратный корень из числа с произвольной точностью
    public static function  bcSqrt($x, $y)
    {
        return bcsqrt($x, $y);
    }
// bcsub — Вычитает одно число с произвольной точностью из другого
    public static function  bcSub($x, $y)
    {
        return bcsub($x, $y);
    }
    public static function getMaxValue($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    public static function getMinValue($x, $y) {
        return bccomp($x, $y) == 1 ? $y : $x;
    }

    public static function getDareje($n, $k) {
        if($k == 0) {
            return 1;
        }
        return bcmul($n, self::getDareje($n, $k-1));
    }
}

class Sorting
{
    public static function mergeSort($aArray) {
        if(count($aArray) <= 1) {
            return $aArray;
        }
        $aLeft = [];
        $aRight = [];
        $n =floor(count($aArray) / 2);
        for($i = 0; $i <$n; $i++) {
            $aLeft[] = $aArray[$i];
        }
        for($i = $n; $i <count($aArray); $i++) {
            $aRight[] = $aArray[$i];
        }

        return self::merge(self::mergeSort($aLeft), self::mergeSort($aRight));
    }

    public static function merge($aLeft, $aRight) {
        $aResult = [];
        $iL = 0;
        $iR = 0;

        while($iL < count($aLeft) && $iR < count($aRight)) {
            if($aLeft[$iL] <= $aRight[$iR]) {
                $aResult[] = $aLeft[$iL];
                $iL++;
            } else {
                $aResult[] = $aRight[$iR];
                $iR++;
            }
        }

        while($iL < count($aLeft)) {
            $aResult[] = $aLeft[$iL];
            $iL++;
        }
        while($iR < count($aRight)) {
            $aResult[] = $aRight[$iR];
            $iR++;
        }

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $long1 = trim(fgets(STDIN));
    $walk1 = trim(fgets(STDIN));
    $long = explode($long1," ");
    $walk = explode($walk1," ");
    $n = 0;
    $x = $long[1];

    for ($i = 0; $i < count($walk); $i++) {
        // $t += $walk[$i];
        if ($x >= $walk[$i]) {
            $x = $x - $walk[$i];
        } elseif ($x < $walk[$i]) {

            $n += $walk[$i] - $x;
            $x = 0;
        } else {
            $n += $walk[$i];
        }
    }
    array_push($array, $n);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $long1 = trim(fgets(STDIN));
    $walk1 = trim(fgets(STDIN));
    $long = str_split($long1);
    $walk = str_split($walk1);
    $n = 0;
    $x = $long[1];

    for ($i = 0; $i < count($walk); $i++) {
        // $t += $walk[$i];
        if ($x >= $walk[$i]) {
            $x = $x - $walk[$i];
        } elseif ($x < $walk[$i]) {

            $n += $walk[$i] - $x;
            $x = 0;
        } else {
            $n += $walk[$i];
        }
    }
    array_push($array, $n);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $long = trim(fgets(STDIN));
    $walk = trim(fgets(STDIN));
    $n = 0;
    $x = $long[1];

    for ($i = 0; $i < count($walk); $i++) {
        // $t += $walk[$i];
        if ($x >= $walk[$i]) {
            $x = $x - $walk[$i];
        } elseif ($x < $walk[$i]) {

            $n += $walk[$i] - $x;
            $x = 0;
        } else {
            $n += $walk[$i];
        }
    }
    array_push($array, $n);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php
$array = [];
$t = (int)fgets(STDIN);
while ($t--) {
    $long = trim(fgets(STDIN));
    $walk = trim(fgets(STDIN));
    $n = 0;
    $x = $long[1];

    for ($i = 0; $i < count($walk); $i++) {
        // $t += $walk[$i];
        if ($x >= $walk[$i]) {
            $x = $x - $walk[$i];
        } elseif ($x < $walk[$i]) {

            $n += $walk[$i] - $x;
            $x = 0;
        } else {
            $n += $walk[$i];
        }
    }
    array_push($array, $t);
}
foreach ($array as $key => $value)
    print($value . "\r\n");
$end = readline();
?>

<?php

$t = (int)fgets(STDIN);
while ($t--) {
    $long = trim(fgets(STDIN));
    $walk = trim(fgets(STDIN));
    $n = 0;
    $x = $long[1];

    for ($i = 0; $i < count($walk); $i++) {
        // $t += $walk[$i];
        if ($x >= $walk[$i]) {
            $x = $x - $walk[$i];
        } elseif ($x < $walk[$i]) {

            $n += $walk[$i] - $x;
            $x = 0;
        } else {
            $n += $walk[$i];
        }
    }
    echo $n;
}

$end = readline();

?>

<?php
$arr2 = [];

$t = (int)fgets(STDIN);
while ($t--) {
    $long = trim(fgets(STDIN));
    $walk = trim(fgets(STDIN));
    $t = 0;
    $x = $long[1];

    for ($i = 0; $i < count($walk); $i++) {
        // $t += $walk[$i];
        if ($x >= $walk[$i]) {
            $x = $x - $walk[$i];
        } elseif ($x < $walk[$i]) {

            $t += $walk[$i] - $x;
            $x = 0;
        } else {
            $t += $walk[$i];
        }
    }
    echo $t;
}

$end = readline();
?>


Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through.It is known that there were N stops, all on different integer heights between 1 and N kilometers (inclusive) above the sea level. On the first day they've traveled from the first stop to the second stop, on the second day they've traveled from the second to the third and so on, and on the last day they've traveled from the stop N - 1 to the stop N and successfully finished their expedition.They are trying to find out which heights were their stops located at. They have an entry in a travel journal specifying how many days did they travel up the hill, and how many days did they walk down the hill.Help them by suggesting some possible stop heights satisfying numbers from the travel journal.

In the first line there is an integer non-negative number A denoting the number of days of climbing up the hill. Second line contains an integer non-negative number B — the number of days of walking down the hill (A + B + 1 = N, 1 ≤ N ≤ 100 000).

Output N space-separated distinct integers from 1 to N inclusive, denoting possible heights of the stops in order of visiting.


Mark is cleaning a row of $$$n$$$ rooms. The $$$i$$$-th room has a nonnegative dust level $$$a_i$$$. He has a magical cleaning machine that can do the following three-step operation.   Select two indices $$$i<j$$$ such that the dust levels $$$a_i$$$, $$$a_{i+1}$$$, $$$\dots$$$, $$$a_{j-1}$$$ are all strictly greater than $$$0$$$.  Set $$$a_i$$$ to $$$a_i-1$$$.  Set $$$a_j$$$ to $$$a_j+1$$$.  Mark's goal is to make $$$a_1 = a_2 = \ldots = a_{n-1} = 0$$$ so that he can nicely sweep the $$$n$$$-th room. Determine the minimum number of operations needed to reach his goal.

The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2\leq n\leq 2\cdot 10^5$$$) — the number of rooms. The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$0\leq a_i\leq 10^9$$$) — the dust level of each room. It is guaranteed that the sum of $$$n$$$ across all test cases does not exceed $$$2\cdot 10^5$$$.

For each test case, print a line containing a single integer — the minimum number of operations. It can be proven that there is a sequence of operations that meets the goal.

NoteIn the first case, one possible sequence of operations is as follows.   Choose $$$i=1$$$ and $$$j=2$$$, yielding the array $$$[1,1,0]$$$.  Choose $$$i=1$$$ and $$$j=3$$$, yielding the array $$$[0,1,1]$$$.  Choose $$$i=2$$$ and $$$j=3$$$, yielding the array $$$[0,0,2]$$$.  At this point, $$$a_1=a_2=0$$$, completing the process.In the second case, one possible sequence of operations is as follows.   Choose $$$i=4$$$ and $$$j=5$$$, yielding the array $$$[0,2,0,1,1]$$$.  Choose $$$i=2$$$ and $$$j=3$$$, yielding the array $$$[0,1,1,1,1]$$$.  Choose $$$i=2$$$ and $$$j=5$$$, yielding the array $$$[0,0,1,1,2]$$$.  Choose $$$i=3$$$ and $$$j=5$$$, yielding the array $$$[0,0,0,1,3]$$$.  Choose $$$i=4$$$ and $$$j=5$$$, yielding the array $$$[0,0,0,0,4]$$$. In the last case, the array already satisfies the condition.

<?php

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

function readInt() {
  return (int) read() ;
}

function readStrs() {
  return explode(" ",read()) ;
}

function readIntArray() {
  return array_map('intval', readStrs());
}

function readAsArray() {
  return str_split(read()) ;
}

function printLine($arg) {
  if($arg === false) {
    print_r("false") ;
  }
  elseif($arg === true) {
    print_r("true") ;
  }
  else {
    print_r($arg) ;
  }
  print_r("\n") ;
}

$t = readInt() ;

while($t--) {
	$n = readInt() ;
	$arr = readIntArray() ;

	$fi = -1 ;
	$su = 0 ;
	for ($i=0; $i< $n; $i++) {
		if($arr[$i] != 0) {
			$fi = $i ;
			break ;
		}
	}
	if($fi == -1) {
		$fi = $n ;
	}
	for ($i=$fi; $i < $n-1; $i++) {
		if($arr[$i] == 0) {
			$su += 1 ;
		}
		else $su += $arr[$i] ;
	}
	printLine($su) ;
}

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
//101
//101
//001
function solve()
{
    $n = IO::get();
    $a = IO::getArray();
    $ans = 0;
//    var_dump($a);
$z = 0;
     for($i=0; $i<$n-1; $i++) {
          if($a[$i] > 0) {
               $ans += $a[$i];
               $z = 1;
          } else {
               if($z > 0) {
                   $ans += 1;
               }
          }
     }
    IO::pr($ans);

}

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

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

<?php

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

function readInt() {
  return (int) read() ;
}

function readStrs() {
  return explode(" ",read()) ;
}

function readIntArray() {
  return array_map('intval', readStrs());
}

function readAsArray() {
  return str_split(read()) ;
}

function printLine($arg) {
  if($arg === false) {
    print_r("false") ;
  }
  elseif($arg === true) {
    print_r("true") ;
  }
  else {
    print_r($arg) ;
  }
  print_r("\n") ;
}

$t = readInt() ;

while($t--) {
	$n = readInt() ;
	$arr = readIntArray() ;

	$fi = -1 ;
	$su = 0 ;
	for ($i=0; $i< $n; $i++) {
		if($arr[$i] != 0) {
			$fi = $i ;
			break ;
		}
	}
	for ($i=$fi; $i < $n-1; $i++) {
		if($arr[$i] == 0) {
			$su += 1 ;
		}
		else $su += $arr[$i] ;
	}
	printLine($su) ;
}


Polycarp wants to cook a soup. To do it, he needs to buy exactly $$$n$$$ liters of water.There are only two types of water bottles in the nearby shop — $$$1$$$-liter bottles and $$$2$$$-liter bottles. There are infinitely many bottles of these two types in the shop.The bottle of the first type costs $$$a$$$ burles and the bottle of the second type costs $$$b$$$ burles correspondingly.Polycarp wants to spend as few money as possible. Your task is to find the minimum amount of money (in burles) Polycarp needs to buy exactly $$$n$$$ liters of water in the nearby shop if the bottle of the first type costs $$$a$$$ burles and the bottle of the second type costs $$$b$$$ burles. You also have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. The next $$$q$$$ lines contain queries. The $$$i$$$-th query is given as three space-separated integers $$$n_i$$$, $$$a_i$$$ and $$$b_i$$$ ($$$1 \le n_i \le 10^{12}, 1 \le a_i, b_i \le 1000$$$) — how many liters Polycarp needs in the $$$i$$$-th query, the cost (in burles) of the bottle of the first type in the $$$i$$$-th query and the cost (in burles) of the bottle of the second type in the $$$i$$$-th query, respectively.

Print $$$q$$$ integers. The $$$i$$$-th integer should be equal to the minimum amount of money (in burles) Polycarp needs to buy exactly $$$n_i$$$ liters of water in the nearby shop if the bottle of the first type costs $$$a_i$$$ burles and the bottle of the second type costs $$$b_i$$$ burles.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     list($b, $c, $d) = explode(" ", trim(fgets(STDIN)));
     $e = $c / 1;
     $f = $d / 2;
     if($e <= $f)
     {
          print bcmul($b, $c);
     }
     else
     {
          $g = bcmod($b, 2);
          if($g == 0)
          {
               print bcmul(bcdiv($b, 2), $d);
          }
          else
          {
               print bcadd(bcmul(bcdiv(bcsub($b, 1), 2), $d), $c);
          }
     }
     print "\n";
}
?>

<?php
fscanf(STDIN,"%d",$tc);
while($tc--)
{
		fscanf(STDIN,"%s %s %s",$n,$a,$b);
		$firstBottle=$n;
		$secndBottle=bcdiv($n,2);
		$money1=bcmul($firstBottle,$a);
		if(bcmod($n,2)==1)
		{
			$money2=bcadd(bcmul($secndBottle,$b),$a);
		}
		else
			$money2=bcmul($secndBottle,$b);
		if($money1<=$money2)
			echo "$money1\n";
		else
			echo "$money2\n";
}

<?php

$q = trim(fgets(STDIN));

$ans = '';

for($i = 0; $i<$q; $i++){
	$data = explode(' ', trim(fgets(STDIN)));
	$s = $data[0];
	$a = $data[1];
	$b = $data[2];
	$sum = 0;

	if(bccomp(2*$a, $b) == -1){
	    $b = bcmul(2, $a);
	}

	$sum = bcadd(bcmul(bcdiv($s, 2), $b), bcmul(bcmod($s, 2),$a));

	$ans .= $sum."\n";
}

fwrite(STDOUT, $ans);

?>

<?php

$q = trim(fgets(STDIN));

$ans = '';

for($i = 0; $i<$q; $i++){
	$data = explode(' ', trim(fgets(STDIN)));
	$s = $data[0];
	$a = $data[1];
	$b = $data[2];
	$sum = 0;

	if($a <= $b/2){
	    $sum = bcmul($s,$a);
	}else{
	    $p1 = bcmul($s/2, $b);
	    $p2 = bcmul($s%2, $a);
	    $sum = bcadd($p1,$p2);
	}

	$ans .= $sum."\n";
}

fwrite(STDOUT, $ans);

?>

<?php

$q = trim(fgets(STDIN));

$ans = '';

for($i = 0; $i<$q; $i++){
	$data = explode(' ', trim(fgets(STDIN)));
	$s = $data[0];
	$a = $data[1];
	$b = $data[2];
	$sum = 0;

	if(bccomp($a, bcdiv($b,2)) == -1){
	    $sum = bcmul($s,$a);
	}else{
	    $p1 = bcmul(bcdiv($s,2), $b);
	    $p2 = bcmul(bcmod($s,2), $a);
	    $sum = bcadd($p1,$p2);
	}

	$ans .= $sum."\n";
}

fwrite(STDOUT, $ans);

?>


An array of integers $$$p_1, p_2, \dots, p_n$$$ is called a permutation if it contains each number from $$$1$$$ to $$$n$$$ exactly once. For example, the following arrays are permutations: $$$[3, 1, 2]$$$, $$$[1]$$$, $$$[1, 2, 3, 4, 5]$$$ and $$$[4, 3, 1, 2]$$$. The following arrays are not permutations: $$$[2]$$$, $$$[1, 1]$$$, $$$[2, 3, 4]$$$.Polycarp invented a really cool permutation $$$p_1, p_2, \dots, p_n$$$ of length $$$n$$$. It is very disappointing, but he forgot this permutation. He only remembers the array $$$q_1, q_2, \dots, q_{n-1}$$$ of length $$$n-1$$$, where $$$q_i=p_{i+1}-p_i$$$.Given $$$n$$$ and $$$q=q_1, q_2, \dots, q_{n-1}$$$, help Polycarp restore the invented permutation.

The first line contains the integer $$$n$$$ ($$$2 \le n \le 2\cdot10^5$$$) — the length of the permutation to restore. The second line contains $$$n-1$$$ integers $$$q_1, q_2, \dots, q_{n-1}$$$ ($$$-n < q_i < n$$$).

Print the integer -1 if there is no such permutation of length $$$n$$$ which corresponds to the given array $$$q$$$. Otherwise, if it exists, print $$$p_1, p_2, \dots, p_n$$$. Print any such permutation if there are many of them.


There is a house with $$$n$$$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i = 1$$$ if in the $$$i$$$-th flat the light is on and $$$a_i = 0$$$ otherwise.Vova thinks that people in the $$$i$$$-th flats are disturbed and cannot sleep if and only if $$$1 < i < n$$$ and $$$a_{i - 1} = a_{i + 1} = 1$$$ and $$$a_i = 0$$$.Vova is concerned by the following question: what is the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $$$k$$$.

The first line of the input contains one integer $$$n$$$ ($$$3 \le n \le 100$$$) — the number of flats in the house. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$a_i \in \{0, 1\}$$$), where $$$a_i$$$ is the state of light in the $$$i$$$-th flat.

Print only one integer — the minimum number $$$k$$$ such that if people from exactly $$$k$$$ pairwise distinct flats will turn off the light then nobody will be disturbed.

NoteIn the first example people from flats $$$2$$$ and $$$7$$$ or $$$4$$$ and $$$7$$$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example.There are no disturbed people in second and third examples.

<?php
$a = trim(fgets(STDIN));
$b = " " . trim(fgets(STDIN));
$c = 0;
$d = 1;
while(TRUE)
{
     $e = strpos($b, "1 0 1", $d);
     if($e == TRUE)
     {
          $c++;
          $d = $e + 5;
     }
     else
     {
          break;
     }
}
print $c;
?>

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

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$a = $ir->readArrayOfInt($n, 1);

$cnt = 0;
for ($i=2; $i<$n; $i++) {
	if ($a[$i]==0 && $a[$i-1] && $a[$i+1]) {
		$a[$i+1] = 0;
		$cnt ++;
	}
}

echo $cnt;


Vasya has two arrays $$$A$$$ and $$$B$$$ of lengths $$$n$$$ and $$$m$$$, respectively.He can perform the following operation arbitrary number of times (possibly zero): he takes some consecutive subsegment of the array and replaces it with a single element, equal to the sum of all elements on this subsegment. For example, from the array $$$[1, 10, 100, 1000, 10000]$$$ Vasya can obtain array $$$[1, 1110, 10000]$$$, and from array $$$[1, 2, 3]$$$ Vasya can obtain array $$$[6]$$$.Two arrays $$$A$$$ and $$$B$$$ are considered equal if and only if they have the same length and for each valid $$$i$$$ $$$A_i = B_i$$$.Vasya wants to perform some of these operations on array $$$A$$$, some on array $$$B$$$, in such a way that arrays $$$A$$$ and $$$B$$$ become equal. Moreover, the lengths of the resulting arrays should be maximal possible.Help Vasya to determine the maximum length of the arrays that he can achieve or output that it is impossible to make arrays $$$A$$$ and $$$B$$$ equal.

The first line contains a single integer $$$n~(1 \le n \le 3 \cdot 10^5)$$$ — the length of the first array. The second line contains $$$n$$$ integers $$$a_1, a_2, \cdots, a_n~(1 \le a_i \le 10^9)$$$ — elements of the array $$$A$$$. The third line contains a single integer $$$m~(1 \le m \le 3 \cdot 10^5)$$$ — the length of the second array. The fourth line contains $$$m$$$ integers $$$b_1, b_2, \cdots, b_m~(1 \le b_i \le 10^9)$$$ - elements of the array $$$B$$$.

Print a single integer — the maximum length of the resulting arrays after some operations were performed on arrays $$$A$$$ and $$$B$$$ in such a way that they became equal. If there is no way to make array equal, print "-1".