<?
error_reporting(0);

$fp = fopen("php://stdin",'r');
//$fp = fopen('D:\work\php\codeforce\div2(142)\AAA_data.php','r');
list($s, $n) = explode(' ', trim( fgets($fp) ) );

$dragons = array();
while($n--)
{
	list($sn, $add) = explode(' ', trim( fgets($fp) ) );
	$dragons[$sn] += $add;
}
ksort($dragons);
$result = true;
foreach($dragons as $k => $v)
{
	if($s > $k)
	{
		$s += $v;
	} else {
		$result = false;
		break;
	}
}
echo ($result) ? 'YES' : 'NO';
fclose($fp);
?>

<?php

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

list($s, $n) = explode(" ", trim(fgets(STDIN)));
$a = array();
for($i=0;$i<$n;$i++){
  $a[] = explode(" ", trim(fgets(STDIN)));
}
usort($a, 'cmp');

foreach($a as $k=>$v){
  if ($s <= $v[0]){
    echo "NO" . PHP_EOL;
    exit();
  }
  $s+=$v[1];
}

echo "YES" . PHP_EOL;
//fclose($fp);

function cmp($a, $b){
  if ($a[0] > $b[0]) return 1;
  if ($a[0] < $b[0]) return -1;
  if ($a[1] > $b[1]) return -1;
  if($a[0] > $b[0]) return 1;
  return 0;
}

<?php
list ($power,$n) = explode(" ",trim(fgets(STDIN)));
$alive = true;
$powerArray = array();
for ($i=0;$i<$n;$i++)
{
    $powerArray[] = explode(" ",trim(fgets(STDIN)));
}
sort($powerArray);
for ($i=0;$i<$n;$i++)
{
    if ($power>$powerArray[$i][0])$power+=$powerArray[$i][1];
    else $alive=false;
}
if ($alive)echo "YES";
else echo "NO";

<?php

$input=explode(' ',trim(fgets(STDIN)));

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

sort($ara);

$sum=$s;

for($i=0;$i<$n;$i++)    {
	if($sum<=$ara[$i][0])        die("NO\n");
	$sum+=$ara[$i][1];
}
echo "YES\n";

?>

<?php

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

$dragons = array();

list($power, $n) = fscanf($f, "%d %d");

for ($j = 0; $j < $n; $j++) {
    list($a, $b) = fscanf($f, "%d %d");
    $dragons[] = $a;
    $levels[] = $b;

}

fclose($f);

array_multisort($dragons, $levels);

foreach ($dragons as $j => $i) {
    if ($power > $i) {
        $power+= $levels[$j];
    } else {
        print 'NO';
        die();
    }
}

print 'YES';

<?php
// 230A     Драконы
$in = fopen("php://stdin", 'r');

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

$arr = array(array());

for ($i=0; $i < $n; $i++) {
    $input_line = fgets($in);
    $arr[$i] = preg_split('/ /', substr($input_line, 0, strlen($input_line)-2), -1, PREG_SPLIT_NO_EMPTY);
}

/* Двумерный массив  */
usort($arr, "compare"); // Вызываем пользовательскую сортировку
  /* Функция для нашей сортировки */
  function compare ($v1, $v2) {
    /* Сравниваем значение по ключу date_reg */
    if ($v1[0] == $v2[0]) return 0;
    return ((int) $v1[0] < (int) $v2[0])? -1: 1;
  }
  //print_r($arr); // Выводим отсортированный массив

$out = "YES";

for ($i=0; $i < $n; $i++) {
    if ($s > $arr[$i][0]) {
        $s += $arr[$i][1];
    } else {
        $out = "NO";
        break;
    }
}

echo $out;

?>

<?php

function cmp($a, $b) {
        if ($a[0] == $b[0]) {
                return 0;
        }
        return ($a[0] < $b[0]) ? -1 : 1;
}

$line = fgets(STDIN);
$expd = explode(" ",$line);
$s = $expd[0];
$n = $expd[1];
$arr = [];
for($i=0; $i<$n; $i++){
    $line = fgets(STDIN);
    $expd = explode(" ",$line);
    $arr[] = [$expd[0], $expd[1]];
}
usort($arr,"cmp");

foreach($arr as $a){
    if($s <= $a[0]){
        echo "NO";
        exit;
    }
    else $s += $a[1];
}

echo "YES";

