Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number — the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously).Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him.

The first line contains the single integer n (1 ≤ n ≤ 1000) — the number of contests where the coder participated. The next line contains n space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000.

Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests.

NoteIn the first sample the performances number 2 and 3 are amazing.In the second sample the performances number 2, 4, 9 and 10 are amazing.

<?php
    $fp = fopen('php://stdin', 'r');
    $n = rtrim(fgets($fp));
    $results = explode(' ', rtrim(fgets($fp)));
    $amazing = 0;
    $min = $max = $results[0];
    for($i = 1; $i < $n; $i++) {
        if($results[$i] > $max) {
            $max = $results[$i];
            $amazing++;
        }elseif($results[$i] < $min) {
            $min = $results[$i];
            $amazing++;
        }
    }
    echo $amazing;
?>

<?php

function solve(){
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_n = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_arr = $Token->nextIntArray();

	$temp_max = $inp_arr[0];
	$temp_min = $inp_arr[0];
	$temp_c = 0;
	$AMAIZING = 0;
	foreach ($inp_arr as $as_i) {
		$temp_c++;
		if ($temp_c == 1) continue;

		if ($temp_max < $as_i) {
			$temp_max = $as_i;
			$AMAIZING++;
		} elseif ($temp_min > $as_i) {
			$temp_min = $as_i;
			$AMAIZING++;
		}
	}

	printf("%d", $AMAIZING);

}

function run(){
	solve();
}

ob_end_clean();
run();

//input -  $inp_
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $_

