Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness.

The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness.

Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order.

<?php
$fp=fopen('php://stdin', 'r');
$lines=stream_get_contents($fp);
$lines=trim($lines);
/*
$lines = '5
          2 4 7 8 10';

$lines = '4
          1 2 1 1';
*/
list($n , $numbers) = explode("\n",trim($lines));
$number = explode(" ", trim($numbers));
$genap = 0; $ganjil = 0;
for($i = 0 ; $i < count($number) ; $i++)
{
    if($number[$i] % 2 == 0)$genap++;
    else $ganjil++;
}
for($i = 0 ; $i < count($number) ; $i++)
{
    if($genap == '1')
    {
        if($number[$i] % 2 == 0){
            echo $i+1;
            break;
        }
    }
    else if($ganjil == '1')
    {
        if($number[$i] % 2 != 0)
        {
            echo $i+1;break;
        }
    }
}
?>

<?php

function FindEvennessNumber($array_size,$array){

    $array     = explode(" ",$array);
    $even      = 0;
    $odd       = 0;
    $index     = 0;

    for($i=0;$i<3;$i++){
        if(($array[$i] % 2)==0)
            $even++;
        else
            $odd++;
    }
    for($i=0;$i<count($array);$i++){
        if($even<=1 && ($array[$i] % 2)==0){
            $index=$i;
            break;
        }
        elseif($odd<=1 && ($array[$i] % 2)!=0){
            $index=$i;
            break;
        }
    }

    return $index+1;
}

$array_size = trim(fgets(STDIN));
$array      = trim(fgets(STDIN));
echo FindEvennessNumber($array_size,$array);

<?php
// 25A  IQ тест
$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$n = (int) $input_line;

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

function chet($a)
{
    if ((((int) $a) % 2) == 0 ) {
        return true;
    } else {
        return false;
    }
}

if ((chet($arr[0]) and chet($arr[1])) or
    (chet($arr[0]) and chet($arr[2])) or
    (chet($arr[1]) and chet($arr[2])))
{
    $flag = true;
} else {
    $flag = false;
}

for ($i=0; $i < $n ; $i++) {
    if ($flag) {
        if (!chet($arr[$i])) {
            break;
        }
    } else {
        if (chet($arr[$i])) {
            break;
        }

    }
}

echo $i + 1;

?>

<?php

$line0 = trim(fgets(STDIN));
$line1 = trim(fgets(STDIN));

$nums = explode(' ', $line1);

foreach ($nums as $key => $value) {
    if ($value % 2 == 0) {
        $even = $even + 1;
        $evenKeys[] = $key;
    }
    else {
        $odd = $odd + 1;
        $oddKeys[] = $key;
    }
}

if ($odd > $even) echo ($evenKeys[0] + 1);
else echo ($oddKeys[0] + 1);

?>

<?php
$stdout = fopen('php://stdout', 'w');
//fputs(STDOUT, "Vhodnie dannie:  ");
$h = fopen('php://stdin', 'r');
$t = (int)trim(fgets($h));
$s = trim(fgets($h));
$len=strlen($s);
if ($t>=3 && $t<=100)
    {
for ($i=1; $i<=$t-1; $i++)
{
    $r=stripos($s,' ');
    $posl[$i]=substr($s, 0, $r);
    if (($posl[$i]<1 && $posl[$i]>100))
    {$f=false;}
    $s=substr($s, $r+1, $len-$r-1);
    }
    $posl[$t]=$s;
    if (($posl[$t]<1 && $posl[$t]>100))
    {$f=false;}
//fputs(STDOUT, "Vihodnie dannie:  ");
    for ($i=1; $i<=$t; $i++)
    {
        $r=$posl[$i]%2;
        if($r==0){
        $chet[$i]=0;
        }
        else {$chet[$i]=1;}
        }
        $countc=0; $countnc=0;
        for ($i=1; $i<=$t; $i++)
        {
            if ($chet[$i]==0){$countc++; $k1=$i;}
            if ($chet[$i]==1){$countnc++; $k2=$i;}
            }
        if ($countc==1){fputs(STDOUT, "$k1");}
        elseif ($countnc==1){fputs(STDOUT, "$k2");}
    }
    /*else
    {fputs(STDOUT, "Число должно быть из диапозона 3<=n<=100");
        }*/
?>

<?
$n=trim(fgets(STDIN));
$arr=explode(' ',trim(fgets(STDIN)));
for($i=0;$i<$n;$i++){
    if($arr[$i]%2==0) $count0[]=$arr[$i];
    else $count1[]=$arr[$i];
}
if(sizeof($count0)==1) {
    foreach($arr as $k=>$v)
        if($v==$count0[0]) $res=$k+1;
}
elseif(sizeof($count1)==1) {
    foreach($arr as $k=>$v)
        if($v==$count1[0]) $res=$k+1;
}
echo $res;
?>

<?php
$number = fgets(STDIN);
$line = fgets(STDIN);

$line = trim($line);
$line = explode(' ', $line);	  	// cоздаем массив из строки

$evens = 0;
$odds = 0;

// разделяем массив на четные и нечетные
for ($i=0; $i < $number; $i++) {
	if (($line[$i] % 2) == 0) {
		$evens++;
	} else {
		$odds++;
	}
}

if ($evens > $odds) {
	foreach ($line as $key => $value) {
		if(($value % 2) != 0){
			$result = $key + 1;
		}
	}
} else {
	foreach ($line as $key => $value) {
		if(($value % 2) == 0){
			$result = $key + 1;
		}
	}
}

print_r($result);

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

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

for($i=0;$i<$n;$i++) $a[$i] %= 2;

$b = array_count_values($a);

print array_search(array_search(1,$b),$a) + 1;

?>

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

$numbers=explode(" ", $lines[1]);
foreach ($numbers as $key=>$num)
{
    if ($num%2==0)
        $chet[]=$key+1;
    else
        $nechet[]=$key+1;
}

echo (count($chet)==1)?$chet[0]:$nechet[0];

?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = 0;
$d = array();
$e = array();
for($x = 0; $x < $a; $x++)
{
    if($b[$x] % 2 == 0)
    {
        array_push($d, $x) ;
    }
    else
    {
        array_push($e, $x);
    }
}
if(count($d) == 1)
{
    print $d[0] + 1;
}
else
{
    print $e[0] + 1;
}
?>

<?php

if (getenv('APPLICATION_ENV') == 'development') {
    $inputStream = STDIN;
    $outputStream = STDOUT;
} else {
    $inputStream = STDIN;
    $outputStream = STDOUT;
}

$n = fgets($inputStream);
$input = fgets($inputStream);

$nums = explode(' ', $input);
$res = array(0, 0);
$last = array(0, 0);
$c = 1;
foreach ($nums as $a) {
    $x = $a & 1;
    $res[$x]++;
    $last[$x] = $c++;
}

if ($res[0] < $res[1]) {
    $out = $last[0];
} else {
    $out = $last[1];
}

fwrite($outputStream, $out);

if (getenv('APPLICATION_ENV') == 'development') {
    fclose($inputStream);
    fclose($outputStream);
}

<?php

$n = readline();

$line = readline();
$numbers = explode(' ', $line);

$chet = 0;
$chetKey = 0;

$nechet = 0;
$nechetKey = 0;

foreach ($numbers as $key => $number) {
    if($number & 1){
        $nechet++;
        $nechetKey = $key;
    }else{
        $chet++;
        $chetKey = $key;
    }

    if($nechet > 1 && $chet == 1){
        echo $chetKey+1;
        break;
    }elseif($chet > 1 && $nechet == 1){
        echo $nechetKey+1;
        break;
    }
}

<?php
$n = trim(fgets(STDIN));
$numbers = array();
$numbers = explode(' ',trim(fgets(STDIN)));

$chetnaya = array();
$nechetnaya = array();

for( $i=0; $i<$n; $i++ ){
    if( $numbers[$i]%2 == 1 ){
        $nechetnaya[] = $i+1;
        //$nechetnaya[] = $numbers[$i];

    }elseif( $numbers[$i] == 1 ){
        $nechetnaya[] = $i+1;
    }else{
        $chetnaya[] = $i+1;
        //$chetnaya[] = $numbers[$i];
    }
}

if( sizeof($nechetnaya) == 1){
    echo $nechetnaya[0];
}elseif( sizeof($chetnaya) == 1 ){
    echo $chetnaya[0];
}

<?php
$n = trim(fgets(STDIN));
$line = explode(" ",trim(fgets(STDIN)));
$even=0;$odd=0;
for ($i=0;$i<$n;$i++)
{
    if ($line[$i]%2==0)
    {
        $even++;
        $evenPlace=$i;
    }
    else
    {
        $odd++;
        $oddPlace=$i;
    }
}
if ($even>$odd)echo $oddPlace+1;
else echo $evenPlace+1;

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

    $n = fgets($stdin);
    $numbers = fgets($stdin);
    $numbers = explode(" ", $numbers);

    for($i=2; $i<count($numbers);++$i){
        if((($numbers[$i]+$numbers[$i-1])%2) == 1){
            if((($numbers[$i]+$numbers[$i-2])%2) == 0){
                fputs($stdout, ($i-1)+1);
                return;
            }
            else {
                fputs($stdout, $i+1);
                return;
            }
        }
    }
    fputs($stdout, 1);

?>

<?php

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

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

    if ($die) {
        die();
    }

    echo '</pre>';
}

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

    return $stdin;
}

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

$stdin = stdin();
/****************************************************** Solving block *****************************************************/
$n = g();
$numbers = explode(' ', g());

$n0cnt = $n1cnt = $n0 = $n1 = 0;

foreach($numbers as $key => $number) {
    if($number % 2 == 0) {
        $n0 = $key + 1;
        $n0cnt++;
    } else {
        $n1 = $key + 1;
        $n1cnt++;
    }
}

echo $n0cnt > $n1cnt ? $n1 : $n0;

?>