<?PHP
list($s, $n) = explode(' ', fgets(STDIN));
for ($i = 0; $i < $n; $i++) {
    list($ds, $bo) = explode(' ', fgets(STDIN));
    $da[] = array('ds' => $ds, 'bo' => $bo);
}
//print_r($da);
foreach ($da as $key => $row) {
    $ds1[$key] = $row['ds'];
    $bo1[$key] = $row['bo'];
}

array_multisort($ds1, SORT_ASC, $bo1, SORT_ASC, $da);
//print_r($da);
$res = 'YES';
foreach ($da as $key => $row) {
    //print_r($row);
    if ($s <= $row['ds'])
        $res = 'NO';
    if ($res == 'YES')
        $s = $s + $row['bo'];
}
echo "$res\n";
?>

<?php
error_reporting("off");
//230A: Dragons
list($s, $n) = explode(" ", trim(fgets(STDIN))); //$s = 10; $n = 1;
//$array = array("100 100");
for ($i = 0; $i < $n; $i++) {
    list($a, $b) = explode(" ", trim(fgets(STDIN))); //list($a, $b) = explode(" ", $array[$i]);
    if ($a < $s) {
        $s += $b; //eliminate the dragons we can right off the bat, even increasing our strength
    } else {
        $x[] = $a;
        $y[] = $b;
    }
}
asort($x);
$echome = "YES";
foreach ($x as $key => $value) {
    if ($value >= $s) {
        $echome = "NO";
        break;
    } else {
        $s += $y[$key];
        unset($x[$key]);
    }
}

echo $echome;
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array();
$d = array();
$i = 0;
$j = 0;
for($x = 1; $x <= $b; $x++)
{
    list($e, $f) = explode(" ", trim(fgets(STDIN)));
    array_push($c, $e);
    array_push($d, $f);
}
asort($c);
$g = array_keys($c);
sort($c);
for($x = 0; $x < $b; $x++)
{
    $i++;
    if($a > $c[$x])
    {
        $j++;
        $a += $d[$g[$x]];
    }
}
if($i == $j)
{
    print "YES";
}
else
{
    print "NO";
}
?>

<?php

error_reporting(0);

solve();