class Token{
	private $token;
	private $tok;

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

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

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

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

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}
/*
	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
}

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

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

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

<?php

$file = file('php://stdin');

$numbers = explode(' ', $file[1], trim($file[0]));

$result = 0;

$min = (int) $numbers[0];
$max = (int) $numbers[0];

foreach ($numbers as $number) {
	$number = (int) $number;
	if ($number < $min) {
		$min = $number;
		$result++;
	} else if ($number > $max) {
		$max = $number;
		$result++;
	}
}

echo $result . PHP_EOL;

<?php
while($s = fgets(STDIN)){
$input .= $s;
}

$input = explode("\r\n", $input);
$line = $input[1];

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

foreach ($numbers as $key => $value) {
    $numbers[$key] = intval($value);
}

$counter = 0;
$array = array();

for($i=0; $i<count($numbers); $i++) {
    if(in_array($numbers[$i], $array)) continue;

    $array[] = $numbers[$i];
    if(((max($array) == $numbers[$i]) || (min($array) == $numbers[$i])) && count($array) !== 1 ) {
        $counter++;
    }
}

echo $counter;

<?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);
$data = fgets($fd);
$score = explode(" ", $data);
fclose($fd);

for ($c = 0; $c < $n; $c++)
{
    $score[$c] = intval($score[$c]);
}
$result = 0;
$min = $score[0];
$max = $score[0];
for ($c = 1; $c < $n; $c++)
{
    if ($score[$c] < $min)
    {
        $min = $score[$c];
        $result++;
    }
    if ($score[$c] > $max)
    {
        $max = $score[$c];
        $result++;
    }
}
printf("$result\n");
?>

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

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

<?
error_reporting(0);

$fp = fopen("php://stdin",'r');
$count = (int)(str_replace( "\r\n", '', fgets($fp)));
$points = explode(" ", trim( str_replace( "\r\n", '', fgets($fp)) ) );

$min = $points[0];
$max = $points[0];
$countTrue = 0;
for( $i = 1; $i < $count; $i++ ){
	if( $points[$i] > $max){
		$max = $points[$i];
		$countTrue++;
	}
	if( $points[$i] < $min){
		$min = $points[$i];
		$countTrue++;
	}
}
echo $countTrue;
fclose($fp);
?>

<?php
fscanf(STDIN,"%d",$n);
$line=trim(fgets(STDIN));
$arr=explode(" ",$line);
$count=0;
$max=$arr[0];
$min=$arr[0];
for($i=0;$i<count($arr);$i++)
    {
    	if($arr[$i]>$max){
    		$max=$arr[$i];
    		$count++;
    	}
    	elseif ($arr[$i]<$min) {
    		$min=$arr[$i];
    		$count++;
    	}
    }
    echo "$count";

//echo $count;

<?php

$n = readline();
$stroka = readline();
$stroka = explode(' ', $stroka);
$shock = 0;
$sravnenie_plus = $stroka[0];
$sravnenie_minus = $stroka[0];
foreach ($stroka as $v) {
    if ($v > $sravnenie_plus) {
        $shock += 1;
        $sravnenie_plus = $v;
    }
    if ($v < $sravnenie_minus) {
        $shock += 1;
        $sravnenie_minus = $v;
    }
}

echo $shock;

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

$mas = explode(' ', trim(fgets(STDIN)));
$k = 0;
for ($i = 1; $i < count($mas); $i++)
{
    if ($mas[$i] > max(array_slice($mas, 0, $i)) || $mas[$i] < min(array_slice($mas, 0, $i)))
        $k++;
}
echo $k;

?>

<?php
// 155A     I_love_\%username\%
$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);

$min = $max = $arr[0];
$out = 0;

foreach ($arr as $key => $value) {
    if ($min > (int) $value) {
        $min = $value;
        $out ++;
    }

    if ($max < (int) $value) {
        $max = $value;
        $out ++;
    }
}

echo $out;

?>

<?php
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$arr = explode("\n", $n);
$numbers = explode(" ", $arr[1]);
$min = (int) $numbers[0];
$max = (int) $numbers[0];
$count = 0;
for($i = 1; $i < $arr[0]; $i++){
    $temp = (int) $numbers[$i];
    if($temp < $min){
        $min = $temp;
        $count++;
    } else if($temp > $max){
        $max = $temp;
        $count++;
    }
}
echo $count;

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

$lines=trim($lines);
$lines=explode("\n", $lines);

$numbers=explode(" ", trim($lines[1]));
$res=0;
$min=$numbers[0]; $max=$numbers[0];
for ($i=1; $i<count($numbers); $i++)
{
    $cur=$numbers[$i];
    if ($cur>$max) { $max=$cur; $res++;}
    if ($cur<$min) { $min=$cur; $res++;}
}
echo $res;
?>

<?php

$count = fgets(STDIN);
$exhibitions = explode(" ", fgets(STDIN));
$local_min = $exhibitions[0];
$local_max = $exhibitions[0];
$magix = 0;
for ($i=1;$i<count($exhibitions); $i++) {
        $e=(int)$exhibitions[$i];
                if ($e < $local_min) {
                        $local_min = $e;
                        $magix++;
                }
                if ($e > $local_max) {
                        $local_max = $e;
                        $magix++;
                }
}
fputs(STDOUT, $magix);

<?php
error_reporting("off");
//155A: I_love_%username%
$n = trim(fgets(STDIN)); //$n = 10;
$scores = explode(" ", trim(fgets(STDIN))); //$scores = explode(" ", "4664 6496 5814 7010 5762 5736 6944 4850 3698 7242");
$recordhigh = 0;
$recordlow = 0;
$amazing = 0;
foreach ($scores as $key => $value) {
    if ($key == 0) {
        $recordhigh = $value;
        $recordlow = $value;
    }
    if ($value > $recordhigh) {
        $recordhigh = $value;
        $amazing++;
    }
    if ($value < $recordlow) {
        $recordlow = $value;
        $amazing++;
    }
}
echo $amazing;
?>

<?php

function solve(){
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_n = $Token->nextInt();
	$Token = new Token(rtrim(fgets(STDIN)), " ");
	$inp_arr = $Token->nextIntArray();

	$temp_max = $inp_arr[1];
	$temp_min = $inp_arr[1];
	$temp_c = 0;
	$AMAIZING = 0;
	foreach ($inp_arr as $as_i) {
		$temp_c++;
		if ($temp_c == 1) continue;

		if ($temp_max < $as_i) {
			$temp_max = $as_i;
			$AMAIZING++;
		} elseif ($temp_min > $as_i) {
			$temp_min = $as_i;
			$AMAIZING++;
		}
	}

	printf("%d", $AMAIZING);

}

function run(){
	solve();
}

ob_end_clean();
run();

//input -  $inp_
//block    $temp_
//two block$ttemp_
//as 	   $as_
//instance $(Upper)
//ref      $ref
//class menba $_

class Token{
	private $token;
	private $tok;

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

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

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

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

	public function nextIntArray() {
		$temp_arr = array();
		$flag = -1;
		while ($flag !== 1) {
			$thisToken = $this->nextToken();
			if ($thisToken !== false) {
				$temp_arr[] = $thisToken;
			} else {
				$flag = 1;
			}
		}
		return $temp_arr;
	}
/*
	public function nnextIntArray($num) {
		$temp_arr = array();
		for ($i = 0; $i < $num; $i++) {
			$temp_arr[] = (int)$this->token;
		}
		return $temp_arr;
	}
}
*/
}

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

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

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