<?php
$fp=fopen('php://stdin', 'r');
$lines=stream_get_contents($fp);
$lines=trim($lines);
/*
$lines = '5
          2 4 7 8 10';
*/
list($n , $numbers) = explode("\n",trim($lines));
$number = explode(" ", $numbers);
$genap = 0; $ganjil = 0;
$angkaGenap = ""; $angkaGanjil = "";
for($i = 0 ; $i < count($number) ; $i++)
{
    if($number[$i] % 2 == 0)
    {
        $genap++;
        $angkaGenap = $number[$i];
        if($ganjil > 1)
        {
            echo $i;
            exit();
        }
    }
    else
    {
        $ganjil++;
        $angkaGanjil = $number[$i];
        if($genap > 1)
        {
            echo $i;
            exit();
        }
    }
}
?>

<?php
$fp=fopen('php://stdin', 'r');
$lines=stream_get_contents($fp);
$lines=trim($lines);
/*
$lines = '5
          2 4 7 8 10';
*/
list($n , $numbers) = explode("\n",trim($lines));
$number = explode(" ", $numbers);
$genap = 0; $ganjil = 0;
$angkaGenap = ""; $angkaGanjil = "";
for($i = 0 ; $i < count($number) ; $i++)
{
    if($number[$i] % 2 == 0)
    {
        $genap++;
        $angkaGenap = $number[$i];
        if($ganjil > 1)
        {
            echo ($i+1);
            exit();
        }
    }
    else
    {
        $ganjil++;
        $angkaGanjil = $number[$i];
        if($genap > 1)
        {
            echo ($i+1);
            exit();
        }
    }
}
?>

<?php
$fp=fopen('php://stdin', 'r');
$lines=stream_get_contents($fp);
$lines=trim($lines);
/*
$lines = '5
          2 4 7 8 10';
*/
list($n , $numbers) = explode("\n",trim($lines));
$number = explode(" ", $numbers);
$genap = 0; $ganjil = 0;
$angkaGenap = ""; $angkaGanjil = "";
for($i = 0 ; $i < count($number) ; $i++)
{
    if($number[$i] % 2 == 0)
    {
        $genap++;
        $angkaGenap = $number[$i];
        if($ganjil > 1)
        {
            echo $angkaGanjil;
            exit();
        }
    }
    else
    {
        $ganjil++;
        $angkaGanjil = $number[$i];
        if($genap > 1)
        {
            echo $angkaGanjil;
            exit();
        }
    }
}
?>

<?php
$fp=fopen('php://stdin', 'r');
$lines=stream_get_contents($fp);
$lines=trim($lines);
/*
$lines = '5
          2 4 7 8 10';
*/
list($n , $numbers) = explode("\n",trim($lines));
$number = explode(" ", $numbers);
$genap = 0; $ganjil = 0;
$angkaGenap = ""; $angkaGanjil = "";
for($i = 0 ; $i < count($number) ; $i++)
{
    if($number[$i] % 2 == 0)
    {
        $genap++;
        $angkaGenap = $number[$i];
        if($ganjil > 1)
        {
            echo ($i+1);
            break;
        }
    }
    else
    {
        $ganjil++;
        $angkaGanjil = $number[$i];
        if($genap > 1)
        {
            echo ($i+1);
            break;
        }
    }
}
?>

<?php

function FindEvennessNumber($array_size,$array){

    $array     = explode(" ",$array);
    $even      = 0;
    $odd       = 0;
    $index     = 0;

    for($i=0;$i<3;$i++){
        if(($array[$i] % 2)==0)
            $even++;
        else
            $odd++;
    }
    for($i=0;$i<count($array);$i++){
        if($even==1 && ($array[$i] % 2)==0){
            $index=$i;
            break;
        }
        elseif($odd==1 && ($array[$i] % 2)!=0){
            $index=$i;
            break;
        }
    }

    return $index+1;
}

$array_size = trim(fgets(STDIN));
$array      = trim(fgets(STDIN));
echo FindEvennessNumber($array_size,$array);

<?php
$stdout = fopen('php://stdout', 'w');
fputs(STDOUT, "Vhodnie dannie:  ");
$h = fopen('php://stdin', 'r');
$t = trim(fgets($h));
if ($k>=3 & $k<=100)
	{
for($i=1; $i<=$t; $i++)
{
	$posl[$i] = trim(fgets($h));
	}
fputs(STDOUT, "Vihodnie dannie:  ");
	for ($i=1; $i<=$t; $i++)
	{
		$r=$posl[$i]%2;
		if($r==0){
		$chet[$i]=0;
		}
		else {$chet[$i]=1;}
		}
		$countc=0; $countnc=0;
		for ($i=1; $i<=$t; $i++)
		{
			if ($chet[$i]==0){$countc++; $k1=$i;}
			if ($chet[$i]==1){$countnc++; $k2=$i;}
			}
		if ($countc==1){fputs(STDOUT, "$k1");}
		elseif ($countnc==1){fputs(STDOUT, "$k2");}
	}
	else
	{fputs(STDOUT, "����� ������ ���� �� ��������� 3<=n<=100");
		}
?>

<?php
$number = fgets(STDIN);
$line = fgets(STDIN);

$line = trim($line);
$line = explode(' ', $line);	  	// cоздаем массив из строки

if (($line[0] % 2) == 0) {
	foreach ($line as $key => $value) {
		if(($value % 2) != 0){
			$result = $key + 1;
		}
	}
} else {
	foreach ($line as $key => $value) {
		if(($value % 2) == 0){
			$result = $key + 1;
		}
	}
}

print_r($result);

<?php

if (getenv('APPLICATION_ENV') == 'development') {
    $inputStream = STDIN;
    $outputStream = STDOUT;
} else {
    $inputStream = STDIN;
    $outputStream = STDOUT;
}

$n = fgets($inputStream);
$input = fgets($inputStream);

$nums = explode(' ', $input);
$res = array(0, 0);
$last = array(0, 0);

foreach ($nums as $a) {
    $x = $a & 1;
    $res[$x]++;
    $last[$x] = $a;
}

if ($res[0] < $res[1]) {
    $out = $last[0];
} else {
    $out = $last[1];
}

fwrite($outputStream, $out);

if (getenv('APPLICATION_ENV') == 'development') {
    fclose($inputStream);
    fclose($outputStream);
}

<?php

$n = readline();

$line = readline();
$numbers = explode(' ', $line);

$chet = 0;
$chetKey = 0;

$nechet = 0;
$nechetKey = 0;

foreach ($numbers as $key => $number) {
    if($number & 1){
        $nechet++;
        $nechetKey = $key;
    }else{
        $chet++;
        $chetKey = $key;
    }

    if($nechet > 1 && $chet == 1){
        echo $chetKey+1;
        break;
    }elseif($chetKey > 1 && $nechet == 1){
        echo $nechetKey+1;
        break;
    }
}

<?php
$n = trim(fgets(STDIN));
$line = explode(" ",trim(fgets(STDIN)));
$even=0;$odd=0;
for ($i=1;$i<$n;$i++)
{
    if ($line[$i]%2==0)
    {
        $even++;
        $evenPlace=$i;
    }
    else
    {
        $odd++;
        $oddPlace=$i;
    }
}
if ($even>$odd)echo $oddPlace+1;
else echo $evenPlace+1;

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

    $n = fgets($stdin);
    $numbers = fgets($stdin);
    $numbers = preg_replace("/\s/", "", $numbers);

    for($i=2; $i<strlen($numbers);++$i){
        if((($numbers[$i]+$numbers[$i-1])%2) == 1){
            if((($numbers[$i]+$numbers[$i-2])%2) == 0){
                fputs($stdout, ($i-1)+1);
                return;
            }
            else {
                fputs($stdout, $i+1);
                return;
            }
        }
    }
    fputs($stdout, 1);

?>

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

    $n = fgets($stdin);
    $numbers = fgets($stdin);
    $numbers = explode(" ", $numbers);

    for($i=2; $i<strlen($numbers);++$i){
        if((($numbers[$i]+$numbers[$i-1])%2) == 1){
            if((($numbers[$i]+$numbers[$i-2])%2) == 0){
                fputs($stdout, ($i-1)+1);
                return;
            }
            else {
                fputs($stdout, $i+1);
                return;
            }
        }
    }
    fputs($stdout, 1);

?>


This is the easy version of the problem. The difference is that in this version the array can not contain zeros. You can make hacks only if both versions of the problem are solved.You are given an array $$$[a_1, a_2, \ldots a_n]$$$ consisting of integers $$$-1$$$ and $$$1$$$. You have to build a partition of this array into the set of segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$$$ with the following property:  Denote the alternating sum of all elements of the $$$i$$$-th segment as $$$s_i$$$: $$$s_i$$$ = $$$a_{l_i} - a_{l_i+1} + a_{l_i+2} - a_{l_i+3} + \ldots \pm a_{r_i}$$$. For example, the alternating sum of elements of segment $$$[2, 4]$$$ in array $$$[1, 0, -1, 1, 1]$$$ equals to $$$0 - (-1) + 1 = 2$$$.  The sum of $$$s_i$$$ over all segments of partition should be equal to zero. Note that each $$$s_i$$$ does not have to be equal to zero, this property is about sum of $$$s_i$$$ over all segments of partition.The set of segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$$$ is called a partition of the array $$$a$$$ of length $$$n$$$ if $$$1 = l_1 \le r_1, l_2 \le r_2, \ldots, l_k \le r_k = n$$$ and $$$r_i + 1 = l_{i+1}$$$ for all $$$i = 1, 2, \ldots k-1$$$. In other words, each element of the array must belong to exactly one segment.You have to build a partition of the given array with properties described above or determine that such partition does not exist.Note that it is not required to minimize the number of segments in the partition.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10\,000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i$$$ is $$$-1$$$ or $$$1$$$) — the elements of the given array. It's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$200\,000$$$.

For each test case, if required partition does not exist, print $$$-1$$$. Otherwise, print an integer $$$k$$$ — the number of segments in the partition.  Then in the $$$i$$$-th of the following $$$k$$$ lines print two integers $$$l_i$$$ and $$$r_i$$$ — description of the $$$i$$$-th segment. The following conditions should be satisfied:   $$$l_i \le r_i$$$ for each $$$i$$$ from $$$1$$$ to $$$k$$$.  $$$l_{i + 1} = r_i + 1$$$ for each $$$i$$$ from $$$1$$$ to $$$(k - 1)$$$.  $$$l_1 = 1, r_k = n$$$.  If there are multiple correct partitions of the array, print any of them.