function solve(){

	//$Input = new Input("input.txt");
	$Input = new Input();

	$S = (int)$Input->in();
	$N = (int)$Input->in();

	for ($i = 0; $i < $N; $i++)
	{
		//$X[(int)$Input->in()] = (int)$Input->in();
		$X[] = (int)$Input->in();
		$Y[] = (int)$Input->in();
	}

	asort($X);

	$flag = 0;

	foreach ($X as $key => $x)
	{
		if ($x >= $S)
		{
			$flag = 1;
			break;
		} else {
			$S += $Y[$key];
		}
	}

	if ($flag === 1) print("NO");
	else print("YES");

	$Input->close();
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = array();
$d = array();
$i = 0;
$j = 0;
for($x = 1; $x <= $b; $x++)
{
    list($e, $f) = explode(" ", trim(fgets(STDIN)));
    array_push($c, $e);
    array_push($d, $f);
}
asort($c);
$g = array_keys($c);
$h = array_combine($g, $d);
sort($c);
for($x = 0; $x < $b; $x++)
{
    $i++;
    if($a > $c[$x])
    {
        $j++;
        $a += $h[$x];
    }
}
if($i == $j)
{
    print "YES";
}
else
{
    print "NO";
}
?>

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

<?php

error_reporting(0);

solve();

function solve(){

	//$Input = new Input("input.txt");
	$Input = new Input();

	$S = (int)$Input->in();
	$N = (int)$Input->in();

	for ($i = 0; $i < $N; $i++)
	{
		$X[(int)$Input->in()] = (int)$Input->in();
	}

	ksort($X);

	$flag = 0;

	foreach ($X as $x => $y)
	{
		if ($x >= $S)
		{
			$flag = 1;
			break;
		} else {
			$S += $y;
		}
	}

	if ($flag === 1) print("NO");
	else print("YES");

	$Input->close();
}

class Input{
	private $handle = "";
	private $values = array();
	private $index = 0;

	public function __construct($localfile){

		if (is_file($localfile)) {

			$this->handle = fopen($localfile, "r");
			$contents = stream_get_contents($this->handle);

		} else {

			$contents = stream_get_contents(STDIN);

		}

		$no_newlines = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->values = explode(" ", $no_newlines);
	}

	public function in(){

		return $this->values[$this->index++];

	}

	public function close(){

		if (is_file($localfile) && feof($this->handle)) fclose($this->handle);

	}
}

?>

<?php
list ($power,$n) = explode(" ",trim(fgets(STDIN)));
$alive = true;
for ($i=0;$i<$n;$i++)
{
    list ($drakoPower,$drakoBonus)= explode(" ",trim(fgets(STDIN)));
    if ($power>$drakoPower)$power+=$drakoBonus;
    else $alive=false;
}
if ($alive)echo "YES";
else echo "NO";

<?php
list ($power,$n) = explode(" ",trim(fgets(STDIN)));
$alive = true;
$powerArray = array();
for ($i=0;$i<$n;$i++)
{
    $powerArray[] = explode(" ",trim(fgets(STDIN)));
}
sort($powerArray);
for ($i=0;$i<$n;$i++)
{
    if ($power>$powerArray[$i][0])$power+=$powerArray[$i][1];
    else $alive=false;
}
if ($alive)echo "YES";
echo "NO";

<?php
list ($power,$n) = explode(" ",trim(fgets(STDIN)));
$alive = true;
$powerArray = array();
for ($i=0;$i<$n;$i++)
{
    $tempCouple = explode(" ",trim(fgets(STDIN)));
    $powerArray[] = $tempCouple;
    sort($powerArray);
}
$max = $powerArray[$n-1][0];
$k=0;
while (($alive)&&($k<$n)&&($power<$max))
{
    if ($power<=$powerArray[$k][0])$alive = false;
    else
    {
        $power+=$powerArray[$k][1];
        $k++;
    }
}
if ($alive)echo "YES";
else echo "NO";

<?php
list ($power,$n) = explode(" ",trim(fgets(STDIN)));
$alive = true;
$powerArray = array();
for ($i=0;$i<$n;$i++)
{
    $tempCouple = explode(" ",trim(fgets(STDIN)));
    $powerArray[] = $tempCouple;
    sort($powerArray);
}
echo $max = $powerArray[count($powerArray)-1][0];
for ($i=0;$i<$n;$i++)
{
    if ($power > $max)break;
    else
    {
        if ($power > $powerArray[$i][0])
        {
            $power+=$powerArray[$i][1];
        }
        else
        {
            $alive = false;
            break;
        }
    }
}
if ($alive)echo "YES";
else echo "NO";

<?php

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

list($s,$n) =  explode(" ",trim(fgets($f)));

for($i=0;$i<$n;$i++){
    list($a,$b) = explode(" ",trim(fgets($f)));

    if ($s>=$a){
        $s = $s+$b;
    }
    if ($s<$a){
        echo "NO";
        exit;
    }
}

echo "YES";

<?php
$line = fgets(STDIN);
$expd = explode(" ",$line);
$s = $expd[0];
$n = $expd[1];
$arr = [];
for($i=0; $i<$n; $i++){
    $line = fgets(STDIN);
    $expd = explode(" ",$line);
    $arr[$expd[0]] = $expd[1];
}
ksort($arr);

foreach($arr as $key => $value){
    if($s < $key){
        echo "NO";
        exit;
    }
    else $s += $value;
}

echo "YES";

<?php
$line = fgets(STDIN);
$expd = explode(" ",$line);
$s = $expd[0];
$n = $expd[1];
$arr = [];
for($i=0; $i<$n; $i++){
    $line = fgets(STDIN);
    $expd = explode(" ",$line);
    $arr[$expd[0]] = $expd[1];
}
ksort($arr);

foreach($arr as $key => $value){
    if($s <= $key){
        echo "NO";
        exit;
    }
    else $s += $value;
}

echo "YES";

<?php
$line = fgets(STDIN);
$expd = explode(" ",$line);
$s = $expd[0];
$n = $expd[1];
$arr = [];
for($i=0; $i<$n; $i++){
    $line = fgets(STDIN);
    $expd = explode(" ",$line);
    $arr[$expd[0]] = $expd[1];
}
ksort($arr);

foreach($arr as $key => $value){
    if($s < $key){
        echo "NO";
        exit;
    }
    else $s = $value;
}

echo "YES";


<?php

function rline(): array
{
    return explode(' ', trim(fgets(STDIN)));
}

function pline($var): void
{
    print(strval($var));
    print(PHP_EOL);
}

function plines(array $arr): void
{
    print(implode(PHP_EOL, $arr));
    print(PHP_EOL);
}

function fbool($var): string
{
    return $var ? 'Yes' : 'No';
}

function ints($arr): array
{
    return array_map(function ($elem) {
        return intval($elem);
    }, $arr);
}

function solve(): void
{
    list($q) = rline();
    $ans = [];
    for ($i = 0; $i < $q; $i++) {
        list($n) = ints(rline());
        $a = ints(rline());

        $subans = true;
        $sides = array_count_values($a);
        foreach (array_keys($sides) as $len) {
            if ($sides[$len] % 2 !== 0) {
                $subans = false;
                break;
            }
            $sides[$len] /= 2;
        }
        if (!$subans) {
            $ans[] = strtoupper(fbool($subans));
            continue;
        }

        $area = -1;
        $lens = array_keys($sides);
        sort($lens);
        while (!empty($lens)) {
            $h = array_shift($lens);
            if (empty($lens)) {
                $w = $h;
            } else {
                $w = array_pop($lens);
            }
            if ($area !== -1 && $h * $w !== $area) {
                $subans = false;
                break;
            }
            $area = $h * $w;
            if ($sides[$h] !== $sides[$w]) {
                $subans = false;
                break;
            }
        }

        $ans[] = strtoupper(fbool($subans));
    }

    // print here
    plines($ans);
}

solve();


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


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


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


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


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

}