<?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);
$data = fgets($fd);
$score = explode(" ", $data);
fclose($fd);

for ($c=0;$c<$n;$c++)
{
   $score[$c]=  intval($score[$c]);
}
$result=0 ;
$min=$score[0]; $max=$score[0];
for ($c=1 ;$c<$n;$c++)
{
    if ($score[$c]<$min)
    {
        $min=$score[$c];
        $result++;
    }
    if ($score[$c]>$max)
    {
        $max=$score[$c];
        $result++;
    }
    printf ( "min=%d max=%d score=%d\n" ,$min, $max, $score[$c]);
}
printf ("$result\n");
?>

<?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);
$data = fgets($fd);
$score = explode(" ", $data);
fclose($fd);

for ($c=0;$c<$n;$c++)
{
   $score[$c]=  intval($score[$c]);
}
$result=0 ;
$min=0; $max=0;
for ($c=0 ;$c<$n;$c++)
{
    if ($score[$c]<$min)
    {
        $min=$score[$c];
        $result++;
    }
    if ($score[$c]>$max)
    {
        $max=$score[$c];
        $result++;
    }
}
printf ("$result\n");
?>

<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%d", $min);
$max = $min;
$a = 0;
for ($i=0;$i<$n-1;$i++){
	fscanf(STDIN, "%d", $curr);
	if ($curr < $min){
		$a++;
		$min = $curr;
	}
	else if ($curr > $max){
		$a++;
		$max = $curr;
	}
}
echo $a;
?>

<?php
fscanf(STDIN, "%d %d", $n, $min);
$max = $min;
$a = 0;
for ($i=0;$i<$n-1;$i++){
	fscanf(STDIN, "%d", $curr);
	if ($curr < $min){
		$a++;
		$min = $curr;
	}
	else if ($curr > $max){
		$a++;
		$max = $curr;
	}
}
echo $a;
?>

<?php
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$arr = explode("\n", $n);
$numbers = explode(" ", $arr[1]);
$min = (int) $numbers[0];
$max = (int) $numbers[0];
$count = 0;
echo $numbers[0].'\n';
for($i = 1; $i < $arr[0]; $i++){
    $temp = (int) $numbers[$i];
    if($temp < $min){
        $min = $temp;
        $count++;
    } else if($temp > $max){
        $max = $temp;
        $count++;
    }
    echo $temp.'\n';
}
echo $count;

<?php
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$arr = explode("\n", $n);
$numbers = explode(" ", $arr[1]);
$num = $numbers[0];
$min = $num;
$max = $num;
$count = 0;
for($i = 1; $i < $arr[0]; $i++){
    if($numbers[$i] < $min || $numbers[$i] > $max){
        $count++;
    }
}
echo $count;

<?php
$s = fopen("php://stdin", 'r');
$n = stream_get_contents($s);
$arr = explode("\n", $n);
$numbers = explode(" ", $arr[1]);
$num = $numbers[0];
$min = $num;
$max = $num;
$count = 0;
for($i = 1; $i < $arr[0]; $i++){
    $temp =  $numbers[$i];
    if($temp < $min){
        $min = $temp;
        $count++;
    }
    if($temp > $max){
        $max = $temp;
        $count++;
    }
}
echo $count;