NoteIn the first test case we can build a partition of one segment of length $$$4$$$. The sum of this segment will be equal to $$$1 - 1 + 1 - 1 = 0$$$.In the second test case we can build a partition of two segments of length $$$3$$$. The sum of the first segment will be equal to $$$-1 -1 + 1 = -1$$$, and the sum of the second segment: $$$1 - 1 + 1 = 1$$$. So, the total sum will be equal to $$$-1 + 1 = 0$$$.In the third and in the fourth test cases it can be proved that there are no required partition.


You came to a local shop and want to buy some chocolate bars. There are $$$n$$$ bars in the shop, $$$i$$$-th of them costs $$$a_i$$$ coins (and you want to buy all of them).You have $$$m$$$ different coupons that allow you to buy chocolate bars. $$$i$$$-th coupon allows you to buy $$$q_i$$$ chocolate bars while you have to pay only for the $$$q_i - 1$$$ most expensive ones (so, the cheapest bar of those $$$q_i$$$ bars is for free).You can use only one coupon; if you use coupon $$$i$$$, you have to choose $$$q_i$$$ bars and buy them using the coupon, and buy all the remaining $$$n - q_i$$$ bars without any discounts.To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of chocolate bars in the shop. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the cost of $$$i$$$-th chocolate bar. The third line contains one integer $$$m$$$ ($$$1 \le m \le n - 1$$$) — the number of coupons you have. The fourth line contains $$$m$$$ integers $$$q_1$$$, $$$q_2$$$, ..., $$$q_m$$$ ($$$2 \le q_i \le n$$$), where $$$q_i$$$ is the number of chocolate bars you have to buy using $$$i$$$-th coupon so that the least expensive of them will be for free. All values of $$$q_i$$$ are pairwise distinct.

Print $$$m$$$ integers, $$$i$$$-th of them should be the minimum amount of money you have to pay if you buy $$$q_i$$$ bars with $$$i$$$-th coupon, and all the remaining bars one by one for their full price.

NoteConsider the first example.If we use the first coupon, we may choose chocolate bars having indices $$$1$$$, $$$6$$$ and $$$7$$$, and we pay $$$18$$$ coins for them and $$$9$$$ coins for all other bars.If we use the second coupon, we may choose chocolate bars having indices $$$1$$$, $$$5$$$, $$$6$$$ and $$$7$$$, and we pay $$$25$$$ coins for them and $$$5$$$ coins for all other bars.

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
rsort($b);
$c = trim(fgets(STDIN));
$d = explode(" ", trim(fgets(STDIN)));
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = 0;
for($x = 0; $x < $a; $x++)
{
     $g = bcadd($g, $b[$x]);
}
for($x = 0; $x < $c; $x++)
{
     $f[$e[$x]] = bcsub($g, $b[$d[$x] - 1]) . "\n";
}
ksort($f);
print implode($f);
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
rsort($b);
$c = trim(fgets(STDIN));
$d = explode(" ", trim(fgets(STDIN)));
$f = "";
$g = 0;
for($x = 0; $x < $a; $x++)
{
     $g = bcadd($g, $b[$x]);
}
for($x = 0; $x < $c; $x++)
{
     $f .= bcsub($g, $b[$d[$x] - 1]) . "\n";
}
print $f;
?>

<?php

$n = trim(fgets(STDIN));
$p = explode(' ', trim(fgets(STDIN)));
$m = trim(fgets(STDIN));
$q = explode(' ', trim(fgets(STDIN)));

rsort($p);

$sum0 = 0;

for($i = 0; $i<$n; $i++){
    $sum0 = bcadd($sum0, $p[$i]);
}

$ans = "";

for($i = 0; $i<$m; $i++){
	$sum = bcsub($sum0, $p[$q[$i]-1]);

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

fwrite(STDOUT, trim($ans));

?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
rsort($b);
$c = trim(fgets(STDIN));
$d = explode(" ", trim(fgets(STDIN)));
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = array_sum($b);
for($x = 0; $x < $c; $x++)
{
     $f[$e[$x]] = bcsub($g, $b[$d[$x] - 1]) . "\n";
}
ksort($f);
print implode($f);
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
rsort($b);
$c = trim(fgets(STDIN));
$d = explode(" ", trim(fgets(STDIN)));
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = array_sum($b);
for($x = 0; $x < $c; $x++)
{
     $f[$e[$x]] = ($g - $b[$d[$x] - 1]) . "\n";
}
ksort($f);
print implode($f);
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = explode(" ", trim(fgets(STDIN)));
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = 0;
for($x = 0; $x < $a; $x++)
{
     $g = bcadd($g, $b[$x]);
}
for($x = 0; $x < $c; $x++)
{
     $f[$e[$x]] = bcsub($g, $b[$d[$x] - 1]) . "\n";
}
ksort($f);
print implode($f);
?>

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
rsort($b);
$c = trim(fgets(STDIN));
$d = explode(" ", trim(fgets(STDIN)));
asort($d);
$e = array_keys($d);
sort($d);
$f = array();
$g = array_sum($b);
for($x = 0; $x < $c; $x++)
{
     $f[$e[$x]] = ($g - $b[$d[$x] - 1]) . "\n";
}
print implode($f);
?>

<?php

$n = trim(fgets(STDIN));
$p = explode(' ', trim(fgets(STDIN)));
$m = trim(fgets(STDIN));
$q = explode(' ', trim(fgets(STDIN)));

rsort($p);

$sum0 = array_sum($p);
$ans = "";

for($i = 0; $i<$m; $i++){
	$sum = $sum0 - $p[$q[$i]-1];

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

fwrite(STDOUT, sprintf("%d", trim($ans)));

?>

<?php

$n = trim(fgets(STDIN));
$p = explode(' ', trim(fgets(STDIN)));
$m = trim(fgets(STDIN));
$q = explode(' ', trim(fgets(STDIN)));

rsort($p);

$sum0 = array_sum($p);
$ans = "";

for($i = 0; $i<$m; $i++){
	$sum = $sum0 - $p[$q[$i]-1];

	$ans .= sprintf("%d", $sum)."\n";
}

fwrite(STDOUT, trim($ans));

?>

<?php

$n = trim(fgets(STDIN));
$p = explode(' ', trim(fgets(STDIN)));
$m = trim(fgets(STDIN));
$q = explode(' ', trim(fgets(STDIN)));

rsort($p);

$sum0 = array_sum($p);
$ans = "";

for($i = 0; $i<$m; $i++){
	$sum = $sum0 - $p[$q[$i]-1];

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

fwrite(STDOUT, trim($ans));

?>

<?php

$n = trim(fgets(STDIN));
$p = explode(' ', trim(fgets(STDIN)));
$m = trim(fgets(STDIN));
$q = explode(' ', trim(fgets(STDIN)));

rsort($p);

$sum0 = array_sum($p);
$ans = "";

for($i = 0; $i<$m; $i++){
	$sum = $sum0 - $p[$q[$i]-1];

	$ans .= $sum." ";
}

fwrite(STDOUT, trim($ans));

?>

<?php

$n = trim(fgets(STDIN));
$p = explode(' ', trim(fgets(STDIN)));
$m = trim(fgets(STDIN));
$q = explode(' ', trim(fgets(STDIN)));

rsort($p);

$sum0 = 0;

for($i = 0; $i<$n; $i++){
    $sum0 = bcadd($sum, $p[$i]);
}

$ans = "";

for($i = 0; $i<$m; $i++){
	$sum = bcsub($sum0, $p[$q[$i]-1]);

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

fwrite(STDOUT, trim($ans));

?>


Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.Let [n] denote the set {1, ..., n}. We will also write f: [x] → [y] when a function f is defined in integer points 1, ..., x, and all its values are integers from 1 to y.Now then, you are given a function f: [n] → [n]. Your task is to find a positive integer m, and two functions g: [n] → [m], h: [m] → [n], such that g(h(x)) = x for all , and h(g(x)) = f(x) for all , or determine that finding these is impossible.

The first line contains an integer n (1 ≤ n ≤ 105). The second line contains n space-separated integers — values f(1), ..., f(n) (1 ≤ f(i) ≤ n).

If there is no answer, print one integer -1. Otherwise, on the first line print the number m (1 ≤ m ≤ 106). On the second line print n numbers g(1), ..., g(n). On the third line print m numbers h(1), ..., h(m). If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.


In the army, it isn't easy to form a group of soldiers that will be effective on the battlefield. The communication is crucial and thus no two soldiers should share a name (what would happen if they got an order that Bob is a scouter, if there are two Bobs?).A group of soldiers is effective if and only if their names are different. For example, a group (John, Bob, Limak) would be effective, while groups (Gary, Bob, Gary) and (Alice, Alice) wouldn't.You are a spy in the enemy's camp. You noticed n soldiers standing in a row, numbered 1 through n. The general wants to choose a group of k consecutive soldiers. For every k consecutive soldiers, the general wrote down whether they would be an effective group or not.You managed to steal the general's notes, with n - k + 1 strings s1, s2, ..., sn - k + 1, each either "YES" or "NO".   The string s1 describes a group of soldiers 1 through k ("YES" if the group is effective, and "NO" otherwise).  The string s2 describes a group of soldiers 2 through k + 1.  And so on, till the string sn - k + 1 that describes a group of soldiers n - k + 1 through n. Your task is to find possible names of n soldiers. Names should match the stolen notes. Each name should be a string that consists of between 1 and 10 English letters, inclusive. The first letter should be uppercase, and all other letters should be lowercase. Names don't have to be existing names — it's allowed to print "Xyzzzdj" or "T" for example.Find and print any solution. It can be proved that there always exists at least one solution.

The first line of the input contains two integers n and k (2 ≤ k ≤ n ≤ 50) — the number of soldiers and the size of a group respectively. The second line contains n - k + 1 strings s1, s2, ..., sn - k + 1. The string si is "YES" if the group of soldiers i through i + k - 1 is effective, and "NO" otherwise.

Find any solution satisfying all given conditions. In one line print n space-separated strings, denoting possible names of soldiers in the order. The first letter of each name should be uppercase, while the other letters should be lowercase. Each name should contain English letters only and has length from 1 to 10. If there are multiple valid solutions, print any of them.

Adam Bob Bob Cpqepqwer Limak Adam Bob Adam

R Q Ccccccccc Ccocc Ccc So Strong Samples Ccc

NoteIn the first sample, there are 8 soldiers. For every 3 consecutive ones we know whether they would be an effective group. Let's analyze the provided sample output:  First three soldiers (i.e. Adam, Bob, Bob) wouldn't be an effective group because there are two Bobs. Indeed, the string s1 is "NO".  Soldiers 2 through 4 (Bob, Bob, Cpqepqwer) wouldn't be effective either, and the string s2 is "NO".  Soldiers 3 through 5 (Bob, Cpqepqwer, Limak) would be effective, and the string s3 is "YES".  ...,  Soldiers 6 through 8 (Adam, Bob, Adam) wouldn't be effective, and the string s6 is "NO".


A sequence of $$$n$$$ numbers is called a permutation if it contains all integers from $$$1$$$ to $$$n$$$ exactly once. For example, the sequences [$$$3, 1, 4, 2$$$], [$$$1$$$] and [$$$2,1$$$] are permutations, but [$$$1,2,1$$$], [$$$0,1$$$] and [$$$1,3,4$$$] — are not.Polycarp lost his favorite permutation and found only some of its elements — the numbers $$$b_1, b_2, \dots b_m$$$. He is sure that the sum of the lost elements equals $$$s$$$.Determine whether one or more numbers can be appended to the given sequence $$$b_1, b_2, \dots b_m$$$ such that the sum of the added numbers equals $$$s$$$, and the resulting new array is a permutation?

The first line of input contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) —the number of test cases.  Then the descriptions of the test cases follow. The first line of each test set contains two integers $$$m$$$ and $$$s$$$ ($$$1 \le m \le 50$$$, $$$1 \le s \le 1000$$$)—-the number of found elements and the sum of forgotten numbers. The second line of each test set contains $$$m$$$ different integers $$$b_1, b_2 \dots b_m$$$ ($$$1 \le b_i \le 50$$$) — the elements Polycarp managed to find.

Print $$$t$$$ lines, each of which is the answer to the corresponding test set. Print as the answer YES if you can append several elements to the array $$$b$$$, that their sum equals $$$s$$$ and the result will be a permutation. Output NO otherwise. You can output the answer in any case (for example, yEs, yes, Yes and YES will be recognized as positive answer).

NoteIn the test case of the example, $$$m=3, s=13, b=[3,1,4]$$$. You can append to $$$b$$$ the numbers $$$6,2,5$$$, the sum of which is $$$6+2+5=13$$$. Note that the final array will become $$$[3,1,4,6,2,5]$$$, which is a permutation.In the second test case of the example, $$$m=1, s=1, b=[1]$$$. You cannot append one or more numbers to $$$[1]$$$ such that their sum equals $$$1$$$ and the result is a permutation.In the third test case of the example, $$$m=3, s=3, b=[1,4,2]$$$. You can append the number $$$3$$$ to $$$b$$$. Note that the resulting array will be $$$[1,4,2,3]$$$, which is a permutation.

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    list($m, $s) = getLineInts();

    $partial = getLineInts();

    $partialMax = max($partial);

    $currInt = 1;
    $currSum = 0;

    while ($currSum < $s)
    {
        if (!in_array($currInt, $partial))
        {
            $currSum += $currInt;
        }

        $currInt++;
    }

    if ($currInt < $partialMax)
    {
        for ($i = $currInt; $i <= $partialMax; $i++)
        {
            if (!in_array($i, $partial))
            {
                break;
            }

            $currInt = $i;
        }
    }

    $results[] = $s <= 0 || $currSum > $s || $currInt < $partialMax ? "NO" : "YES";
}

echo(implode(PHP_EOL, $results));

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

function getLineInts()
{
    return array_map("intval", explode(' ', trim(fgets(STDIN))));
}

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

function getWords()
{
    return explode(' ', trim(fgets(STDIN)));
}

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s,$t] = explode(' ', trim(fgets(STDIN)));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
for($i=0;$i<$t;$i++){
    [$n, $s] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $set = [];
    for($j=0;$j<$n;$j++){
        $set[$a[$j]]=true;
    }
    for($j=1;$j<=200;$j++){
        if(isset($set[$j])) {
            unset($set[$j]);
            if(count($set) == 0 && $s == 0){
                break;
            }
            continue;
        }
        $s -= $j;
        if(count($set) == 0 && $s == 0){
            break;
        }
    }
    if(count($set) == 0 && $s == 0){
        $ans[] = "YES";
    }else{
        $ans[] = "NO";
    }
}
echo implode(PHP_EOL, $ans);

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    list($m, $s) = getLineInts();

    $partial = getLineInts();

    $partialMax = max($partial);

    $currInt = 1;
    $currSum = 0;

    while ($currSum < $s)
    {
        if (!in_array($currInt, $partial))
        {
            $currSum += $currInt;
        }

        $currInt++;
    }

    $results[] = $s <= 0 || $currSum > $s || $currInt < $partialMax ? "NO" : "YES";
}