?>


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

?>


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

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


<?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
$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
$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
$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
$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();
?>


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


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

?>


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


<?php

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

$data = array();
for ($i=0; $i<$col; $i++)
$data[] = explode(' ', trim(fgets(STDIN)));

$result = 0;
for ($i=0; $i<$col; $i++) {
	$x = $data[$i][0];
	$y = $data[$i][1];

	$tochka = array(
		'left' => 0,
		'right' => 0,
		'up' => 0,
		'down' => 0,
	);

	for($j=0; $j<$col; $j++)
		if ($i != $j) {
			$x_s = $data[$j][0];
			$y_s = $data[$j][1];

			if ($x > $x_s and $y == $y_s) $tochka['right']++;
			elseif ($x < $x_s and $y == $y_s) $tochka['left']++;
			elseif ($x == $x_s and $y > $y_s) $tochka['up']++;
			elseif ($x == $x_s and $y < $y_s) $tochka['down']++;
		}

	if ($tochka['right'] and $tochka['left'] and $tochka['up'] and $tochka['down']) $result++;
}

print $result;

<?php
$openFile = fopen('php://stdin','r');
$lines = stream_get_contents($openFile);
/*
$lines = '8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3';

$lines = '5
0 0
0 1
1 0
0 -1
-1 0';
*/
$data = explode("\n", trim($lines));
$list = array();
for($i = 1 ; $i < count($data) ; $i++)
{
    $coords = explode(" ", trim($data[$i]));
    $list[] = array("x" => (int)$coords[0] , "y" => (int)$coords[1]);
}

$result = 0;
for($i = 0 ; $i < count($list) ; $i++)
{
    $flagTop = false;
    $flagRight = false;
    $flagBottom = false;
    $flagLeft = false;
    for($j = 0 ; $j < count($list) ; $j++)
    {
        if($i != $j)
        {
            if($list[$i]["x"] < $list[$j]["x"] && $list[$i]["y"] == $list[$j]["y"])
            {
                $flagRight = true;
            }
            if($list[$i]["x"] > $list[$j]["x"] && $list[$i]["y"] == $list[$j]["y"])
            {
                $flagLeft = true;
            }
            if($list[$i]["x"] == $list[$j]["x"] && $list[$i]["y"] > $list[$j]["y"])
            {
                $flagBottom = true;
            }
            if($list[$i]["x"] == $list[$j]["x"] && $list[$i]["y"] < $list[$j]["y"])
            {
                $flagTop = true;
            }
        }
        if($flagTop && $flagRight && $flagBottom && $flagLeft)
        {
            $result++;
            break;
        }
    }
}
echo $result;
?>

<?php

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

$n = trim(fgets($stdin));

$points = array();
for($i = 0; $i < $n; $i++) {
    $points[] = explode(" ", trim(fgets($stdin)));
}