<?php
$count = fgets(STDIN);
$exhibitions = explode(" ", fgets(STDIN), "\n");
$local_min = $exhibitions[0];
$local_max = $exhibitions[0];
$magix = 0;
for ($i = 1; $i < count($exhibitions); $i++) {
        $e = (int) $exhibitions[$i];
        if ($e != "") {
                if ($e < $local_min) {
                        $local_min = $e;
                        $magix++;
                }
                if ($e > $local_max) {
                        $local_max = $e;
                        $magix++;
                }
        }
}
fputs(STDOUT, $magix);

<?php

$count = fgets(STDIN);
$exhibitions = explode(" ", fgets(STDIN));
$local_min = $exhibitions[0];
$local_max = $exhibitions[0];
$magix = 0;
for ($i = 1; $i < count($exhibitions); $i++) {
        $e = (int) $exhibitions[$i];
        if ($e != "") {
                if ($e < $local_min) {
                        $local_min = $e;
                        $magix++;
                }
                if ($e > $local_max) {
                        $local_max = $e;
                        $magix++;
                }
        }
}
fputs(STDOUT, $magix);

<?php

$count = fgets(STDIN);
$exhibitions = explode(" ", trim(fgets(STDIN),"\n"));
$local_min = $exhibitions[0];
$local_max = $exhibitions[0];
$magix = 0;
for ($i=1;$i<count($exhibitions); $i++) {
        $e=$exhibitions[$i];
        if ($e!="") {
                if ($e < $local_min) {
                        $local_min = $e;
                        $magix++;
                }
                if ($e > $local_max) {
                        $local_max = $e;
                        $magix++;
                }
        }
}
print $magix;

<?php

$count = fgets(STDIN);
$exhibitions = explode(" ", fgets(STDIN),"\n");
$local_min = $exhibitions[0];
$local_max = $exhibitions[0];
$magix = 0;
for ($i=1;$i<count($exhibitions); $i++) {
        $e=(int)$exhibitions[$i];
        if ($e!="") {
                if ($e < $local_min) {
                        $local_min = $e;
                        $magix++;
                }
                if ($e > $local_max) {
                        $local_max = $e;
                        $magix++;
                }
        }
}
print $magix;


Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage.The situation is complicated by the dependence of online courses, for each course there is a list of those that must be passed before starting this online course (the list can be empty, it means that there is no limitation).Help Polycarp to pass the least number of courses in total to get the specialty (it means to pass all main and necessary courses). Write a program which prints the order of courses. Polycarp passes courses consistently, he starts the next course when he finishes the previous one. Each course can't be passed more than once.

The first line contains n and k (1 ≤ k ≤ n ≤ 105) — the number of online-courses and the number of main courses of Polycarp's specialty.  The second line contains k distinct integers from 1 to n — numbers of main online-courses of Polycarp's specialty.  Then n lines follow, each of them describes the next course: the i-th of them corresponds to the course i. Each line starts from the integer ti (0 ≤ ti ≤ n - 1) — the number of courses on which the i-th depends. Then there follows the sequence of ti distinct integers from 1 to n — numbers of courses in random order, on which the i-th depends. It is guaranteed that no course can depend on itself.  It is guaranteed that the sum of all values ti doesn't exceed 105.

Print -1, if there is no the way to get a specialty.  Otherwise, in the first line print the integer m — the minimum number of online-courses which it is necessary to pass to get a specialty. In the second line print m distinct integers — numbers of courses which it is necessary to pass in the chronological order of their passage. If there are several answers it is allowed to print any of them.

NoteIn the first test firstly you can take courses number 1 and 2, after that you can take the course number 4, then you can take the course number 5, which is the main. After that you have to take only the course number 3, which is the last not passed main course.

<?php
error_reporting(E_ALL);
ini_set("memory_limit", "256M");
//ini_set("max_execution_time", 2);

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

list($allCount, $mainCount) = explode(" ", trim(fgets($fd)));
$dependencies = [];
$dependencies[0] = explode(" ", trim(fgets($fd)));
array_unshift($dependencies[0], $mainCount);