echo(implode(PHP_EOL, $results));

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

function getLineInts()
{
    return array_map("intval", explode(' ', trim(fgets(STDIN))));
}

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

function getWords()
{
    return explode(' ', trim(fgets(STDIN)));
}

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    list($m, $s) = getLineInts();

    $partial = getLineInts();

    $maxPartial = max($partial);

    $currInt = 1;
    $currSum = 0;

    while ($currSum < $s)
    {
        if (!in_array($currInt, $partial))
        {
            $currSum += $currInt;
        }

        $currInt++;
    }

    $results[] = $currSum > $s || $currInt < $maxPartial ? "NO" : "YES";
}

echo(implode(PHP_EOL, $results));

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

function getLineInts()
{
    return array_map("intval", explode(' ', trim(fgets(STDIN))));
}

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

function getWords()
{
    return explode(' ', trim(fgets(STDIN)));
}

<?php

$tests = getLineInt();

$pattern = "Yes";

$patternLength = strlen($pattern);

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    list($m, $s) = getLineInts();

    $b = getLineInts();

    $results[] = in_array($s, $b) ? "NO" : "YES";
}

echo(implode(PHP_EOL, $results));

// Helpers

function getLineInt()
{
    return (int) trim(fgets(STDIN));
}

function getLineInts()
{
    return array_map("intval", explode(' ', trim(fgets(STDIN))));
}

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

function getWords()
{
    return explode(' ', trim(fgets(STDIN)));
}

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s,$t] = explode(' ', trim(fgets(STDIN)));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
for($i=0;$i<$t;$i++){
    [$n, $s] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $set = [];
    for($j=0;$j<$n;$j++){
        $set[$a[$j]]=true;
    }
    for($j=1;$j<=50;$j++){
        if(isset($set[$j])) {
            unset($set[$j]);
            if(count($set) == 0 && $s == 0){
                break;
            }
            continue;
        }
        $s -= $j;
        if(count($set) == 0 && $s == 0){
            break;
        }
    }
    if(count($set) == 0 && $s == 0){
        $ans[] = "YES";
    }else{
        $ans[] = "NO";
    }
}
echo implode(PHP_EOL, $ans);

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s,$t] = explode(' ', trim(fgets(STDIN)));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
for($i=0;$i<$t;$i++){
    [$n, $s] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $set = [];
    for($j=0;$j<$n;$j++){
        $set[$a[$j]]=true;
    }
    for($j=1;$j<=50;$j++){
        if(isset($set[$j])) continue;
        $set[$j] = true;
        $s -= $j;
        if($s == 0){
            ksort($set);
            $ok=true;
            for($x=1;$x<=count($set);$x++){
                if(!isset($set[$x])){
                    $ok = false;
                    break;
                }
            }
            if($ok) $ans[] = "YES";
            else $ans[] = "NO";
            break;
        }
        if($s < 0){
            $ans[] = "NO";
            break;
        }
    }
}
echo implode(PHP_EOL, $ans);


Methodius received an email from his friend Polycarp. However, Polycarp's keyboard is broken, so pressing a key on it once may cause the corresponding symbol to appear more than once (if you press a key on a regular keyboard, it prints exactly one symbol).For example, as a result of typing the word "hello", the following words could be printed: "hello", "hhhhello", "hheeeellllooo", but the following could not be printed: "hell", "helo", "hhllllooo".Note, that when you press a key, the corresponding symbol must appear (possibly, more than once). The keyboard is broken in a random manner, it means that pressing the same key you can get the different number of letters in the result.For each word in the letter, Methodius has guessed what word Polycarp actually wanted to write, but he is not sure about it, so he asks you to help him.You are given a list of pairs of words. For each pair, determine if the second word could be printed by typing the first one on Polycarp's keyboard.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of pairs to check. Further input contains $$$n$$$ descriptions of pairs. The first line of each description contains a single non-empty word $$$s$$$ consisting of lowercase Latin letters. The second line of the description contains a single non-empty word $$$t$$$ consisting of lowercase Latin letters. The lengths of both strings are not greater than $$$10^6$$$. It is guaranteed that the total length of all words $$$s$$$ in the input is not greater than $$$10^6$$$. Also, it is guaranteed that the total length of all words $$$t$$$ in the input is not greater than $$$10^6$$$.

Output $$$n$$$ lines. In the $$$i$$$-th line for the $$$i$$$-th pair of words $$$s$$$ and $$$t$$$ print YES if the word $$$t$$$ could be printed by typing the word $$$s$$$. Otherwise, print NO.

4
hello
hello
hello
helloo
hello
hlllloo
hello
helo