// 0 - x
// 1 - y

$result = 0;
foreach($points as $i=>$point1) {
    $l = false;
    $r = false;
    $t = false;
    $d = false;
    foreach($points as $j=>$point2) {
        if($point2[0] > $point1[0] && $point2[1] == $point1[1]) {
            $l = true;
        }
        if($point2[0] < $point1[0] && $point2[1] == $point1[1]) {
            $r = true;
        }
        if($point2[0] == $point1[0] && $point2[1] > $point1[1]) {
            $t = true;
        }
        if($point2[0] == $point1[0] && $point2[1] < $point1[1]) {
            $d = true;
        }

        if($l && $r && $t && $d) {
            $result++;
            break;
        }
    }
}

echo $result;

//file_put_contents("out.txt", $result);
?>

<?php
$arr = array();
while(($line = fgets(STDIN)) != false)
{
    $arr[] = $line;
}

list($N) = explode(" ", trim($arr[0]));

$count = 0;

$left   = false;
$right  = false;
$top    = false;
$bottom = false;

for ($i=1; $i<=$N; $i++) {
    list($x, $y) = explode(" ", trim($arr[$i]));
    $top    = false;
    $bottom = false;
    $right  = false;
    $left   = false;
    for ($j=1; $j<=$N; $j++) {
        list($x1, $y1) = explode(" ", trim($arr[$j]));
        if ($x1 > $x && $y1 == $y) {
            $right = true;
        } else if ($x1 < $x && $y1 == $y) {
            $left = true;
        } else if ($x1 == $x && $y1 < $y) {
            $bottom = true;
        } else if ($x1 == $x && $y1 > $y) {
            $top = true;
        }

        if ($top && $bottom && $right && $left) {
            $count++;
            break;

        }

    }

}

fputs(STDOUT, $count);

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	for ($i = 0; $i < $inp_N; $i++) {
		$inp_arr[$i][] = (int)$Scanner->Scan();
		$inp_arr[$i][] = (int)$Scanner->Scan();
	}

	$POINT = 0;
	for ($i = 0; $i < $inp_N; $i++) {
		$c_left = 0;
		$c_right = 0;
		$c_upper = 0;
		$c_lower = 0;
		for ($j = 0; $j < $inp_N; $j++) {
			if ($inp_arr[$i][0] > $inp_arr[$j][0] && $inp_arr[$i][1] === $inp_arr[$j][1]) $c_left++;
			elseif ($inp_arr[$i][0] < $inp_arr[$j][0] && $inp_arr[$i][1] === $inp_arr[$j][1]) $c_right++;
			elseif ($inp_arr[$i][0] === $inp_arr[$j][0] && $inp_arr[$i][1] < $inp_arr[$j][1]) $c_upper++;
			elseif ($inp_arr[$i][0] === $inp_arr[$j][0] && $inp_arr[$i][1] > $inp_arr[$j][1])$c_lower++;
			if ($c_left > 0 && $c_right > 0 && $c_upper > 0 && $c_lower > 0) break;
		}
		if ($c_left > 0 && $c_right > 0 && $c_upper > 0 && $c_lower > 0) $POINT++;
		//echo $POINT;
	}
	print($POINT);
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

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

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

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

== function end ======
*/

?>

<?php
    $input = array();
    while(($line = fgets(STDIN)) != false)
    {
        $input[] = trim($line);
    }
    $count = (int)$input[0];
    $arr = array();
    $count_input = count($input);
    for ($i = 1; $i < $count_input; $i++)
    {
        $arr[] = explode(" ", $input[$i]);
    }
    $count_main = 0;
    $count_arr = count($arr);
    for ($i = 0; $i < $count_arr; $i++)
    {
        $point = $arr[$i];
        $left = FALSE;
        $right = FALSE;
        $top = FALSE;
        $bottom = FALSE;
        for ($j = 0; $j < $count_arr; $j++)
        {
            $temp = $arr[$j];
            // Левый сосед
            if ($point[0] < $temp[0] && $point[1] == $temp[1])
            {
                $left = TRUE;
            }
            // Правый сосед
            if ($point[0] > $temp[0] && $point[1] == $temp[1])
            {
                $right = TRUE;
            }
            // Верхний сосед
            if ($point[0] == $temp[0] && $point[1] < $temp[1])
            {
                $top = TRUE;
            }
            // Нижний сосед
            if ($point[0] == $temp[0] && $point[1] > $temp[1])
            {
                $bottom = TRUE;
            }
        }
        if ($left and $right and $top and $bottom)
        {
            $count_main++;
        }
    }
    fputs(STDOUT, $count_main);