for ($i = 1; $i <= $allCount; $i++) {
    $dependencies[$i] = explode(" ", trim(fgets($fd)));
}

$preBuilt = [];
$built = [];
$string = "";
function buildDependencyTree($v) {
    global $dependencies, $built, $string, $preBuilt;
    $v = (int) $v;

    if ($dependencies[$v][0] == 0) {
        $preBuilt[$v] = true;
        $built[$v] = true;
        return [];
    }
    $result = [];
    for ($i = 1; $i <= $dependencies[$v][0]; $i++) {
        if (!isset ($preBuilt[$dependencies[$v][$i]])) {
            $preBuilt[$dependencies[$v][$i]] = true;
            $result[$dependencies[$v][$i]] = buildDependencyTree($dependencies[$v][$i]);
            $built[$dependencies[$v][$i]] = true;
            $string .= $dependencies[$v][$i] . " ";
        } elseif (isset($preBuilt[$dependencies[$v][$i]]) && !isset($built[$dependencies[$v][$i]])) {
            die("-1");
        }
    }
    return $result;
}

$path = [];
$tree = buildDependencyTree(0);
echo count($built) . "\n";
echo $string;


Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down.There is a cursor pointing at some symbol of the string. Suppose that cursor is at position i (1 ≤ i ≤ n, the string uses 1-based indexing) now. Left and right arrow keys are used to move cursor around the string. The string is cyclic, that means that when Nam presses left arrow key, the cursor will move to position i - 1 if i > 1 or to the end of the string (i. e. position n) otherwise. The same holds when he presses the right arrow key (if i = n, the cursor appears at the beginning of the string).When Nam presses up arrow key, the letter which the text cursor is pointing to will change to the next letter in English alphabet (assuming that alphabet is also cyclic, i. e. after 'z' follows 'a'). The same holds when he presses the down arrow key.Initially, the text cursor is at position p. Because Nam has a lot homework to do, he wants to complete this as fast as possible. Can you help him by calculating the minimum number of arrow keys presses to make the string to be a palindrome?

The first line contains two space-separated integers n (1 ≤ n ≤ 105) and p (1 ≤ p ≤ n), the length of Nam's string and the initial position of the text cursor. The next line contains n lowercase characters of Nam's string.

Print the minimum number of presses needed to change string into a palindrome.

NoteA string is a palindrome if it reads the same forward or reversed.In the sample test, initial Nam's string is:  (cursor position is shown bold).In optimal solution, Nam may do 6 following steps:The result, , is now a palindrome.


It is a holiday season, and Koala is decorating his house with cool lights! He owns $$$n$$$ lights, all of which flash periodically.After taking a quick glance at them, Koala realizes that each of his lights can be described with two parameters $$$a_i$$$ and $$$b_i$$$. Light with parameters $$$a_i$$$ and $$$b_i$$$ will toggle (on to off, or off to on) every $$$a_i$$$ seconds starting from the $$$b_i$$$-th second. In other words, it will toggle at the moments $$$b_i$$$, $$$b_i + a_i$$$, $$$b_i + 2 \cdot a_i$$$ and so on.You know for each light whether it's initially on or off and its corresponding parameters $$$a_i$$$ and $$$b_i$$$. Koala is wondering what is the maximum number of lights that will ever be on at the same time. So you need to find that out.    Here is a graphic for the first example.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$), the number of lights. The next line contains a string $$$s$$$ of $$$n$$$ characters. The $$$i$$$-th character is "1", if the $$$i$$$-th lamp is initially on. Otherwise, $$$i$$$-th character is "0". The $$$i$$$-th of the following $$$n$$$ lines contains two integers $$$a_i$$$ and $$$b_i$$$ ($$$1 \le a_i, b_i \le 5$$$)  — the parameters of the $$$i$$$-th light.

Print a single integer — the maximum number of lights that will ever be on at the same time.

NoteFor first example, the lamps' states are shown in the picture above. The largest number of simultaneously on lamps is $$$2$$$ (e.g. at the moment $$$2$$$).In the second example, all lights are initially on. So the answer is $$$4$$$.