5
aa
bb
codeforces
codeforce
polycarp
poolycarpp
aaaa
aaaab
abcdefghijklmnopqrstuvwxyz
zabcdefghijklmnopqrstuvwxyz

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));

	$printed=trim(fgets(STDIN));

	          $grp1=identicalSubstring($typed);
             // print_r($grp1);
              $grp2=identicalSubstring($printed);
              //print_r($grp2);

                    if(count($grp1)!=count($grp2))
                    {
                        $same=false;
                        //echo "some";
                    }
                     else
                     {
                            $same=true;
                           //echo "hi\n";

                            for ($i=0; $i <count($grp1) ; $i++)
                            {
                                    if((strlen($grp1[$i])>strlen($grp2[$i]))||($grp1[$i][0]!=$grp2[$i][0]))
                                    {
                                        $same=false;
                                        break;
                                    }

                            }
                     }

  echo $same?"YES\n":"NO\n";
}
function identicalSubstring($str)
{

               $grp1=array();

                if(count(array_unique(str_split($str)))==1)
                {
                    $grp1[0]=$str;
                    return $grp1;
                }
                else
                 {
                    /*
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($str)-1 ; $i++)
                         {
                              if($str[$i]!=$str[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($str,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($str,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($str,$ara[$i]+1);

                        }
                        return $grp1;
                        */
                        $i=0;
                        $k=0;
                        //$sbstr=array();
                        $str2="";
                        while($i<strlen($str)-1)
                        {

                            if($str[$i]!=$str[$i+1])
                            {
                                $last=$i+1;
                                //echo "$last\n";

                                $grp1[$k]=$str2.$str[$i];
                                $k++;
                                $str2="";
                            }
                            else
                                $str2.=$str[$i];
                         $i++;

                        }
                        $grp1[count($grp1)]=substr($str,$last);
                        return $grp1;

                    }

}