?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	for ($i = 0; $i < $inp_N; $i++) {
		$inp_arr[$i][] = (int)$Scanner->Scan();
		$inp_arr[$i][] = (int)$Scanner->Scan();
	}

	$POINT = 0;
	for ($i = 0; $i < $inp_N; $i++) {
		for ($j = 0; $j < $inp_N; $j++) {
			$c_left = 0;
			$c_right = 0;
			$c_upper = 0;
			$c_lower = 0;
			if ($inp_arr[$i][0] > $inp_arr[$j][0] && $inp_arr[$i][1] === $inp_arr[$j][1]) $c_left++;
			elseif ($inp_arr[$i][0] < $inp_arr[$j][0] && $inp_arr[$i][1] > $inp_arr[$j][1]) $c_right++;
			elseif ($inp_arr[$i][0] === $inp_arr[$j][0] && $inp_arr[$i][1] < $inp_arr[$j][1]) $c_upper++;
			elseif ($inp_arr[$i][0] === $inp_arr[$j][0] && $inp_arr[$i][1] > $inp_arr[$j][1])$c_lower++;
			if ($c_left > 0 && $c_right > 0 && $c_upper > 0 && $c_lower > 0) break;
		}
		if ($c_left > 0 && $c_right > 0 && $c_upper > 0 && $c_lower > 0) $POINT++;
	}
	printf("%d", $POINT);
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

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

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

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

== function end ======
*/

?>

<?php
error_reporting(0);

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$inp_N = (int)$Scanner->Scan();
	for ($i = 0; $i < $inp_N; $i++) {
		$inp_arr[$i][] = (int)$Scanner->Scan();
		$inp_arr[$i][] = (int)$Scanner->Scan();
	}

	$POINT = 0;
	for ($i = 0; $i < $inp_N; $i++) {
		for ($j = 0; $j < $inp_N; $j++) {
			$c_left = 0;
			$c_right = 0;
			$c_upper = 0;
			$c_lower = 0;
			if ($inp_arr[$i][0] > $inp_arr[$j][0] && $inp_arr[$i][1] === $inp_arr[$j][1]) $c_left++;
			elseif ($inp_arr[$i][0] < $inp_arr[$j][0] && $inp_arr[$i][1] === $inp_arr[$j][1]) $c_right++;
			elseif ($inp_arr[$i][0] === $inp_arr[$j][0] && $inp_arr[$i][1] < $inp_arr[$j][1]) $c_upper++;
			elseif ($inp_arr[$i][0] === $inp_arr[$j][0] && $inp_arr[$i][1] > $inp_arr[$j][1])$c_lower++;
			if ($c_left > 0 && $c_right > 0 && $c_upper > 0 && $c_lower > 0) break;
		}
		if ($c_left > 0 && $c_right > 0 && $c_upper > 0 && $c_lower > 0) $POINT++;
	}
	printf("%d", $POINT);
	$Scanner->close();
}

ob_end_clean();
solve();

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link or ''php://stdin' err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		//err $c_row = array("\n", "\r", "\r\n");
		$c_row = array("\r\n", "\r", "\n");
		$contents = str_replace($c_row, " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	function Scan(){
		$x = $this->Id;
		$sc = $this->Scanners[$x];
		$this->Id = ++$x;
		return $sc;
	}

	function close(){
		fclose($this->Stream);
	}
}