<?php
fscanf(STDIN,"%d",$n);
while ($n--)
{
	$typed=trim(fgets(STDIN));
    $printed=trim(fgets(STDIN));

	          $grp1=identicalSubstring($typed);
              $grp2=identicalSubstring($printed);
                     if(count($grp1)!=count($grp2))
                        {
                           $same=false;
                        }
                     else
                     {
                            $same=true;
                             for ($i=0; $i <count($grp1) ; $i++)
                            {
                                    if((strlen($grp1[$i])>strlen($grp2[$i]))||($grp1[$i][0]!=$grp2[$i][0]))
                                    {
                                        $same=false;
                                        break;
                                    }

                            }
                     }

  echo $same?"YES\n":"NO\n";
}
function identicalSubstring($str)
{
                $grp1=array();
                if(count(array_unique(str_split($str)))==1)
                  {
                    $grp1[0]=$str;
                    return $grp1;
                  }
                else
                 {
                        $i=0;
                        $k=0;
                        $str2="";
                        while($i<strlen($str)-1)
                        {

                                    if($str[$i]!=$str[$i+1])
                                    {
                                        $last=$i+1;
                                        $grp1[$k]=$str2.$str[$i];
                                        $k++;
                                        $str2="";
                                    }
                                    else
                                        $str2.=$str[$i];
                                 $i++;

                        }
                        $grp1[count($grp1)]=substr($str,$last);
                        return $grp1;

                    }

}

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = str_split(trim(fgets(STDIN)));
     $c = str_split(trim(fgets(STDIN)));
     if(count($b) < count($c))
     {
          $b = array_unique($b);
          $c = array_unique($c);
          if(implode($b) == implode($c))
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(count($b) == count($c))
     {
          if($b == $c)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(count($b) > count($c))
     {
          print "NO";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = str_split(trim(fgets(STDIN)));
     $c = str_split(trim(fgets(STDIN)));
     if(count($b) > count($c))
     {
          print "NO\n";
     }
     else
     {
          $b = array_unique($b);
          $c = array_unique($c);
          if(implode($b) == implode($c))
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = trim(fgets(STDIN));
     if(strlen($b) < strlen($c))
     {
          $d = $b[0];
          for($y = 0; $y < strlen($b) - 1; $y++)
          {
               if($b[strlen($b) - 1] != $b[$y + 1])
               {
                    $d .= $b[$y + 1];
               }
          }
          $e = $c[0];
          for($y = 0; $y < strlen($c) - 1; $y++)
          {
               if($c[strlen($c) - 1] != $c[$y + 1])
               {
                    $e .= $c[$y + 1];
               }
          }
          if($d == $e)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(strlen($b) == strlen($c))
     {
          if($b == $c)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(strlen($b) > strlen($c))
     {
          print "NO\n";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = trim(fgets(STDIN));
     if(strlen($b) < strlen($c))
     {
          $d = $b[0];
          for($y = 0; $y < strlen($b); $y++)
          {
               if($d[strlen($d) - 1] != $b[$y + 1])
               {
                    $d .= $b[$y + 1];
               }
          }
          $e = $c[0];
          for($y = 0; $y < strlen($c); $y++)
          {
               if($e[strlen($e) - 1] != $c[$y + 1])
               {
                    $e .= $c[$y + 1];
               }
          }
          if($d == $e)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(strlen($b) == strlen($c))
     {
          if($b == $c)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(strlen($b) > strlen($c))
     {
          print "NO\n";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = str_split(trim(fgets(STDIN)));
     $c = str_split(trim(fgets(STDIN)));
     if(count($b) < count($c))
     {
          $b = array_unique($b);
          $c = array_unique($c);
          if(implode($b) == implode($c))
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(count($b) == count($c))
     {
          if($b == $c)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(count($b) > count($c))
     {
          print "NO\n";
     }
}
?>

<?php
fscanf(STDIN,"%d",$n);
//$pair=$n*2;
while ($n--)
{
	$typed=trim(fgets(STDIN));
	$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
	$printedSplit=str_split($printed,2);
	//print_r($printedSplit);
	$tLength=strlen($typed);
	$pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	 {
	 	for ($i=0; $i <$tLength-1 ; $i++)
	 	{
	 	  $str1[$i]=substr($typed,$i,2);
	 	}
	 	for ($i=0; $i <$pLength-1 ; $i++)
	 	{
	 	  $str2[$i]=substr($printed,$i,2);
	 	}
	 	$count=0;
	 	for ($i=0; $i <count($str1) ; $i++)
	 	 {

                  $k=0;
	 		for ($j=0; $j <count($str2) ; $j++)
	 		{
	 			if($str1[$i]==$str2[$j])
	 			{
	 				$count++;
	 				$k=1;
	 				break;
	 			}
	 		}
	 		if($k==0)
	 			break;

	 	}

	 	//print_r($store1);

       if($count==$tLength-1)
	 	$same=true;

     }
    echo $same?"YES\n":"NO\n";
}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));
    $tLength=strlen($typed);
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
    $pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	     {

                if(count(array_unique(str_split($typed)))==1)
                    $grp1[0]=$typed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($typed)-1 ; $i++)
                         {
                              if($typed[$i]!=$typed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp1=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($typed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($typed,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($typed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp1)."\n";
                if(count(array_unique(str_split($printed)))==1)
                    $grp2[0]=$printed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($printed)-1 ; $i++)
                         {
                              if($printed[$i]!=$printed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp2=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp2[$i]=substr($printed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp2[$i]=substr($printed,$ara[$i-1]+1,$diff);
                                }
                              $grp2[$i+1]=substr($printed,$ara[$i]+1);

                        }
                    }
                    if(count($grp1)!=count($grp2))
                        $same=false;
                     else
                     {
                       $same=true;

                        for ($i=0; $i <count($grp1) ; $i++)
                        {
                            if(strlen($grp1[$i])>strlen($grp2[$i]))
                            {
                                $same=false;
                                break;
                            }
                        }
                     }

        }

   echo $same?"YES\n":"NO\n";
}

<?php
fscanf(STDIN,"%d",$n);
//$pair=$n*2;
while ($n--)
{
	$typed=trim(fgets(STDIN));
	$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
	$printedSplit=str_split($printed,2);
	//print_r($printedSplit);
	$tLength=strlen($typed);
	$pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	 {
	 	for ($i=0; $i <$tLength-1 ; $i++)
	 	{
	 	  $str1[$i]=substr($typed,$i,2);
	 	}
	 	for ($i=0; $i <$pLength-1 ; $i++)
	 	{
	 	  $str2[$i]=substr($printed,$i,2);
	 	}
	 	$count=0;
	 	for ($i=0; $i <count($str1) ; $i++)
	 	 {
	 		for ($j=0; $j <count($str2) ; $j++)
	 		{
	 			if($str1[$i]==$str2[$j])
	 				$count++;
	 		}
	 		if($count==0)
	 			break;
	 	}

	 	//print_r($store1);

       if($count==$tLength-1)
	 	$same=true;

     }
    echo $same?"YES\n":"NO\n";
}

<?php
fscanf(STDIN,"%d",$n);
//$pair=$n*2;
while ($n--)
{
	$typed=trim(fgets(STDIN));
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
	//$printedSplit=str_split($printed,2);
	//print_r($printedSplit);
	$tLength=strlen($typed);
	$pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	 {

	      for ($i=0; $i <$pLength ; $i++)
	      {
	      	if($printed[$i]==$typed[$count])
	      	 {
	      		$count++;

	      		if($count==$tLength)
	      		{
	      			$same=true;
	      			break;
	      		}
	      	 }
	      	 //echo "$count\n";

	      }

     }
   echo $same?"YES\n":"NO\n";
}

<?php
fscanf(STDIN,"%d",$n);
//$pair=$n*2;
while ($n--)
{
	$typed=trim(fgets(STDIN));
	$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
	$printedSplit=str_split($printed,2);
	//print_r($printedSplit);
	$tLength=strlen($typed);
	$pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	 {
	 	for ($i=0; $i <$tLength-1 ; $i++)
	 	{
	 	  $str1[$i]=substr($typed,$i,2);
	 	}
	 	for ($i=0; $i <$pLength-1 ; $i++)
	 	{
	 	  $str2[$i]=substr($printed,$i,2);
	 	}
	 	for ($i=0; $i <count($str1) ; $i++)
	 	 {
	 	$count=0;

	 		for ($j=0; $j <count($str2) ; $j++)
	 		{
	 			if($str1[$i]==$str2[$j])
	 				$count++;
	 		}
	 		if($count==0)
	 			break;
	 	}

	 	//print_r($store1);

       if($count==$tLength-1)
	 	$same=true;

     }
    echo $same?"YES\n":"NO\n";
}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));
    $tLength=strlen($typed);
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
    $pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	     {

                $same=true;

                if(count(array_unique(str_split($typed)))==1)
                    $grp1[0]=$typed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($typed)-1 ; $i++)
                         {
                              if($typed[$i]!=$typed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp1=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($typed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($typed,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($typed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp1)."\n";
                if(count(array_unique(str_split($printed)))==1)
                    $grp2[0]=$printed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($printed)-1 ; $i++)
                         {
                              if($printed[$i]!=$printed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp2=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp2[$i]=substr($printed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp2[$i]=substr($printed,$ara[$i-1]+1,$diff);
                                }
                              $grp2[$i+1]=substr($printed,$ara[$i]+1);

                        }
                    }
                    if(count($grp1)!=count($grp2))
                        $same=false;
                     else
                     {
                        for ($i=0; $i <count($grp1) ; $i++)
                        {
                            if(strlen($grp1[$i])>strlen($grp2[$i]))
                            {
                                $same=false;
                                break;
                            }
                        }
                     }

        }

   echo $same?"YES\n":"NO\n";
}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));
    $tLength=strlen($typed);
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
    $pLength=strlen($printed);

	$same=false;
       // echo "before\n";
    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	     {

               $grp1=array();
               $grp2=array();

                if(count(array_unique(str_split($typed)))==1)
                    $grp1[0]=$typed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($typed)-1 ; $i++)
                         {
                              if($typed[$i]!=$typed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($typed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($typed,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($typed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp1)."\n";
                if(count(array_unique(str_split($printed)))==1)
                    $grp2[0]=$printed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($printed)-1 ; $i++)
                         {
                              if($printed[$i]!=$printed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp2[$i]=substr($printed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp2[$i]=substr($printed,$ara[$i-1]+1,$diff);
                                }
                              $grp2[$i+1]=substr($printed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp2)."\n";
                    //echo count($grp1).count($grp2)."\n";
                    if(count($grp1)!=count($grp2))
                    {
                        $same=false;
                        //echo "some";
                    }
                     else
                     {
                        $same=true;
                       //echo "hi\n";

                        for ($i=0; $i <count($grp1) ; $i++)
                        {
                            if(strlen($grp1[$i])>strlen($grp2[$i]))
                            {
                                $same=false;
                                break;
                            }
                        }
                     }

        }

   echo $same?"YES\n":"NO\n";
}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));
    $tLength=strlen($typed);
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
    $pLength=strlen($printed);

	$same=false;
       // echo "before\n";
    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	     {

               $grp1=array();
               $grp2=array();

                if(count(array_unique(str_split($typed)))==1)
                    $grp1[0]=$typed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($typed)-1 ; $i++)
                         {
                              if($typed[$i]!=$typed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($typed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($typed,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($typed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp1)."\n";
                if(count(array_unique(str_split($printed)))==1)
                    $grp2[0]=$printed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($printed)-1 ; $i++)
                         {
                              if($printed[$i]!=$printed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp2[$i]=substr($printed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp2[$i]=substr($printed,$ara[$i-1]+1,$diff);
                                }
                              $grp2[$i+1]=substr($printed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp2)."\n";
                    //echo count($grp1).count($grp2)."\n";
                    if(count($grp1)!=count($grp2))
                    {
                        $same=false;
                        //echo "some";
                    }
                     else
                     {
                        $same=true;
                       //echo "hi\n";

                        for ($i=0; $i <count($grp1) ; $i++)
                        {
                            if(strlen($grp1[$i])>strlen($grp2[$i]))
                            {
                                $same=false;
                                break;
                            }
                            //$count=0;
                            for ($j=0,$k=0; $j <strlen($grp2[$i]) ; $j++)
                            {
                                if($grp2[$i][$j]==$grp1[$i][$k])
                                {
                                       $k++;
                                       if($k==strlen($grp1[$i]))
                                       {
                                        $same=true;
                                        break;
                                       }
                                }
                                else
                                    $same=false;

                            }
                            if($same==true)
                                break;
                        }
                     }

        }

   echo $same?"YES\n":"NO\n";
}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));
    $tLength=strlen($typed);
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
    $pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	     {

                $same=true;

                if(count(array_unique(str_split($typed)))==1)
                    $grp1[0]=$typed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($typed)-1 ; $i++)
                         {
                              if($typed[$i]!=$typed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp1=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($typed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($typed,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($typed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp1)."\n";
                if(count(array_unique(str_split($printed)))==1)
                    $grp2[0]=$printed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($printed)-1 ; $i++)
                         {
                              if($printed[$i]!=$printed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp2=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp2[$i]=substr($printed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp2[$i]=substr($printed,$ara[$i-1]+1,$diff);
                                }
                              $grp2[$i+1]=substr($printed,$ara[$i]+1);

                        }
                    }
                    if(count($grp1)!=count($grp2))
                        $same=false;
                     else
                     {
                        for ($i=0; $i <count($grp1) ; $i++)
                        {
                            if(array_unique(str_split($grp1[$i]))!=array_unique(str_split($grp2[$i])))
                            {
                                $same=false;
                                break;
                            }
                        }
                     }

        }

   echo $same?"YES\n":"NO\n";
}


Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.

The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.  Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.   The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0.  At the last stop, all the passengers exit the tram and it becomes empty. More formally, .  No passenger will enter the train at the last stop. That is, bn = 0.

Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).

NoteFor the first example, a capacity of 6 is sufficient:   At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.  At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now.  At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now.  Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.

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

<?php
    $fp = fopen('php://stdin', 'r');
    $n = fgets($fp);
    $a = array();
    $b = array();
    while(!feof($fp))
        list($a[], $b[]) = explode(' ', rtrim(fgets($fp)));
    $max = $now = $b[0];
    for($i = 1; $i < $n; $i++) {
        $now = $now - $a[$i] + $b[$i];
        if($now > $max)
            $max = $now;
    }
    echo $max;
?>

<?php
	$cur = 0;
	$max = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		list($out,$in) = explode(' ',fgets(STDIN));
		$cur = $cur - (int)$out + (int)$in;
		if ($cur > $max) $max = $cur;
	}
	echo $max;

<?php

fscanf (STDIN, "%d",$n);
$num = 0;
$res = 0;
for ($i=0; $i < $n; $i++)
{
  fscanf (STDIN, "%d %d", $out, $in);
  $num -= $out;
  $num += $in;
  if ($num > $res) $res = $num;
}
echo $res;
?>

<?php

$n = readline();

$stationStatus = [];
for($i = 0; $i < $n; $i++){
    $stationStatus[] = explode(' ', readline());
}
$count = 0;
$max = 0;
foreach ($stationStatus as $key => $stationStatus) {
    $count -= $stationStatus[0];
    $count += $stationStatus[1];
    if($count > $max) $max = $count;
}
echo $max;

<?php
$input = STDIN;
$output = STDOUT;

fscanf($input,"%d",$n);
$capacity = 0;
$totalPassengers = 0;
for($i=0; $i<$n; ++$i) {
    fscanf($input,"%d%d",$exited,$entered);
    $totalPassengers += $entered - $exited;
    if($totalPassengers > $capacity) {
        $capacity = $totalPassengers;
    }
}
fprintf($output,"%d",$capacity);

?>

<?php
/**
 * Created by PhpStorm.
 * User: kuangzhexi
 * Date: 13-11-11
 * Time: 下午12:07
 */

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

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

$max = 0;
$num = 0;
while ($n--) {
    $line = fgets($fp);
    list($a, $b) = explode(" ", trim($line));

    $num = $num - $a + $b;
    if ($num > $max) {
        $max = $num;
    }
}

print $max . "\n";

<?php
list($n)=explode(" ", trim(fgets(STDIN)));
$max=0;$s=0;
while ($n>0):
list($a,$b)=explode(" ", trim(fgets(STDIN)));
$s=$s-$a+$b;
if ($s>$max) $max=$s;
$n--;
endwhile;
print $max;
?>

<?php

$a = array();
fscanf(STDIN, "%d", $n);
$res = 0;
$cnt = 0;

for ($i = 0; $i < $n; $i++) {
	$cur = explode(" ", trim(fgets(STDIN)));
	$cnt = $cnt - $cur[0] + $cur[1];
	if ($cnt > $res)
	    $res = $cnt;
}

echo $res;

<?php
    $n = trim(fgets(STDIN));
    $m = 0; $c = 0;
    for($i = 0; $i < $n; $i++){
        $s = explode(" ",trim(fgets(STDIN)));
        $c=$c-$s[0]+$s[1];
        if($c > $m)$m = $c;
    }
    fwrite(STDOUT, $m);

<?php
	$i = 0;
	$min = 0;
	$x = 0;
	$stop = trim(fgets(STDIN));
	while($i<$stop)
	{
		$pass = explode(" ",trim(fgets(STDIN)));
		$x = $x - $pass[0] + $pass[1];
		if($min < $x)
			$min = $x;
		$i++;
	}
	echo $min;
?>

<?php
$stops = fgets(STDIN);
$num_pasengers = 0;$previous_enter=0;
for ($i=0; $i <$stops ; $i++) {
	$exit_enter = explode(' ', fgets(STDIN));
	$num_pasengers += $exit_enter[1]-$exit_enter[0];
	$max_num[$i] = $num_pasengers;
}
echo max($max_num);
?>

<?php
$n = fgets(STDIN);
$total=0;
$ans=0;
for($i=0;$i<$n;$i++){
list($a, $b) = explode(' ',trim(fgets(STDIN)));
 $total-=$a-$b;
 if($total>$ans){$ans=$total;}
}
echo $ans;
?>

<?php

$flag = 1; //must be not zero for STDIN
$in = 'php://stdin';
if (!$flag)
{
    $in = "input.txt";
}
$fd = fopen($in, "r");
fscanf($fd, "%d\n", $n);

$exit = array($n);
$enter = array($n);
for ($c = 0; $c < $n; $c++)
{
    fscanf($fd, "%d %d\n", $exit[$c], $enter[$c]);
}
fclose($fd);

for ($c = 0, $pass = 0, $max = 0; $c < $n; $c++)
{
    $pass+=$enter[$c];
    $pass-=$exit[$c];
    if ($max < $pass)
    {
        $max = $pass;
    }
}
print $max . "\n";
?>

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

    fscanf($stdin, "%d\n", $n);

    $maxCapacity = 0;
    $capacity = 0;
    for($i=0; $i<$n; $i++){
        fscanf($stdin, "%d%d\n", $a, $b);
        $tmp = $b - $a;
        $capacity += $tmp;
        if($capacity > $maxCapacity)
            $maxCapacity = $capacity;

    }

    echo $maxCapacity;

    fclose($stdin);
?>

<?php
$counter=0;
$max=0;
fscanf(STDIN, "%d",$n);
for ($i=0; $i < $n; $i++) {
	fscanf(STDIN,"%d %d",$out, $in);
	$counter-=($out-$in);
	if($max<$counter) $max=$counter;
}
echo $max;
?>

<?php
   $n = trim(fgets(STDIN));
   $sum = 0;
   $max = 0;
   for($i=0;$i<$n;$i++)
   {
       $pass = explode(' ',trim(fgets(STDIN)));
       $sum -= $pass[0];
       $sum += $pass[1];
       if($sum > $max) $max = $sum;
   }
   echo $max;
?>

<?php

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

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

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

$r = 0;
$a = $b = [];
$max = 0;
$t = 0;

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

for ($i = 0; $i < $n; $i++) {
    list($a[$i], $b[$i]) = fscanf($input, "%d %d\n");

    $t -= $a[$i];
    $t += $b[$i];

    if ($t > $max) {
        $max = $t;
    }
}

fwrite($output, $max);

<?php

$n = fgets(STDIN);
$sum = 0;
$max = 0;
for ($i=1; $i <= $n; $i++) {
    list($a, $b) = explode(' ',trim(fgets(STDIN)));
    $sum -= (int) $a;
    $sum += (int) $b;
    if ($sum > $max) {
        $max = $sum;
    }
}

echo $max;

<?php
$max = 0;
$cur = 0;
$n = intval(fgets(STDIN));
for($i=0;$i<$n;$i++) {
    $in = explode(' ',trim(fgets(STDIN)));
    $cur -= $in[0];
    $cur += $in[1];
    if($cur > $max) {
        $max = $cur;
    }
}
echo( $max );

<?php
$n = trim(fgets(STDIN));
$station_list[] = array();
$max = 0;

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

$count_passengers = array();
for( $i=0; $i<$n; $i++ ){
    for( $j=0; $j<1; $j++ ) {
        if( $i > 0 )
        {
            $in_bus = (($count_passengers[$i-1]) - $station_list[$i][$j]);
        }else{
            $in_bus = 0;
        }
        $count_passengers[$i] = $in_bus + $station_list[$i][++$j];
    }
}

for( $k=0; $k<sizeof($count_passengers); $k++  ){
    if( $max < $count_passengers[$k] )
    {
        $max = $count_passengers[$k];
    }
}
echo $max;

<?
$a = trim(fgets(STDIN));
$max = 0;
$curr = 0;
for($i = 0; $i < $a; $i++){
    list($out, $in) = explode(' ', trim(fgets(STDIN)));
    $curr -= $out;
    $curr += $in;
    if($max < $curr)
        $max = $curr;
}
echo $max;

<?php
$n = trim(fgets(STDIN));
$max=0;
$current=0;
for ($i=0;$i<$n;$i++)
{
    $player = explode(" ",fgets(STDIN));
    $current += $player[1]-$player[0];
    if ($max<$current)$max=$current;
}
echo $max;
?>

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

	$n = input();
	$result = 0;
	$now = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$str = explode(" ", trim(fgets($stdin)));
		$now += $str[1] - $str[0];
		if ($now > $result)
		{
			$result = $now;
		}
	}
	echo $result;
?>

<?php
$f = fopen("php://stdin", "r");
fscanf($f, "%d", $n);

$res = 0;
$cur = 0;
while ($n--) {
    fscanf($f, "%d%d", $a, $b);
    $cur-=$a;
    $cur+=$b;
    $res = max($res, $cur);
}
echo $res;

?>

<?
$n=trim(fgets(STDIN));
$in=0;$max=0;
for($i=0;$i<$n;$i++)
    {
        $ex=explode(" ",trim(fgets(STDIN)));
        $in-=$ex[0];
        $in+=$ex[1];
        if($in>$max)$max=$in;
    }
   echo $max;
?>

<?php
  //$file = fopen("/home/py/PHPtraing/input.txt", "r");
  $file = STDIN;
  $n = (int) fgets($file);

  $now = 0;
  $ans = 0;
  for ($i=0; $i < $n; $i++) {
    $a = explode(" ",trim(fgets($file)));
    $now = $now - $a[0] + $a[1];
    $ans = max($ans,$now);
  }

  print $ans;

 fclose($file);

?>

<?php
// Open the file
$input = "C:\\xampp\\htdocs\\test\\test.txt";
if (@(ONLINE_JUDGE)) {
 $input = 'php://stdin';
}

// Add each line to an array

    $array = explode("\n", file_get_contents($input));
    array_shift($array);
    $array = array_values($array);
    $output = [];
    $max = 0;
    $id = 0;
    foreach ($array as $key => $value){
        $arr = explode(" ", $value);
        $id += -intval($arr[0]) + intval($arr[1]);

        if($id > $max) $max= $id;

    }
    echo $max;

<?php
$n = trim(fgets(STDIN));
$as = [];
$bs = [];

$cap = 0;
$cap_min = 0;
for($i = 0; $i<$n ; $i++){
  $input = fgets(STDIN);
  $array = array_map('intval', explode(' ', $input));
  array_push($as, $array[0]);
  array_push($bs, $array[1]);
}
for ($i = 0; $i<$n ; $i++){
  if($i == 0){
    $cap = $bs[$i];
    $cap_min = $cap;
  }else{
    $cap = $cap - $as[$i] + $bs[$i];
    if($cap > $cap_min){
      $cap_min = $cap;
    }
  }
}
echo $cap_min;

?>

<?php
$f = fopen('php://stdin', 'r');
//$f = fopen('5q.txt', 'r');
$n = trim(fgets($f));

$max = 0;
$cur = 0;

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

    $cur-=$a[0];
    $cur+=$a[1];

    if ($cur>$max) $max = $cur;
}

echo $max;

<?php

fscanf(STDIN, "%d\n", $n);

$maxRiders = 0;
$currentRiders = 0;

for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%d %d\n", $a, $b);

    $currentRiders -= $a;
    $currentRiders += $b;
    $maxRiders = ($currentRiders > $maxRiders) ? $currentRiders : $maxRiders;
}

echo $maxRiders;

?>

<?php
fscanf(STDIN, "%d", $n);
$max_number = 0;
$max_array = array();
while($n--){
	fscanf(STDIN, "%s%s", $out, $in);
	$max_number = ($max_number - $out) + $in;
	$max_array[] = $max_number;
}
echo max($max_array);

<?php
$n = trim(fgets(STDIN));
$pass = 0;
$min = 0;
for ($i=0;$i<$n;$i++){
    $s = explode(' ', trim(fgets(STDIN)));
    $pass += -$s[0] + $s[1];
    if ($pass > $min)
        $min = $pass;
}
echo $min;
?>

<?php
    $f = fopen('php://stdin', 'r');
    $count = (int)fgets($f);
    $people = 0;
    $max = 0;

    for ($i = 0; $i < $count; $i++) {
        $arr = explode(' ', fgets($f));

        if (($people = $people - (int)$arr[0] + (int)$arr[1]) > $max) $max = $people;
    }

    echo $max;
?>

<?php
    $f = fopen('php://stdin', 'r');
    $count = (int)fgets($f);
    $people = 0;
    $max = 0;

    for ($i = 0; $i < $count; $i++) {
        $out = '';
        $in = '';

        while(is_numeric($char = fgetc($f))) {
            $out.= $char;
        }
        while(is_numeric($char = fgetc($f))) {
            $in.= $char;
        }
        fgets($f);

        if (($people = $people - $out + $in) > $max) $max = $people;
    }

    echo $max;
?>

<?php

$kol = trim(fgets(STDIN));

while ($str = fgets(STDIN))
{
    $mas[] = explode(' ', $str);
}
$n = 0;
for ($i = 0; $i < count($mas); $i++)
{
    $max[] = $n - $mas[$i][0] + $mas[$i][1];
    $n = $n - $mas[$i][0] + $mas[$i][1];
}
$vmestimost = max($max);
echo $vmestimost;

?>

<?php
/**
 * Created by IntelliJ IDEA.
 * User: 低调的程序员
 * Date: 2015/4/25
 * Time: 1:17
 */

while(fscanf(STDIN,"%d",$n)){
    $ans=0;
    $per=0;
    while($n-->0){
        fscanf(STDIN,"%d%d",$ex,$en);
        $per+=$en-$ex;
        if($ans<$per)$ans=$per;
    }
    fprintf(STDOUT,"%d\n",$ans);
}

<?php
// 116A Трамвай

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

$input_line = fgets($in);
$n = (int) $input_line;

$out = 0;
$col = 0;

for ($i=1; $i <= $n; $i++) {

    $input_line = fgets($in);

    list($a, $b) = split(" ", $input_line);
    $a = (int) $a;
    $b = (int) $b;

    $col += $b - $a;

    if ($col > $out) $out = $col;
}

echo $out;

?>

<?php
    $n = trim(fgets(STDIN));
    $count=0; $min=0;
    for ($i=1; $i<=$n; $i++){
        list($a,$b) = explode(' ',trim(fgets(STDIN)));
        $count=$count+$b-$a;
        if ($min<$count) $min=$count;
    }
    print($min);

?>

<?php
    fscanf(STDIN, "%d",$s);
    $c=0;
    $max=0;
    while (fscanf(STDIN, "%d %d", $out, $in)){
      $c = $c-$out+$in;
      $max=$c>$max?$c:$max;
    }
    echo $max;
?>

<?php

$count = (int) fgets(STDIN);

$passengers = 0;
$maxPassengers = 0;
for ($i = 0; $i < $count; $i++) {
    $rawQInfo = rtrim(fgets(STDIN));
    $rawInfo = explode(' ', $rawQInfo);

    $output = (int) $rawInfo[0];
    $input = (int) $rawInfo[1];

    $passengers += $input - $output;
    $maxPassengers = max($passengers, $maxPassengers);
}

echo $maxPassengers . PHP_EOL;

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=explode(' ',trim(fgets(STDIN)));
$cur_peoples=0;
$max=0;
for($i=0;$i<$n;$i++){
    $cur_peoples-=$arr[$i][0];
    $cur_peoples+=$arr[$i][1];
    if($cur_peoples>$max) $max=$cur_peoples;
}
echo $max;
?>

<?php
fscanf(STDIN, '%d', $n);	// считываем кол-во остановок

$trainCounter = 0;
$total = array();

for($i = 0; $i < $n; $i++) {	// считываем количество выходящих и входящих
	fscanf(STDIN, '%d%d', $outcomers, $incomers);
	 //$trainCounter[$i] = $outcomers . '' . $outcomers;
	// $trainCounter[$i + 1] = $incomers;
	$trainCounter = $trainCounter - $outcomers;

	$trainCounter = $trainCounter + $incomers;
	array_push($total, $trainCounter);
}

printf(max($total));

<?php
fscanf(STDIN, '%d', $n);

$capacity = 0;
$max = 0;
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%d %d', $wyj, $wej);
    $capacity = $capacity - $wyj + $wej;
    //echo $capacity."\n";
    if ($capacity > $max) $max = $capacity;
}

echo $max;

<?php

error_reporting(0);
$arr = [];
$testCase = (int) fgets(STDIN);

while ($testCase--) {
    list($n1, $n2) = explode(' ', fgets(STDIN));
    $current = $current - $n1;
    $current = $current + $n2;
    $arr[] = $current;
}
echo max($arr)."\n";

<?
$n=trim(fgets(STDIN));
$intram=0;$mx=0;
for($i=0;$i<$n;$i++)
    {
        $ex=explode(" ",trim(fgets(STDIN)));
        $intram-=$ex[0];
        $intram+=$ex[1];
        if($intram>$mx)$mx=$intram;
    }
   echo $mx;
?>

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

$c = 0;
$m = 0;
for($i=0;$i<$n;$i++){
 list($a, $b) = explode(' ',trim(fgets(STDIN)));
 $c -= $a - $b;
 if($m < $c) $m = $c;
}

print $m;
?>

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

$cur=0;
$max=0;
for($i=1; $i<count($lines); $i++)
{
    list($minus, $plus)=explode(" ", trim($lines[$i]));
    $cur=$cur-$minus+$plus;
    if ($cur>$max) $max=$cur;
}
echo $max;
?>

<?php
$a = array();
fscanf(STDIN, "%d", $n);
$result = 0;
$count = 0;
for ($i = 0; $i < $n; $i++) {
	$task = explode(" ", trim(fgets(STDIN)));
	$count = $count - $task[0] + $task[1];
	if ($count > $result) $result = $count;
}

fprintf(STDOUT, $result);

<?php

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

fscanf($stdin, "%d", $n);

$currentMax = 0;
$inTram = 0;

for($i = 0; $i < $n; $i++)
{
	list($out, $in) = fscanf($stdin, "%d %d");

	$inTram -= $out;
	$inTram += $in;
	if($inTram > $currentMax)
	{
		$currentMax = $inTram;
	}
}

echo $currentMax;

<?php
//116A: Tram
$n = trim(fgets(STDIN)); //$n = 4;
//$array = array("0 3", "2 5", "4 2", "4 0");
$capacities = array();
$ontram = 0;
for ($i = 0; $i < $n; $i++) {
    list($off, $on) = explode(" ", trim(fgets(STDIN)));
    //list($off, $on) = explode(" ", $array[$i]);
    $ontram = $ontram - $off;
    $ontram = $ontram + $on;
    $capacities[] = $ontram;
}
rsort($capacities);
echo $capacities[0];
?>

<?php

$m_capacity = $c_capacity = 0;

$s1 = fgets(STDIN);

while ($s = fgets(STDIN))
{
    $row = preg_split("/\s/", $s);
    $c_capacity = $c_capacity - $row[0] + $row[1];

    if ($c_capacity > $m_capacity)
        $m_capacity = $c_capacity;
}

echo $m_capacity;
exit;

<?php
	fgets(STDIN);
	$max = -1;
	$now = 0;
	$arr = [];
	while(fscanf(STDIN, '%d %d', $arr[0], $arr[1])){
		$now = $now - $arr[0] + $arr[1];
		if($now > $max) $max = $now;
	}
	echo $max;
?>

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

<?php

fscanf (STDIN, "%d",$n);
$num = 0;
$res = 0;
for ($i=0; $i < $n; $i++)
{
  fscanf (STDIN, "%d %d", $o, $i);
  $num -= $o;
  $num += $i;
  if ($num > $res) $res = $num;
}
echo $res;
?>

<?php

$dir = fopen("php://stdin", 'r');
$input = stream_get_contents($dir);

$arr = explode(PHP_EOL, $input);
$sum = 0;
$max = 0;
for ($i=1; $i <= $arr[0]; $i++) {
    $sum -= (int) $arr[$i][0];
    $sum += (int) $arr[$i][2];
    if ($sum > $max) {
        $max = $sum;
    }
}

echo $max;

<?php
$n = trim(fgets(STDIN));
$max=0;
for ($i=0;$i<$n;$i++)
{
    $player = explode(" ",fgets($resource));
    if ($max<=$player[1]-$player[0])
    {
        $max+=$player[1]-$player[0];
    }
}
echo $max;
?>

<?php
$n = trim(fgets(STDIN));
$max=0;
$current=0;
for ($i=0;$i<$n;$i++)
{
    $player = explode(" ",fgets($resource));
    $current += $player[1]-$player[0];
    if ($max<$current)$max=$current;
}
echo $max;
?>

<?php
$n = trim(fgets(STDIN));
$max=0;
for ($i=0;$i<$n;$i++)
{
    $player = explode(" ",fgets(STDIN));
    if ($max<=$player[1]-$player[0])
    {
        $max+=$player[1]-$player[0];
    }
}
echo $max;
?>

<?php
// Open the file
//$input = "C:\\xampp\\htdocs\\test\\test.txt";
$input = 'php://stdin';

//$file = @fopen("C:\\xampp\\htdocs\\test\\test.txt", 'r');

$file = fopen($input, 'r');

// Add each line to an array
if ($file) {
    $array = explode("\n", file_get_contents($input));

    $array = array_values($array);
    $arr = [4, 7];
    var_dump($array);

    $output = [];
    $max = 0;
    $id = 0;
    foreach ($array as $key => $value) {
        $thisWordCodeVerdeeld = str_split($value);
        foreach ($thisWordCodeVerdeeld as $val) {
            $a = in_array(intval($val), $arr);
            if ($a == false) {
                echo 'NO';
                break;
            }
        }
//        $output[] = $str;
    }
    echo 'YES';
}
    fclose($file);

<?php
// Open the file
//$input = "C:\\xampp\\htdocs\\test\\test.txt";
$input = 'php://stdin';

//$file = @fopen("C:\\xampp\\htdocs\\test\\test.txt", 'r');

$file = fopen($input, 'r');

// Add each line to an array
if ($file) {
    $array = explode("\n", file_get_contents($input));

    array_shift($array);
    $array = array_values($array);
    $output = [];
    $max = 0;
    $id = 0;
    foreach ($array as $key => $value){
        $id += -intval($value[0]) + intval(substr($value,-1));
        if($id > $max) $max= $id;

//        $output[] = $str;
    }
    fclose($file);
    echo $max;
}

<?php
// Open the file
//$input = "C:\\xampp\\htdocs\\test\\test.txt";
$input = 'php://stdin';

//$file = @fopen("C:\\xampp\\htdocs\\test\\test.txt", 'r');

$file = fopen($input, 'r');

// Add each line to an array
if ($file) {
    $array = explode("\n", file_get_contents($input));

    array_shift($array);
    $array = array_values($array);
    $output = [];
    $max = 0;
    $id = 0;
    foreach ($array as $key => $value){
        $id += -intval($value[0]) + intval(substr($value,-1));
        if($id > $max) $max= $id;

    }
    echo $max;
    fclose($file);
}

<?php
// Open the file
//$input = "C:\\xampp\\htdocs\\test\\test.txt";
$input = 'php://stdin';

//$file = @fopen("C:\\xampp\\htdocs\\test\\test.txt", 'r');

$file = fopen($input, 'r');

// Add each line to an array
if ($file) {
    $array = explode("\n", file_get_contents($input));

    array_shift($array);
    $array = array_values($array);
    $output = [];
    $max = 0;
    $id = 0;
    foreach ($array as $key => $value){
        $id += -intval($value[0]) + intval(substr($value,-1));
        if($id > $max) $max= $id;

//        $output[] = $str;
    }
    echo $max;
    fclose($file);
}

<?php
$n = trim(fgets(STDIN));
$pass = 0;
$min = 0;
for ($i=0;$i<$n;$i++){
    $s = explode(' ', trim(fgets(STDIN)));
    $pass += $s[0] + $s[1];
    if ($pass > $min)
        $min = $pass;
}
echo $min;
?>

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
	$arr[]=explode(' ',trim(fgets(STDIN)));
print_r($arr);
$cur_peoples=0;
$max=0;
for($i=0;$i<$n;$i++){
	$cur_peoples-=$arr[$i][0];
	$cur_peoples+=$arr[$i][1];
	if($cur_peoples>$max) $max=$cur_peoples;
}
echo $max;
?>

<?php

error_reporting(0);
$std = fopen("php://stdin","r");
fscanf($std,"%d",$n);
$current = 0;
$arr = [];
for($i = 0; $i < $n; $i++)
{
    fscanf($std,"%d",$n1);
    fscanf($std,"%d",$n2);

    $current = $current - $n1;
    $current = $current + $n2;
    $arr[] = $current;
}
echo max($arr)."\n";

fclose($std);