/*
====begin=====

//input    $inp_ or upper
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $^Upper

====end=======

===== class begin =====

//error_reporting(0);
//$Scanner = new Scanner("php://stdin");
//ref "#109_div2_B_1230942 laurenceHR"
class LineScanner{
	private $Stream;
	private $Scanners = array();
	private $LineIds_Of_ScanIds= array();
	private $LinesScanners = array();
	private $LastScanIds_Of_LineIds = array();
	private $Scan_number = 0;
	private $Scanline_number = 0;

	public function __construct($opend){
		if((!is_file($opend) && !is_link($opend)) && $opend !== "php://stdin"){
  			print("file or link err");
  			exit;
		}

		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);

		$temp_lines = explode("\n", $contents);
		$temp_linescanners = array();
		$temp_x = 0;
		$temp_y = 0;
		//--attention for initting of array--(these is not needed but for easily reading)//
		$ttemp_scanners = array();
		//$del = Array("\n","\r","\n\r");
		foreach ($temp_lines as $as_line) {
			if (strlen($as_line) === 0) {
				print("input err");
			}

			//$as_line = str_replace($del,'',$as_line);
			$temp_linescanners[] = $as_line;
			$ttemp_line_scanners = explode(" ", $as_line);
			//$ttemp_scanners = array();
			foreach ($ttemp_line_scanners as $as_sc) {
				$ttemp_scanners[] = $as_sc;
				$this->LineIds_Of_ScanIds[$temp_x] = $temp_y;
				$temp_x++;
			}
			$this->LastScanIds_Of_LineIds[$temp_y] = $temp_x - 1;
			$temp_y++;
		}
		$this->Scanners = $ttemp_scanners;
		$this->LinesScanners = $temp_linescanners;
	}

	function Scan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("scan err");
		}

		$sc = $this->Scanners[$x];
		//--attention for ++$x//
		//$this->Scan_number = $x++;
		$this->Scan_number = ++$x;
		$this->Scanline_number = $this->LineIds_Of_ScanIds[$x];
		return $sc;
	}

	function LineScan(){
		$x = $this->Scan_number;
		$y = $this->Scanline_number;
		if ($this->LineIds_Of_ScanIds[$x] === false || $this->LastScanIds_Of_LineIds[$y] === false) {
			print("linescan err");
		}

		$lsc = $this->LinesScanners[$y];
		$this->Scan_number = $this->LastScanIds_Of_LineIds[$y] + 1;
		$this->Scanline_number = $y + 1;
		return $lsc;
	}

	function close(){
		fclose($this->Stream);
	}
}

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

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}

	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
===== class end ======

=== function begin ===

function get_line() {
        $stdin = fopen("php://stdin", "r");
        $line = rtrim($stdin, "\n");
        fclose($stdin);
        return $line;
}

function num_printf($i){
	if (is_float($i)) {
		printf("%.0f", $i);
	}
	if (is_int($i)) {
		printf("%d", $i);
	}
}

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

== function end ======
*/

?>

<?php
$arr = array();
while(($line = fgets(STDIN)) != false)
{
    $arr[] = $line;
}

list($N) = explode(" ", trim($arr[0]));

$count = 0;

$left   = false;
$right  = false;
$top    = false;
$bottom = false;

for ($i=1; $i<$N; $i++) {
    for ($j=1; $j<$N; $j++) {
        list($x, $y) = explode(" ", trim($arr[$i]));
        list($x1, $y1) = explode(" ", trim($arr[$j]));
        if ($x1 > $x && $y1 == $y) {
            $right = true;
        } elseif ($x1 < $x && $y1 == $y) {
            $left = true;
        } elseif ($x1 == $x && $y1 < $y) {
            $bottom = true;
        } elseif ($x1 == $x && $y1 > $y) {
            $top = true;
        }

        if ($top && $bottom && $right && $left) {
            $count++;
            $top    = false;
            $bottom = false;
            $right  = false;
            $left   = false;
            break;
        }

    }
}

fputs(STDOUT, $count);

?>

<?php
$arr = array();
while(($line = fgets(STDIN)) != false)
{
    $arr[] = $line;
}

list($N) = explode(" ", trim($arr[0]));

$count = 0;

$left   = false;
$right  = false;
$top    = false;
$bottom = false;

for ($i=1; $i<=$N; $i++) {
    list($x, $y) = explode(" ", trim($arr[$i]));
    for ($j=1; $j<=$N; $j++) {
        list($x1, $y1) = explode(" ", trim($arr[$j]));
        if ($x1 > $x && $y1 == $y) {
            $right = true;
        } else if ($x1 < $x && $y1 == $y) {
            $left = true;
        } else if ($x1 == $x && $y1 < $y) {
            $bottom = true;
        } else if ($x1 == $x && $y1 > $y) {
            $top = true;
        }

        if ($top && $bottom && $right && $left) {
            $count++;
            $top    = false;
            $bottom = false;
            $right  = false;
            $left   = false;

            break;
        }

    }

}

fputs(STDOUT, $count);

?>