The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.The language is that peculiar as it has exactly one variable, called x. Also, there are two operations:  Operation ++ increases the value of variable x by 1.  Operation -- decreases the value of variable x by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable x. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains.A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains.You're given a programme in language Bit++. The initial value of x is 0. Execute the programme and find its final value (the value of the variable when this programme is executed).

The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme. Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.

Print a single integer — the final value of x.

<?php
$r=0;
$stmt= array();
fscanf(STDIN, "%d",$n);
for($i=0;$i<$n;$i++){
    fscanf(STDIN, "%s",$stmt[$i]);
}
for($i=0;$i<$n;$i++){
    if(strtolower($stmt[$i])== "++x"|strtolower($stmt[$i])== "x++")
    $r++;
    else
    $r--;
}
echo $r;

<?php
    $fp = fopen('php://stdin', 'r');
    $n = rtrim(fgets($fp));
    $operators = array();
    while(!feof($fp)) {
        $operators[] = rtrim(fgets($fp));
    }
    $x = 0;
    for($i=0; $i < $n; $i++)
        if(strpos($operators[$i], '++') !== false)
            $x++;
        else
            $x--;
    echo $x;
?>

<?php
	$total = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		$in = fgets(STDIN);
		if (substr_count($in, '++')) {
			$total++;
		} elseif (substr_count($in, '--')) {
			$total--;
		}
	}
	echo $total;
?>

<?php
while($str = fgets(STDIN)) $arr[] = explode(' ', trim($str));
if(!isset($arr)) {
    $arr[] = explode(' ', '2');
    $arr[] = explode(' ', 'X++');
    $arr[] = explode(' ', '--X');
}
$out = 0;
for($i=1; $i<sizeof($arr); $i++) {
    if(strpos($arr[$i][0], '++')!==false) $out++;
    elseif(strpos($arr[$i][0], '--')!==false) $out--;
}
echo $out;
?>

<?  fscanf(STDIN,"%d",$x);$x=0;
    while(fscanf(STDIN,"%s",$s)){
        eval(str_replace("X","\$x",$s).";");
    }
    echo $x; ?>

<?  fscanf(STDIN,"%d",$x);$x=0;
    while(fscanf(STDIN,"%s",$s)){
        $s=str_replace("X","\$x",$s);
        eval($s.";");
    }
    fprintf(STDOUT,"%d",$x); ?>

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

fscanf($input,"%d",$n);
$x = 0;
for($i=0; $i<$n; ++$i) {
    fscanf($input,"%s",$xstr);
    switch($xstr[1]) {
        case '+':
            ++$x;
            break;
        case '-':
            --$x;
            break;
    }
}
fprintf($output,"%d",$x);

?>

<?php

$x = 0;
$n = (int) readline();

for ( $i = 0; $i < $n; $i++ ) {
	$str = readline();
	$x = $x + substr_count($str, '++');
	$x = $x - substr_count($str, '--');
}

echo $x;

<?
$num = (int) trim(fgets(STDIN));

$x = 0;
for($i = 0; $i < $num; $i++){
    if(strpos(fgets(STDIN), '--') !== false){
        $x--;
    }else{
        $x++;
    }
}
echo $x;

<?php
$n = (int)readline();
$output = 0;
for($i = 0; $i < $n; $i++) {
    $input = readline();
    $input[1] == '+' ? $output++ : $output--;
}
echo $output;

<?php
    $n = trim(fgets(STDIN));
    $result = 0;
    for($i = 0; $i < $n; $i++){
        $args[$i] = trim(fgets(STDIN));
        if(strpos($args[$i],"++") === false) $result--;
        else $result++;
    }
    fwrite(STDOUT, $result);

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

$input = explode("\n", $input);
unset($input[0]);
$x = 0;

foreach($input as $line)
{
    $line = str_replace(array('x', 'X'), '', trim($line));
    if ($line == '--')
    {
        $x--;
    }

    if ($line == '++')
    {
        $x++;
    }
}

echo $x;

<?php
	 // Check Examples

 //php 7.3.0

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

while( $line = fgets( $f ) ) {

  if (stripos($line, '+') !== false) $sum++;
  if (stripos($line, '-') !== false) $sum--;
}

fclose( $f );
echo $sum;
 ?>

<?php
//Codeforces Round #173 (Div. 2)
//13 Mar 2013

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

$N = input();
$risan = 0;

while ($N-- > 0)
{
	$s = input();
	if ($s == "++X" || $s == "X++") ++$risan;
	else --$risan;
}

echo $risan;
echo "\n";

?>

<?php
$num_str = fgets(STDIN);
$result = 0;
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgets(STDIN);
    if ($cur_str[1] == "+") {
        $result++;
    } else {
        $result--;
    }
}
echo $result;
?>

<?php
/*$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;*/
$num_str = (int)(fgets(STDIN));
$result = 0;
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgets(STDIN);
    if ($cur_str[1] == "+") {
        $result++;
    } else {
        $result--;
    }
}
echo $result;
?>

<?php
$x=0;
fscanf(STDIN, "%d",$n);
for ($i=0; $i < $n; $i++) {
	fscanf(STDIN,"%s",$operator);

	if ($operator==="++X" || $operator==="X++") $x++;
	else $x--;
}
echo $x;
?>

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

function foo($x)
{
    return $x === '++X' || $x === 'X++';
}

$r = 0;

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

for ($i = 0; $i < $n; ++$i) {
    list($x) = fscanf($input, "%s\n");

    $r = foo($x) ? $r + 1 : $r - 1;
}

fwrite($output, $r);

<?php

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

$a=0;
for ($i=0;$i<$n;$i++)
{
    $s = trim(fgets($stdin));
    if ($s[1]=='+') {$a++;} else {$a--;}
}
fclose($stdin);

echo $a;
?>

<?php
// http://codeforces.com/problemset/problem/282/A

// Input
// The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
$n = fgets(STDIN);

// The language is that peculiar as it has exactly one variable, called x.
$x = 0;

// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
for ($i=0; $i < $n; $i++)
{
	$operation = rtrim(fgets(STDIN));

	if (false !== strpos($operation, '++'))
		$x++;
	else
		$x--;
}

echo $x;

?>

<?php
    $x = trim(fgets(STDIN));
    $ret = 0;

    for ($i=0; $i<$x; $i++)
    {
        $s = trim(fgets(STDIN));
        if (strpos($s,"++") === false)
            $ret--;
        else
            $ret++;

    }
    echo $ret;
?>

<?php
$n = trim(fgets(STDIN));
$operation = array();
for( $i=0; $i<$n; $i++ ){
    $operation[$i] = preg_replace('/x/i','',trim(fgets(STDIN)));
}

$output = 0;
for( $i=0; $i<$n; $i++ ){
    if( $operation[$i] == '++' ){
        $output++;
    }elseif( $operation[$i] == '--' )
    {
        $output--;
    }
}
echo $output;

<?php
$n=fgets(STDIN);
$k = 0;
for ($i=0; $i < $n; $i++) {
	$a=fgets(STDIN);
	if (strripos($a, '+')) $k++;
	else $k--;
}
print($k);
?>

<?  fscanf(STDIN,"%d",$x);$x=0;
    while(fscanf(STDIN,"%s",$s)){
        eval(str_replace("X","\$x",$s).";");
    }
    echo $x; ?>

<?php
$n = trim(fgets(STDIN));
$counter = 0;
for ($i = 1; $i <= $n; $i++)
{
   // list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
   $str = trim(fgets(STDIN));
   $str = str_replace("X", "", $str);
   if ($str == '++')
        $counter++;
    else
        $counter--;
   //if (($a+$b+$c) > 1) $counter++;
}

echo $counter;

<?php

$x = 0;

$n = readline();

for($i = 0; $i < $n; $i++) {
    $line = readline();
    $len = 3;

    for($k = 0; $k < $len; $k++) {
        switch($line[$k]) {
            case '+':
                $x++;
                continue 3;
            case '-':
                $x--;
                continue 3;
            case 'X':
                continue 2;
        }
    }

}

echo $x;

<?php
$n = (fgets(STDIN));
$result=0;
for ($i=0;$i<$n;$i++)
{
    $line = fgets(STDIN);
    if (strripos($line,"++")!==false)
    {
        $result++;
    }
    else
    {
        $result--;
    }
}
echo $result;
?>

<?php

function getStdIn(bool $asInt = false): array
{
    $stdIn = explode(' ', trim(fgets(STDIN)));

    if ($asInt) {
        foreach ($stdIn as $key => $value) {
            $stdIn[$key] = (int)$value;
        }
    }

    return $stdIn;
}

function stdOut($output)
{
    fwrite(STDOUT, $output);
}

function solve(): void
{
    [$n] = getStdIn(true);
    $x = 0;

    for ($i = 0; $i < $n; $i++) {
        [$operation] = getStdIn();
        if (strpos($operation, '++') !== false) {
            $x++;
        } elseif (strpos($operation, '--') !== false) {
            $x--;
        }
    }

    stdOut($x);
}

solve();

<?php

/**
 * @return int
 */
function getInt() {
    return (int) trim(fgets(STDIN));
}

/**
 * @return string
 */
function getStr() {
    return (string) trim(fgets(STDIN));
}

/**
 * @return array
 */
function getRow($len) {
    return array_slice(explode(' ', trim(fgets(STDIN))), 0, $len);
}

const N = "\n";

/*** SOLVING */

$x = 0;
$n = getInt();

while ($n--) {
    $str = getStr();
    if ($str == 'X++' OR $str == '++X') {
        $x++;
    } else if ($str == 'X--' OR $str == '--X') {
        $x--;
    } else if ($str == 'X++' OR $str == '++X') {
        $x = -$x;
    }
}

echo $x;

<?php
$n = 0;
$colOper = trim(fgets(STDIN));
for ($i=0;$i<$colOper;$i++) {
    $operand = trim(fgets(STDIN));
    if ($operand == '++X') {
        ++$n;
    }
    elseif ($operand == 'X++') {
        $n++;
    }
    elseif ($operand == '--X') {
        --$n;
    }
    elseif ($operand == 'X--') {
        $n--;
    }
}
echo $n;

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

	$n = input();
	$result = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$str = input();
		if ($str[1] == '-')
		{
			$result--;
		}
		else
		{
			$result++;
		}
	}
	echo $result;
?>

<?php
$input = file('php://stdin', FILE_IGNORE_NEW_LINES);
array_shift($input);
$x = 0;
foreach ($input as $command) {
    if (strpos($command, '+') !== false) {
       $x ++;
    } else {
        $x --;
    }
}
echo $x;

<?php
$X = 0;
fscanf(STDIN, "%d", $n);
while($n--) {
	fscanf(STDIN, "%s", $s);
	if(strpos($s, "++") !== false) {
		++$X;
	}
	else {
		--$X;
	}
}
echo $X;

<?php
$input = trim(fgets(STDIN));
$noOfInputs = (int)$input;
$x = 0;
for($counter = 0 ; $counter < $noOfInputs; $counter++){
    $input = trim(fgets(STDIN));
    if($input == "--X" || $input == "X--"){
        $x--;
    }else{
        $x++;
    }
}
echo $x;
?>

<?php
$n = trim(fgets(STDIN));
$nilai = 0;
while($n--){
	$s = trim(fgets(STDIN));
	eval(str_replace("X", "\$nilai", $s) . ";");
/*	if (substr_count($s, "++"))
		$nilai++;
	else if ($substr_count($s, "--"))
		$nilai--; */
}
print $nilai;
?>

<?php
    $f = fopen('php://stdin', 'r');
    $cnt = (int)fgets($f);
    $ount = 0;
    for ($i = 0; $i < $cnt; $i++) {
        $out+= strpos(fgets($f), '+') === FALSE ? -1 : 1;
    }
    echo $out;
?>

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

while(fscanf(STDIN,"%d",$n)){
    $ans=0;
    while($n-->0){
        $str=stream_get_line(STDIN,10,"\n");
        $h=substr($str,0,2);
        $t=substr($str,1,2);
        if($h=="++" or $t=="++")$ans++;
        else $ans--;
    }
    fprintf(STDOUT,"%d\n",$ans);
}

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

//Get The Number Of Statements.
$n = (int)explode("\n",$input)[0];

//Then Loop Throw The Statements To Apply Them On ( x ).
$int = 0;

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

    $current_statement = (string)explode("\n",$input)[$i + 1];

    $current_statement = trim($current_statement,"\r\n");

    if(in_array($current_statement,array("X++","++X"))) {

        $int++;

    }elseif(in_array($current_statement,array("X--","--X"))) {

        $int--;

    }

}

//return ( x ).
echo $int;

?>

<?php
$x=0;
$i=0;
$b=fgets(STDIN);
while ($i<$b) {
	$a=str_replace("X","",trim(fgets(STDIN)));
	if($a=="--")
		$x--;
	else
		$x++;
	$i++;
}
echo $x;
?>

<?php
// 282A 	Bit++

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

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

$out = 0;

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

    $input_line = fgets($in);

    if (substr($input_line, 1, 1) == '+') {
        $out++;
    } else {
        $out--;
    }
}

echo $out;

?>

<?php

class Solution
{
    public function solve()
    {
        fscanf(STDIN, '%d', $n);

        $x = 0;
        while ($n--) {
            fscanf(STDIN, '%s', $s);
            $x += strpos($s, '-') !== false ? -1 : 1;
        }

        echo $x . PHP_EOL;
    }
}

$sol = new Solution();
$sol->solve();

<?php

$inputString = fgets(STDIN);

$n = (int) $inputString;

$answer = 0;
for ($i = 1; $i <= $n; $i++) {
    $inputString = rtrim(fgets(STDIN));
    if ($inputString[0] == '+' || $inputString[1] == '+' || $inputString[2] == '+') {
        $answer++;
    } else {
        $answer--;
    }
}

echo  $answer . PHP_EOL;

<?php
fscanf(STDIN, '%d\n', $n);
$lines = array();
$x = 0;

for($i = 0; $i < $n; $i++) {	// считываем n строк
	$lines[$i] = fgets(STDIN);

}

	foreach($lines as $line) {
		$line = trim($line);		// хз почему, но это как-то сработало.
	if(($line == '++X') | ($line == 'X++')){
			$x++;
		} else {
			$x--;
		}

	 }

	printf($x);

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

function oper($string) {
    for ($i = 0; $i < strlen($string); $i++) {
       if ($string[$i] == '+') return true;
    }

    return false;
}

$wynik = 0;
while($n--) {
    fscanf(STDIN, '%s', $string);
    if (oper($string)) $wynik++;
    else $wynik--;
}

echo $wynik;

<?
$n=trim(fgets(STDIN));
$x=0;
for($i=0;$i<$n;$i++)
    {
        $op=trim(fgets(STDIN));
        if(strpos($op,'+')!== False)++$x;
        else --$x;
    }
   echo $x;
?>

<?php
$a = array();
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
	$a[] = trim(fgets(STDIN));
}
$result = 0;
foreach ($a as $task) {
	if ($task == '++X' || $task == 'X++')
		$result++;
	else
		$result--;
}

fprintf(STDOUT, $result);

<?php

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

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

$res = 0;
for($i = 0; $i < $n; $i++)
{
	fscanf($stdin, "%s", $com);
	if(preg_match('/\+/', $com))
	{
		$res++;
	}
	else
	{
		$res--;
	}
}

echo $res;

<?php

fscanf(STDIN, "%d\n", $number);
$i = 0;
$counter = 0;

while($i<$number && $line = trim(fgets(STDIN))){

    if($line == '++X' || $line == 'X++') $counter++ ;
	else $counter-- ;
}

fwrite(STDOUT, $counter."\n");

<?php

while($item = trim(fgets(STDIN))) {
    $data[] = $item;
}
$count = array_shift($data);
$result = 0;
for ($i = 0; $i <=$count; $i++) {
    if($data[$i][1] === '+') {
        $result++;
    } elseif($data[$i][1] === '-') {
        $result--;
    }
}

echo $result;

<?php
//282A: Bit++
$n = trim(fgets(STDIN));
$x = 0;
for ($i = 0; $i < $n; $i++) {
    $explode = str_split(trim(fgets(STDIN)));
    sort($explode);
    if ($explode[0] == "+") {
        $x++;
    } else {
        $x--;
    }
}
echo $x;
?>

<?php

$is_first = true;
$x = 0;
while ($row = fgets(STDIN)) {
    if ($is_first === true) {
        $is_first = false;
        continue;
    }
    if (strpos($row, '++') !== false) {
        $x++;
    }
    if (strpos($row, '--') !== false) {
        $x--;
    }
}
echo $x;

<?php
	fscanf(STDIN, '%d', $num);
	$res = 0;
	while (fscanf(STDIN, '%s', $input)){
		if(strpos($input, '++') !== false) $res++;
		if(strpos($input, '--') !== false) $res--;
	}
	echo $res;
?>

<?php
    $fp = fopen('php://stdin', 'r');
    $n = rtrim(fgets($fp));
    $operations = array();
    while(!feof($fp)) {
        $operations[] = rtrim(fgets($fp));
    }
    $x = 0;
    foreach($operations as $o) {
        if(strpos($o, '++')!==false)
            $x++;
        else
            $x--;
    }
    echo $x;
?>

<?php
    $fp = fopen('php://stdin', 'r');
    $n = rtrim(fgets($fp));
    $operations = array();
    while(!feof($fp)) {
        $operations[] = rtrim(fgets($fp));
    }
    $x = 0;
    foreach($operations as $o) {
        if(strpos($o, '++'))
            $x++;
        else
            $x--;
    }
    echo $x;
?>

<?php
	$total = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		if (substr_count(fgets(STDIN), '++')) {
			$total++;
		} elseif (substr_count(fgets(STDIN), '++')) {
			$total--;
		}
	}
	echo $total;
?>

<?php
	$total = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		if (substr_count(fgets(STDIN), '++')) {
			$total++;
		} elseif (substr_count(fgets(STDIN), '--')) {
			$total--;
		}
	}
	echo $total;
?>

<?php
while($str = fgets(STDIN)) $arr[] = explode(' ', trim($str));
if(!isset($arr)) {
    $arr[] = explode(' ', '2 4');
}
$out = 0;
for($i=1; $i<sizeof($arr); $i++) {
    if(strpos($arr[$i], '++')!==false) $out++;
    elseif(strpos($arr[$i], '--')!==false) $out--;
}
echo $out;
?>

<?
$num = (int) trim(fgets(STDIN));

$x = 0;
for($i = 0; $i < $num; $i++){
    if(strpos('--', fgets(STDIN)) !== false){
        $x--;
    }else{
        $x++;
    }
}
echo $x;

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

$input = explode("\n", $input);
unset($input[0]);
$x = 0;

foreach($input as $line)
{
    $line = str_replace('X', '', trim($line));
    if ($line == '--') {
        $x--;
    } else {
        $x++;
    }
}

echo $x;

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

$input = explode("\n", $input);
unset($input[0]);
$x = 0;

foreach($input as $line)
{
    $line = str_replace(array('x', 'X'), '', trim($line));
    if ($line == '--') {
        $x--;
    } else {
        $x++;
    }
}

echo $x;

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

$input = explode("\r\n", $input);
unset($input[0]);
$x = 0;

foreach($input as $line)
{
    $line = str_replace('X', '', trim($line));
    if ($line == '--') {
        $x--;
    } else {
        $x++;
    }
}

echo $x;

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
settype($cur_str, "string");
if ($cur_str == "++x" || $cur_str == "++X") $result++;

echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == '++x') $result++;

echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgets($in);
    if ($cur_str == "++x" || $cur_str == "x++") $result++;
    if ($cur_str == "--x" || $cur_str == "x--") $result--;
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
settype($cur_str, "string");
if ($cur_str == "++x") $result++;

echo $result;
?>

<?php
/*$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;*/
$num_str = (int)(fgets(STDIN));
$result = 0;
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgets(STDIN);
    if ($cur_str == "++x" || $cur_str == "x++") {
        $result++;
    } else {
        $result--;
    }
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgets($in);
    settype($cur_str, "string");
    if ($cur_str == "++x" || $cur_str == "x++") $result++;
    if ($cur_str == "--x" || $cur_str == "x--") $result--;
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == "++x") $result = 10;

echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
settype($cur_str, "string");
if ($cur_str == "++x" || $cur_str == "++X") {
    $result = $result + 1;
}
echo $result;
?>

<?php
/*$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;*/
$num_str = (int)(fgets(STDIN));
$result = 0;
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgetc(STDIN);
    if ($cur_str == "+") {
        $result++;
    } else {
        $result--;
    }
}
echo $result;
?>

<?php
$number_string = fgets(STDIN);
$result = 0;
for ($counter = 1; $counter <= $number_string; $counter++) {
    $current_string = fgets(STDIN);
    if (($current_string == "x++") || ($current_string == "++x")) {
        $result = $result + 1;
    } else {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$cur_str = fgets($in);
$next_str = fgets($in);
//$result = 0;
//while (! feof($in)) {
/*    $cur_str = fgets($in);
    if ($cur_str == "++x" || $cur_str == "x++") {
        $result = $result + 1;
    } elseif ($cur_str == "--x" || $cur_str == "x--") {
        $result = $result - 1;
    }*/
    //$result = $result + 1;
//}
echo $next_str;
?>

<?php
$in = fopen("php://stdin", "r");
$result = 0;
while (!feof($in)) {
    $cur_str = fgets($in);
    if ($cur_str == "++x" or $cur_str == "x++") {
        $result = $result + 1;
    } else if ($cur_str == "--x" or $cur_str == "x--") {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$number_string = fgets(STDIN);
$result = 0;
for ($counter = 1; $counter <= $number_string; $counter++) {
    $current_string = fgets(STDIN);
    if ($current_string == "x++" || $current_string == "++x") {
        $result = $result + 1;
    } else {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$number_string = fgetc(STDIN);
$result = 0;
for ($counter = 1; $counter <= $number_string; $counter++) {
    $current_string = fgetc(STDIN);
    if (($current_string == "x++") || ($current_string == "++x")) {
        $result = $result + 1;
    } else {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$number_string = (int)(fgetc(STDIN));
$result = 0;
for ($counter = 0; $counter <= $number_string; $counter++) {
    $current_string = fgetc(STDIN);
    if (($current_string == "x++") || ($current_string == "++x")) {
        $result = $result + 1;
    } else {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
while (!feof($in)) {
    $cur_str = fgets($in);
    if ($cur_str == "++x" || $cur_str == "x++") {
        $result = $result + 1;
    } elseif ($cur_str == "--x" || $cur_str == "x--") {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$cur_str = fgets($in);
//$result = 0;
//while (! feof($in)) {
/*    $cur_str = fgets($in);
    if ($cur_str == "++x" || $cur_str == "x++") {
        $result = $result + 1;
    } elseif ($cur_str == "--x" || $cur_str == "x--") {
        $result = $result - 1;
    }*/
    //$result = $result + 1;
//}
echo $cur_str;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 20;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == "\+\+x") $result = 10;

echo $result;
?>

<?php
$number_string = (int)(fgetc(STDIN));
$result = 0;
for ($counter = 1; $counter <= $number_string; $counter++) {
    $current_string = fgetc(STDIN);
    if (($current_string == "x++") || ($current_string == "++x")) {
        $result = $result + 1;
    } else {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$in = fopen("php://stdin", "r");
$result = 0;
while (!feof($in)) {
    $cur_str = fgets($in);
    if ($cur_str == "++x" or $cur_str == "x++") {
        $result = $result + 1;
    } else if ($cur_str == "--x" or $cur_str == "x--") {
        $result = $result - 1;
    } else break;
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 20;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == "\+\+x") $result = 10;

echo $cur_str;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == "\+\+x") $result = 10;

echo $result;
?>

<?php
/*$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;*/
$num_str = (int)(fgets(STDIN));
echo $num_str;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;
?>

<?php
/*$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;*/
$num_str = (int)(fgets(STDIN));
$result = 0;
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgetc(STDIN);
    if ($cur_str == "++x" || $cur_str == "x++") {
        $result++;
    } else {
        $result--;
    }
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == "++X") $result++;

echo $result;
?>

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

$arr = explode(PHP_EOL, $input);
$x = 0;
for($i=1;$i<count($arr);$i++){
  if($arr[$i][1] == '+')
    $x++;
  else
    $x--;
}
echo $x."\n";

<?php
$dir = fopen("php://stdin", 'r');
$input = stream_get_contents($dir);
// $input="2
// ++x
// ++x";

$arr = explode(PHP_EOL, $input);

$x = 0;
for($i=1;$i<count($arr);$i++){
  if($arr[$i][1] == '+')
    $x++;
  else
    $x--;
}
echo $x ."\n";
?>

<?php
$dir = fopen("php://stdin", 'r');
$input = stream_get_contents($dir);
// $input="1
// ++X";

$arr = explode(PHP_EOL, $input);

$x = 0;
for($i=1;$i<count($arr);$i++){
  if($arr[$i][1] == '+')
    $x++;
  else
    $x--;
}
echo $x ."\n";

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

$arr = explode(PHP_EOL, $input);

$x = 0;
for($i=1;$i<count($arr);$i++){
  if($arr[$i][1] == '+')
    $x++;
  else
    $x--;
}
echo $x ."\n";

<?php
// http://codeforces.com/problemset/problem/282/A

// Input
// The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
$n = fgets(STDIN);

// The language is that peculiar as it has exactly one variable, called x.
$x = 0;

// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
for ($i=0; $i < $n; $i++)
{
	$operation = rtrim(fgets(STDIN));

	if (false == strpos($operation, '++'))
		$x++;
	else
		$x--;
}

echo $x;

?>

<?php
// http://codeforces.com/problemset/problem/282/A

// Input
// The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
$n = fgets(STDIN);

// The language is that peculiar as it has exactly one variable, called x.
$x = 0;

// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
for ($i=0; $i < $n; $i++)
{
	$operation = rtrim(fgets(STDIN));

	if (false != strpos($operation, '++'))
		$x++;
	else
		$x--;
}

echo $x;

?>

<?php
    $x = trim(fgets(STDIN));
    $ret = 0;

    for ($i=0; $i<$x; $i++)
    {
        $s = trim(fgets(STDIN));
        if (strpos($s, "++")>=0)
            $ret++;
        else
            $ret--;

    }
    echo $ret;
?>

<?php
fscanf(STDIN, "%d", $x);

while (fscanf(STDIN, "%s", $s)) {
    eval(str_replace("X", "\$x", $s) . ";");
}
echo $x;
?>

<?php
$n = (fgets(STDIN));
$result=0;
for ($i=0;$i<$n;$i++)
{
    $line = fgets(STDIN);
    if (strripos($line,"++"))
    {
        $result++;
    }
    elseif (strripos($line,"--"))
    {
        $result--;
    }
}
echo $result;
?>

<?php
$n = (fgets(STDIN));
$summSolution=0;
for ($i=0;$i<$n;$i++)
{
    $peopleVote = explode(" ",fgets(STDIN));
    if (($peopleVote[0]+$peopleVote[1]+$peopleVote[2])>=2)
    {
        $summSolution++;
    }
}
echo $summSolution;
?>

<?php

function getStdIn(bool $asInt = false): array
{
    $stdIn = explode(' ', trim(fgets(STDIN)));

    if ($asInt) {
        foreach ($stdIn as $key => $value) {
            $stdIn[$key] = (int)$value;
        }
    }

    return $stdIn;
}

function stdOut($output)
{
    fwrite(STDOUT, $output);
}

function solve(): void
{
    [$n] = getStdIn(true);
    $x = 0;

    for ($i = 0; $i < $n; $i++) {
        [$operation] = getStdIn();
        var_dump($operation);
        if (strpos($operation, '++') !== false) {
            $x++;
        } elseif (strpos($operation, '--') !== false) {
            $x--;
        }
    }

    stdOut($x);
}

solve();

<?php
$input = trim(fgets(STDIN));
$noOfInputs = (int)$input;
$x = 0;
for($counter = 0 ; $counter < $noOfInputs; $counter++){
    $input = trim(fgets(STDIN));
    if(strpos($input, "--")){
        $x--;
    }else{
        $x++;
    }
}
echo $x;
?>

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

//Get The Number Of Statements.
$n = explode("\n",$input)[0];

//Then Loop Throw The Statements To Apply Them On ( x ).
$x = 0;
for($i = 1;$i <= $n;$i++) {

    $current_statement = explode("\n",$input)[$i];

    if(in_array($current_statement,array("++x","x++"))) {

        $x++;

    }else {

        $x--;

    }

}

//return ( x ).
echo $x;

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

//Get The Number Of Statements.
$n = (int)explode("\n",$input)[0];

//Then Loop Throw The Statements To Apply Them On ( x ).
$int = 0;

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

    $current_statement = (string)explode("\n",$input)[$i + 1];

    $current_statement = trim($current_statement,"\r\n");

    if(in_array($current_statement,array("x++","++x"))) {

        $int++;

    }elseif(in_array($current_statement,array("x--","--x"))) {

        $int--;

    }

}

//return ( x ).
echo $int;

?>

<?php
fscanf(STDIN, '%d\n', $n);
$lines = array();
$x = 0;

for($i = 0; $i < $n; $i++) {	// считываем n строк
	$lines[$i] = fgets(STDIN);
	$lines = explode(' ', $lines[$i]); // теперь $lines - двумерный массив c выражениями
	}

for($i = 0; $i < $n; $i++) {
	// if($lines[$i] == "++X" || "X++") {
	// 	$x = 1;
	// } elseif($lines[$i] == "X--" || "--X") {
	// 	$x = 0;
	// }
	if($lines[$i][2] == "X--" || "--X"){
		$x = 0;
	} else {
		$x = 1;
	}
}

printf($x);

<?php
$a = array();
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
	$a[] = trim(fgets(STDIN));
}
$result = 0;
foreach ($a as $task) {
	if ($task == '++X')
		$result++;
	else
		$result--;
}

fprintf(STDOUT, $result);

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

fprintf(STDOUT, $result);


You have a card deck of $$$n$$$ cards, numbered from top to bottom, i. e. the top card has index $$$1$$$ and bottom card — index $$$n$$$. Each card has its color: the $$$i$$$-th card has color $$$a_i$$$.You should process $$$q$$$ queries. The $$$j$$$-th query is described by integer $$$t_j$$$. For each query you should:   find the highest card in the deck with color $$$t_j$$$, i. e. the card with minimum index;  print the position of the card you found;  take the card and place it on top of the deck.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \le n \le 3 \cdot 10^5$$$; $$$1 \le q \le 3 \cdot 10^5$$$) — the number of cards in the deck and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 50$$$) — the colors of cards. The third line contains $$$q$$$ integers $$$t_1, t_2, \dots, t_q$$$ ($$$1 \le t_j \le 50$$$) — the query colors. It's guaranteed that queries ask only colors that are present in the deck.

Print $$$q$$$ integers — the answers for each query.

NoteDescription of the sample:   the deck is $$$[2, 1, 1, 4, \underline{3}, 3, 1]$$$ and the first card with color $$$t_1 = 3$$$ has position $$$5$$$;  the deck is $$$[3, \underline{2}, 1, 1, 4, 3, 1]$$$ and the first card with color $$$t_2 = 2$$$ has position $$$2$$$;  the deck is $$$[2, 3, \underline{1}, 1, 4, 3, 1]$$$ and the first card with color $$$t_3 = 1$$$ has position $$$3$$$;  the deck is $$$[\underline{1}, 2, 3, 1, 4, 3, 1]$$$ and the first card with color $$$t_4 = 1$$$ has position $$$1$$$;  the deck is $$$[1, 2, 3, 1, \underline{4}, 3, 1]$$$ and the first card with color $$$t_5 = 4$$$ has position $$$5$$$.

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n, $q) = IO::arr();
    $a = IO::arr();
    $t = IO::arr();
    $k = [];
    $res = [];
    foreach ($a as $in => $v) {
        if (!isset($k[$v])) {
            $k[$v] = $in + 1;
        }
    }

    foreach ($t as $v) {
        $ind = $k[$v];
        $res[] = $ind;
        foreach ($k as $cl => &$ix) {
            if ($ix < $ind) {
                $ix+=1;
            }
        }
        $k[$v] = 1;
    }

    IO::line(implode(' ', $res));

}

?>


An array is beautiful if both of the following two conditions meet:  there are at least $$$l_1$$$ and at most $$$r_1$$$ elements in the array equal to its minimum;  there are at least $$$l_2$$$ and at most $$$r_2$$$ elements in the array equal to its maximum. For example, the array $$$[2, 3, 2, 4, 4, 3, 2]$$$ has $$$3$$$ elements equal to its minimum ($$$1$$$-st, $$$3$$$-rd and $$$7$$$-th) and $$$2$$$ elements equal to its maximum ($$$4$$$-th and $$$5$$$-th).Another example: the array $$$[42, 42, 42]$$$ has $$$3$$$ elements equal to its minimum and $$$3$$$ elements equal to its maximum.Your task is to calculate the minimum possible number of elements in a beautiful array.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Each test case consists of one line containing four integers $$$l_1$$$, $$$r_1$$$, $$$l_2$$$ and $$$r_2$$$ ($$$1 \le l_1 \le r_1 \le 50$$$; $$$1 \le l_2 \le r_2 \le 50$$$).

For each test case, print one integer — the minimum possible number of elements in a beautiful array.

<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";

  $t = getT();
//   $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = 0;
      list($l1, $r1, $l2, $r2) = getA();

      if($r1 >= $l2 && $l1 <= $r2) {
          $ans = getMaxValue($l2, $l1);
      } else {
          $ans = $l1 + $l2;
      }

          pr($ans);

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
function getDar($n) {
    $dar = [2];
    for($i=0; $i<$n; $i++) {
        $dar[] = $dar[$i] * 2;
    }
    return $dar;
}
function getDar2($n, $k) {
    if($k == 0) {
        return 1;
    }
    return bcmul($n, getDar2($n, $k-1));
}

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

  function is_prime($n) {
    $d = 2;
        while ($n % $d != 0) {
        	 $d += 1;
        }

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

    function getMaxValueBc($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    function getRotate($a, $s, $e, $ind) {
 		$ar = [];
        for ($i= $s; $i<=$e; $i++) {
        	$ar[$i] = $a[$i];
        	$j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
        	// echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
        	$a[$i] = $j < $i ? $ar[$j] : $a[$j];
        }
        return $a;
    }
    function pr($s) {
        if(is_array($s)) {
            echo implode( ' ', $s), PHP_EOL;
        } else {
            echo $s, PHP_EOL;
        }
    }
    function fab2($n, $a) {
        if($n <= 1) {
            return $a[$n];
        }
       for($i=2; $i<=$n; $i++) {
           $a[$i] = $a[$i-1] + $a[$i-2];
       }

        return $a[$n];
    }

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

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

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

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

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

    return $aResult;

}


You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined . You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it by 1.Output the minimum possible value of error after k1 operations on array A and k2 operations on array B have been performed.

The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line contains n space separated integers b1, b2, ..., bn ( - 106 ≤ bi ≤ 106)— array B.

Output a single integer — the minimum possible value of  after doing exactly k1 operations on array A and exactly k2 operations on array B.

NoteIn the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is now E = (2 - 2)2 + (2 - 2)2 = 0. This is the minimum possible error obtainable.In the third sample case, we can increase the first element of A to 8, using the all of the 5 moves available to us. Also, the first element of B can be reduced to 8 using the 6 of the 7 available moves. Now A = [8, 4] and B = [8, 4]. The error is now E = (8 - 8)2 + (4 - 4)2 = 0, but we are still left with 1 move for array B. Increasing the second element of B to 5 using the left move, we get B = [8, 5] and E = (8 - 8)2 + (4 - 5)2 = 1.


You are given a sequence $$$a=[a_1,a_2,\dots,a_n]$$$ consisting of $$$n$$$ positive integers.Let's call a group of consecutive elements a segment. Each segment is characterized by two indices: the index of its left end and the index of its right end. Denote by $$$a[l,r]$$$ a segment of the sequence $$$a$$$ with the left end in $$$l$$$ and the right end in $$$r$$$, i.e. $$$a[l,r]=[a_l, a_{l+1}, \dots, a_r]$$$.For example, if $$$a=[31,4,15,92,6,5]$$$, then $$$a[2,5]=[4,15,92,6]$$$, $$$a[5,5]=[6]$$$, $$$a[1,6]=[31,4,15,92,6,5]$$$ are segments.We split the given sequence $$$a$$$ into segments so that:   each element is in exactly one segment;  the sums of elements for all segments are equal. For example, if $$$a$$$ = [$$$55,45,30,30,40,100$$$], then such a sequence can be split into three segments: $$$a[1,2]=[55,45]$$$, $$$a[3,5]=[30, 30, 40]$$$, $$$a[6,6]=[100]$$$. Each element belongs to exactly segment, the sum of the elements of each segment is $$$100$$$.Let's define thickness of split as the length of the longest segment. For example, the thickness of the split from the example above is $$$3$$$.Find the minimum thickness among all possible splits of the given sequence of $$$a$$$ into segments in the required way.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Each test case is described by two lines. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the length of the sequence $$$a$$$. The second line of each test case contains exactly $$$n$$$ integers: $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — elements of the sequence $$$a$$$. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2000$$$.

For each test case, output one integer — the minimum possible thickness of a split of the sequence $$$a$$$ into segments. Note that there always exist a split, you can always consider whole sequence as one segment.

NoteThe split in the first test case is explained in the statement, it can be shown that it is optimal.In the second test case, it is possible to split into segments only by leaving a single segment. Then the thickness of this split is equal to the length of the entire sequence, that is, $$$4$$$.In the third test case, the optimal split will be $$$[10, 55], [35, 30], [65]$$$. The thickness of the split equals to $$$2$$$.In the fourth test case possible splits are:  $$$[4] + [1, 1, 1, 1] + [4]$$$;  $$$[4, 1, 1] + [1, 1, 4]$$$.

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $a = IO::getArray();
   $z = false;
   $ans = $n;
   $t = [];
   $tt = 0;
   $tols = 0;
   $e = [];
   $cnt = array_sum($a);
   for($j=0; $j<$n; $j++) {
        $tols = $j+1;
        $tt += $a[$j];
        $t[$j][] = $tt;
        $temp = 0;
        $rr = 0;
     for($i=$j+1; $i<$n; $i++) {
          $rr++;
         $temp += $a[$i];
         if($temp == $tt) {
          //    IO::pr('rr => ' . $rr . ' ' . $tols);
              $tols = $tols > $rr ? $tols : $rr;
            $t[$j][] = $tt;
            $temp = 0;
            $rr = 0;
         }
     }
     if(array_sum($t[$j]) == $cnt) {
         $e[$j] = $tols;
     } else {
          $e[$j] = $n;
     }

   }
   $min = $n;
   foreach($t as $key=>$value) {

        if(count($value) > 1 ) {
            $min = $min > count($value) ? count($value) : $min;
            $ans = $ans > $e[$key] ? $e[$key] : $ans;
        }
   }

   IO::pr($ans);
}

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

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

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$n] = 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<$n;$i++){
    [$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $suma = array_sum($a);
    $f = 0;
    $cnt = 0;
    $min = $m;
    for($j=0;$j<$m-1;$j++){
        $f += $a[$j];
        $cnt++;
        if($suma % $f == 0){
            $max = $cnt;
            //echo ">>>>>>".$max." ".$f.PHP_EOL;
            $s = 0;
            $cnt1 = 0;
            $ok = true;
            for($k=$j+1;$k<$m;$k++){
                $s += $a[$k];
                //echo ">>>>".$s.PHP_EOL;
                $cnt1++;
                if($k==$m-1){
                    if($f == $s){
                        $max = max($max,$cnt1);
                    }else{
                        $ok=false;
                        break;
                    }
                }else{
                    if($f < $s){
                        $ok=false;
                        break;
                    }else if($f == $s){
                        $max = max($max, $cnt1);
                        //echo ">>".$max." ".$cnt.PHP_EOL;
                        $cnt1 = 0;
                        $s = 0;
                    }
                }
            }
            if($ok){
                $min = min($min, $max);
            }
        }
    }
    $ans[] = $min;
}
echo implode(PHP_EOL,$ans);

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $a = IO::getArray();
   $z = false;
   $ans = $n;
   $t = [];
   $tt = 0;
   $tols = 0;
   $e = [];
   for($j=0; $j<$n; $j++) {
        $tols = $j+1;
        $tt += $a[$j];
        $t[$j][] = $tt;
        $temp = 0;
        $rr = 0;
     for($i=$j+1; $i<$n; $i++) {
          $rr++;
         $temp += $a[$i];
         if($temp == $tt) {
          //    IO::pr('rr => ' . $rr . ' ' . $tols);
              $tols = $tols > $rr ? $tols : $rr;
            $t[$j][] = $tt;
            $temp = 0;
            $rr = 0;
         }
     }
     $e[$j] = $tols;
   }
   $min = $n;
   foreach($t as $key=>$value) {

        if(count($value) > 1 ) {
            $min = $min > count($value) ? count($value) : $min;
            $ans = $ans > $e[$key] ? $e[$key] : $ans;
        }
   }

   IO::pr($ans);
}

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

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

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $a = IO::getArray();
   $z = false;
   $ans = $n;
   $t = [];
   $tt = 0;
   for($j=0; $j<$n; $j++) {
        $tt += $a[$j];
        $t[$j][] = $tt;
        $temp = 0;
     for($i=$j+1; $i<$n; $i++) {
         $temp += $a[$i];
         if($temp == $tt) {
            $t[$j][] = $tt;
            $temp = 0;
         }
     }
   }
   $min = $n;
   foreach($t as $key=>$value) {
     //    IO::pr($key . ' ' . count($value));
     //    IO::prArray($value);
        if(count($value) > 1 ) {
            $ans = $ans > count($value) ? count($value) : $ans;
        }
   }

   IO::pr($ans);
}

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

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

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$n] = 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<$n;$i++){
    [$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $suma = array_sum($a);
    $f = 0;
    $cnt = 0;
    $min = $m;
    for($j=0;$j<$m;$j++){
        $f += $a[$j];
        $cnt++;
        if($suma % $f == 0){
            $max = $cnt;
            $s = 0;
            $cnt = 0;
            $ok = true;
            for($k=$j+1;$k<$m;$k++){
                $s += $a[$k];
                //echo ">>>>".$s.PHP_EOL;
                $cnt++;
                if($k==$m-1){
                    if($f == $s){
                        $max = max($max,$cnt);
                    }else{
                        $ok=false;
                        break;
                    }
                }else{
                    if($f < $s){
                        $ok=false;
                        break;
                    }else if($f == $s){
                        $max = max($max, $cnt);
                        //echo ">>".$max." ".$cnt.PHP_EOL;
                        $cnt = 0;
                        $s = 0;
                    }
                }
            }
            if($ok){
                $min = min($min, $max);
            }
        }
    }
    $ans[] = $min;
}
echo implode(PHP_EOL,$ans);


There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, xi is the coordinate of the i-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers.You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time.Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.

The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles.  The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers x1, x2, ..., xn (0 ≤ xi ≤ 109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.

In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.  Print the only integer -1, if the collision of particles doesn't happen.

NoteIn the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.


After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first.Help guys determine the winner photo by the records of likes.

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the total likes to the published photoes.  The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 1 000 000), where ai is the identifier of the photo which got the i-th like.

Print the identifier of the photo which won the elections.

NoteIn the first test sample the photo with id 1 got two likes (first and fifth), photo with id 2 got two likes (third and fourth), and photo with id 3 got one like (second). Thus, the winner is the photo with identifier 2, as it got:  more likes than the photo with id 3;  as many likes as the photo with id 1, but the photo with the identifier 2 got its second like earlier.

#!/usr/bin/php
<?php
trim(fgets(STDIN));
$arr = explode(' ', trim(fgets(STDIN)));
$c = array();
$w = '';
$wc = 0;
foreach ($arr as $ak => $a) {
	if (isset($c[$a])) {
		$c[$a]++;
	} else {
		$c[$a] = 1;
	}
	if ($c[$a] > $wc) {
		$w = $a;
		$wc = $c[$a];
	}
}
echo $w;
exit();

<?php
$num = intval(fgets(STDIN));
$likes = trim(fgets(STDIN));

$likes = explode(" ", $likes);

$max = -1;

for ($i = 0; $i < $num; $i++) {
	$photos[$likes[$i]]++;
	if ($photos[$likes[$i]] > $max) {
		$max = $photos[$likes[$i]];
		$index = $likes[$i];
	}
}

echo $index;

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

$likes = [];
foreach ($a as $i => $id) {
  if (!isset($likes[$id])) {
    $likes[$id] = [0, -1];
  }
  $likes[$id][0]++;
  $likes[$id][1] = $i;
}

uasort($likes, function ($a, $b) {
  if ($a[0] != $b[0]) {
    return $b[0] - $a[0];
  }
  return $a[1] - $b[1];
});

reset($likes);
echo key($likes), "\n";

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$row=fgets($handle);
$row = preg_replace ('/\s+/', ' ',  $row) ;
$row = trim($row);
$input = explode(" ",$row );
$counters=array();
$counter=0;
if ($n>count($input))
$n=count($input);
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}

if($n>0){
echo $input[array_search(max($counters),$counters, true)];
}
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<$n;$i++){
		if($input[$i]==$v&&$i<=$k+1)
			$count++;
	}
	return $count;
}
?>

<?php

$n = trim(fgets(STDIN));
$sArr = trim(fgets(STDIN));
$arr = explode(' ', $sArr);
$arCount = array_count_values($arr);
arsort($arCount);
$e = reset($arCount);
$last = -1;
$asw = 0;
foreach ($arCount as $key=>$value)
{
    if ($value == $e)
    {
        //print_R('key='.$key."\r");
        $cur = array_keys($arr, $key);

        //print_R($cur[count($cur)-1]);
        if (($cur[count($cur)-1] < $last) || $last < 0)
        {
            $last = $cur[count($cur)-1];
            $asw = $key;
        }
    }
    else
        break;
}
echo $asw;

<?

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

$counts = [];
$max    = 0;
$max_id = 0;

foreach ($a as $id) {
    $id = (int) $id;

    $counts[$id]++;

    if ($counts[$id] > $max) {
        $max_id = $id;
        $max    = $counts[$id];
    }
}

echo $max_id;

<?php

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

$photos = [];

for ($i = 0; $i < $n; $i++) {
	$k = $ids[$i];
	if (!isset($photos[$k])) {
		$photos[$k] = [
			'id' => $k,
			'time' => 0,
			'likes' => 0,
		];
	}

	$photos[$k]['time'] = $i;
	$photos[$k]['likes']++;
}

function compare($a, $b) {
	if ($a['likes'] > $b['likes']) {
		return -1;
	} elseif ($a['likes'] < $b['likes']) {
		return 1;
	} elseif ($a['time'] < $b['time']) {
		return -1;
	} elseif ($a['time'] > $b['time']) {
		return 1;
	} else {
		return 0;
	}
}

usort($photos, "compare");

echo $photos[0]['id'];

<?
$stdin = fopen('php://stdin', 'r');
$num = fgets($stdin);
$str = fgets($stdin);
$arr = array();
$t = explode(" ", $str);
$out = -1;
for($i = 0; $i < $num; $i++){
    $m = trim($t[$i]);
    if(array_key_exists($m, $arr)) $arr[$m]++; else $arr[$m] = 1;
    if($arr[$out] < $arr[$m] || $out == -1) $out = $m;
}

$stdout = fopen('php://stdout', 'w');
fwrite($stdout, $out);
fclose($stdout);
?>

<?php
$n = intval(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));
$likes=[];
$last_likes=[];
for ($i=0; $i<$n; $i++){
    $id = $a[$i];
    if(isset($likes[$id])){
        $likes[$id]++;
    }else{
        $likes[$id] = 1;
    }
    $last_likes[$id] = $i;
}
//var_dump($likes, $last_likes);
$max = 0;
$max_id = 0;
$last_like = 10000;
foreach($likes as $id => $count){
    if ($count >= $max && $last_likes[$id] < $last_like || $count > $max ){
        $max = $count;
        $max_id = $id;
        $last_like = $last_likes[$id];
    }
}

echo $max_id."\n";

<?php

function getint()
{
    $result = 0;
    while ($c = fgetc(STDIN)) {
        if (false === strpos(" \t\n\r\0\x0B", $c)) {
            break;
        }
    }

    do {
        if (!is_numeric($c)) {
            break;
        }

        $result = $result * 10 + $c;
    } while (null !== $c = fgetc(STDIN));

    return $result;
}

$map = [];
$maxNumber = 0; $max = 0;
$n = getint();
while ($n--) {
    $number = getint();
    if (!isset($map[$number])) {
        $map[$number] = 0;
    }

    if ($max < $value = ++$map[$number]) {
        $max = $value;
        $maxNumber = $number;
    }
}

echo $maxNumber . PHP_EOL;

<?php
$a = trim(fgets(STDIN));
$l = explode(' ',trim(fgets(STDIN)));
$lengArray = (count($l));
$totalArray = [];
for($i = 0; $i < $lengArray; $i++){
    $id = $l[$i];
    $totalArray[$id]['value'] = $totalArray[$id]['value'] + 1;
    $totalArray[$id]['key'] = $i;
}

function cmp($a, $b)
{
    if ($a['value'] == $b['value']) {
        return $a['key'] > $b['key'];
    }
    return $a['value'] < $b['value'];
}

uasort($totalArray, "cmp");
reset($totalArray);
echo key($totalArray);
?>

<?
fgets(STDIN);
$a = explode(' ', trim(fgets(STDIN)));
foreach($a as $b) $c[$b][] = 1;
foreach($c as $b => $e) $f[$b] = sizeof($c[$b]);
$e = max($f);
foreach($f as $g => $h) if((int)$f[$g] < $e) unset($f[$g]);
$e = null;
foreach($f as $g => $h) $e[$g] = max(array_keys($a, $g));
print trim(array_search(min($e), $e));

<?php

$amount = trim(fgets(STDIN));
$photos = explode(' ', trim(fgets(STDIN)));

$counter = array();
$result = array();

$sort = array();
$sort['index'] = array();
$sort['amount'] = array();

for ($i = 0; $i < $amount; $i++)
{
    $photo = $photos[$i];

    $result[$photo] = array(
        'index'  => $i,
        'amount' => ++$counter[$photo],
        'photo'  => $photo
    );

    $sort['index'][$photo] = $i;
    $sort['amount'][$photo] = $counter[$photo];
}

array_multisort($sort['amount'], SORT_DESC, $sort['index'], SORT_ASC, $result);

$result = reset($result);

echo $result['photo'];

?>

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}
if($n>0){
    print_r($counters);
echo $input[array_search(max($counters),$counters, true)];
}
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<$n;$i++){
		if($input[$i]==$v&&$i<=$k)
			$count++;
	}
	return $count;
}
?>

<?
$handle = fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($i,$input[$i],$input);
	$counter++;
}
echo $input[array_search(max($counters),$counters)];
function bestqualityfunctiononphp($k,$v,$input){
	for($i=0; $i<=$k;$i++){
		if($input[$i]==$v&&$i<=$k)
			$count++;
	}
	return $count;
}
?>

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}
echo $input[array_search(max($counters),$counters)];
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<=$n;$i++){
		if($input[$i]==$v&&$i<=$k+1)
			$count++;
	}
	return $count;
}
?>

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}
if($n>0){
echo $input[array_search(max($counters),$counters, true)];
}
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<$n;$i++){
		if($input[$i]==$v&&$i<=$k)
			$count++;
	}
	return $count;
}
?>

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}
if($n>0){
echo $input[array_search(max($counters),$counters, true)];
}
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<$n;$i++){
		if($input[$i]==$v&&$i<=$k+1)
			$count++;
	}
	return $count;
}
?>

<?
$handle = @fopen("php://stdin", "r");
$n=fgets($handle);
$input = explode(" ", fgets($handle));
$counters=array();
$counter=0;
for($i=0; $i<$n;$i++){
	$counters[$counter]=bestqualityfunctiononphp($n,$i,$input[$i],$input);
	$counter++;
}
print_r($counters);
echo $input[array_search(max($counters),$counters)];
function bestqualityfunctiononphp($n,$k,$v,$input){
	for($i=0; $i<=$n;$i++){
		if($input[$i]==$v&&$i<=$k+1)
			$count++;
	}
	return $count;
}
?>

<?
$stdin = fopen('php://stdin', 'r');
$num = fgets($stdin);
$str = fgets($stdin);
$arr = array();
$t = explode(" ", $str);
$out = -1;
for($i = 0; $i < $num; $i++){
    if($arr[$t[$i]]) $arr[$t[$i]]++; else $arr[$t[$i]] = 1;
    if($arr[$out] < $arr[$t[$i]] || $out == -1) $out = $t[$i];
}

$stdout = fopen('php://stdout', 'w');
fwrite($stdout, $out);
fclose($stdout);
?>

<?php
$n = intval(fgets(STDIN));
$a = explode(' ', fgets(STDIN));
$likes=[];
$last_likes=[];
for ($i=0; $i<$n; $i++){
    $id = $a[$i];
    if(isset($likes[$id])){
        $likes[$id]++;
    }else{
        $likes[$id] = 1;
    }
    $last_likes[$id] = $i;
}
$max = 0;
$max_id = 0;
$last_like = 10000;
foreach($likes as $id => $count){
    if ($count >= $max && $last_likes[$id] < $last_like){
        $max = $count;
        $max_id = $id;
        $last_like = $last_likes[$id];
    }
}

echo $max_id."\n";

<?php
$n = intval(fgets(STDIN));
$a = explode(' ', trim(fgets(STDIN)));
$likes=[];
$last_likes=[];
for ($i=0; $i<$n; $i++){
    $id = $a[$i];
    if(isset($likes[$id])){
        $likes[$id]++;
    }else{
        $likes[$id] = 1;
    }
    $last_likes[$id] = $i;
}
//var_dump($likes, $last_likes);
$max = 0;
$max_id = 0;
$last_like = 10000;
foreach($likes as $id => $count){
    if ($count >= $max && $last_likes[$id] < $last_like){
        $max = $count;
        $max_id = $id;
        $last_like = $last_likes[$id];
    }
}

echo $max_id."\n";

<?php
$n = intval(fgets(STDIN));
$a = explode(' ', fgets(STDIN));
$likes=[];
for ($i=0; $i<$n;$i++){
    $id = $a[$i];
    if(isset($likes[$id])){
        $likes[$id]++;
    }else{
        $likes[$id] = 1;
    }
}
$max = 0;
$max_id = 0;
foreach($likes as $id => $count){
    if ($count > $max){
        $max = $count;
        $max_id = $id;
    }
}

echo $id;

<?php
$n = intval(fgets(STDIN));
$a = explode(' ', fgets(STDIN));
$likes=[];
for ($i=0; $i<$n;$i++){
    $id = $a[$i];
    if(isset($likes[$id])){
        $likes[$id]++;
    }else{
        $likes[$id] = 1;
    }
}
$max = 0;
$max_id = 0;
foreach($likes as $id => $count){
    if ($count > $max){
        $max = $count;
        $max_id = $id;
    }
}

echo $max_id;

<?php

$map = [];
fscanf(STDIN, '%d', $n);

$max = 0;
$maxNumber = 0;

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

foreach ($input as $number) {
    if (!isset($map[$number])) {
        $map[$number] = 0;
    }

    if ($max < $value = ++$map[$number]) {
        $max = $value;
        $maxNumber = $number;
    }
}

echo $maxNumber . PHP_EOL;

<?
fgets(STDIN);
$a = explode(' ', fgets(STDIN));
foreach($a as $b) $c[$b][] = 1;
foreach($c as $b => $e) $f[$b] = sizeof($c[$b]);
$e = max($f);
foreach($f as $g => $h) if($f[$g] < $e) unset($f[$g]);
$e = null;
foreach($f as $g => $h) $e[$g] = max(array_keys($a, $g));
print array_search(min($e), $e);


Polycarp has an array $$$a$$$ consisting of $$$n$$$ integers.He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains $$$n-1$$$ elements). For each of the next moves he chooses any element with the only restriction: its parity should differ from the parity of the element deleted on the previous move. In other words, he alternates parities (even-odd-even-odd-... or odd-even-odd-even-...) of the removed elements. Polycarp stops if he can't make a move.Formally:   If it is the first move, he chooses any element and deletes it;  If it is the second or any next move:   if the last deleted element was odd, Polycarp chooses any even element and deletes it;  if the last deleted element was even, Polycarp chooses any odd element and deletes it.   If after some move Polycarp cannot make a move, the game ends. Polycarp's goal is to minimize the sum of non-deleted elements of the array after end of the game. If Polycarp can delete the whole array, then the sum of non-deleted elements is zero.Help Polycarp find this value.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the number of elements of $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^6$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the minimum possible sum of non-deleted elements of the array after end of the game.

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

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

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

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

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

<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = 0;
$d = 0;
$e = array();
$f = array();
for($x = 0; $x < $a; $x++)
{
     if($b[$x] % 2 == 0)
     {
          $c++;
          $e[count($e)] = $b[$x];
     }
     else
     {
          $d++;
          $f[count($f)] = $b[$x];
     }
}
if($a == 2000)
{
     print $c . " " . $d . "\n";
}
if($c < $d)
{
     $g = array_sum($e) + array_sum(array_splice($f, 0, $c + 1));
}
else
{
     $g = array_sum($f) + array_sum(array_splice($e, 0, $d + 1));
}
print array_sum($b) - $g;
?>


Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi.The way to split up game pieces is split into several steps:  First, Alice will split the pieces into two different groups A and B. This can be seen as writing the assignment of teams of a piece in an n character string, where each character is A or B.  Bob will then choose an arbitrary prefix or suffix of the string, and flip each character in that suffix (i.e. change A to B and B to A). He can do this step at most once.  Alice will get all the pieces marked A and Bob will get all the pieces marked B. The strength of a player is then the sum of strengths of the pieces in the group.Given Alice's initial split into two teams, help Bob determine an optimal strategy. Return the maximum strength he can achieve.

The first line contains integer n (1 ≤ n ≤ 5·105) — the number of game pieces. The second line contains n integers pi (1 ≤ pi ≤ 109) — the strength of the i-th piece. The third line contains n characters A or B — the assignment of teams after the first step (after Alice's step).

Print the only integer a — the maximum strength Bob can achieve.

NoteIn the first sample Bob should flip the suffix of length one.In the second sample Bob should flip the prefix or the suffix (here it is the same) of length 5.In the third sample Bob should do nothing.


Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all.  The park can be represented as a rectangular n × m field. The park has k spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time.Om Nom isn't yet sure where to start his walk from but he definitely wants:  to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders);  to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries.Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell.

The first line contains three integers n, m, k (2 ≤ n, m ≤ 2000; 0 ≤ k ≤ m(n - 1)).  Each of the next n lines contains m characters — the description of the park. The characters in the i-th line describe the i-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down).  It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly k spiders.

Print m integers: the j-th integer must show the number of spiders Om Nom will see if he starts his walk from the j-th cell of the first row. The cells in any row of the field are numbered from left to right.

NoteConsider the first sample. The notes below show how the spider arrangement changes on the field over time:...        ...        ..U       ...R.L   ->   .*U   ->   L.R   ->  ...R.U        .R.        ..R       ...Character "*" represents a cell that contains two spiders at the same time.  If Om Nom starts from the first cell of the first row, he won't see any spiders.  If he starts from the second cell, he will see two spiders at time 1.  If he starts from the third cell, he will see two spiders: one at time 1, the other one at time 2.

<?php

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

$parkHeight = $line[0];
$parkWidth = $line[1];
$spiderNum = $line[2];

$result = array_fill(0, $parkWidth, 0);

for($y = 0; $y < $parkHeight; $y++){
    $line = trim(fgets(STDIN));
    for($x = 0; $x < $parkWidth; $x++){
        if($line[$x] == "R"){
            $result[$x + $y]++;
        }
        if($line[$x] == "L"){
            $result[$x - $y]++;
        }
        if($line[$x] == "U"){
            if($y%2 == 0){
                $result[$x]++;
            }
        }
    }
}

for($x = 0; $x < $parkWidth; $x++){
    echo $result[$x] . " ";
}
?>

<?php

$input = STDIN;
#$input = fopen('b_input2.txt', 'r');

fscanf($input, "%d %d %d\n", $rows, $cols, $spiders_num);

$seen = array_pad(array(), $cols, 0);
for ($row = 0; $row < $rows; $row++) {
    $line = trim(fgets($input));
    $line = str_split($line);

    foreach ($line as $col => $direction) {
        if ($direction == '.' || $direction == 'D') {
            continue;
        }

        switch ($direction)
        {
        case 'U':
            if ($row % 2 == 0) {
                $seen[$col]++;
            }
            break;
        case 'L':
            $k = $col - $row;
            if ($k >= 0) {
                $seen[$k]++;
            }
            break;
        case 'R':
            $k = $col + $row;
            if ($k < $cols) {
                $seen[$k]++;
            }
            break;
        default:
            break;
        }
    }
}

echo join(' ', $seen);

<?php

$input = STDIN;
#$input = fopen('b_input2.txt', 'r');

fscanf($input, "%d %d %d\n", $rows, $cols, $spiders_num);

$spiders_U = $spiders_L = $spiders_R = array();
for ($row = 0; $row < $rows; $row++) {
    $line = trim(fgets($input));
    $line = str_split($line);

    foreach ($line as $col => $direction) {
        if ($direction == '.') {
            continue;
        }

        switch ($direction)
        {
        case 'U':
            $spiders_U[$col][] = $row;
            break;
        case 'L':
            $spiders_L[$row][] = $col;
            break;
        case 'R':
            $spiders_R[$row][] = $col;
            break;
        }
    }
}

$seen = array_pad(array(), $cols, 0);
for ($row = 1; $row < $rows; $row++) {
    calculate_state($row, $seen);
}

foreach ($GLOBALS['spiders_U'] as $col => &$spiders) {
    foreach ($spiders as $row) {
        if ($row > 1) {
            $seen[$col]++;
        }
    }
}

echo join(' ', $seen);

function calculate_state($min_row, &$seen) {
    foreach ($GLOBALS['spiders_R'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_R'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]++;

            if ($spiders[$k] >= count($seen)) {
                unset($spiders[$k]);
                continue;
            }

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }

    foreach ($GLOBALS['spiders_L'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_L'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]--;

            if ($spiders[$k] < 0) {
                unset($spiders[$k]);
                continue;
            }

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }
}

<?php

$input = STDIN;
#$input = fopen('b_input3.txt', 'r');

fscanf($input, "%d %d %d\n", $rows, $cols, $spiders_num);

$spiders_U = $spiders_L = $spiders_R = array();
for ($row = 0; $row < $rows; $row++) {
    $line = trim(fgets($input));
    $line = str_split($line);

    foreach ($line as $col => $direction) {
        if ($direction == '.') {
            continue;
        }

        switch ($direction)
        {
        case 'U':
            $spiders_U[$col][] = $row;
            break;
        case 'L':
            $spiders_L[$row][] = $col;
            break;
        case 'R':
            $spiders_R[$row][] = $col;
            break;
        }
    }
}

$seen = array_pad(array(), $cols, 0);
for ($row = 1; $row < $rows; $row++) {
    calculate_state($row, $seen);
}

foreach ($GLOBALS['spiders_U'] as $col => &$spiders) {
    $seen[$col] += count($spiders);
}

echo join(' ', $seen);

function calculate_state($min_row, &$seen) {
    foreach ($GLOBALS['spiders_R'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_R'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]++;

            if ($spiders[$k] >= count($seen)) {
                unset($spiders[$k]);
                continue;
            }

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }

    foreach ($GLOBALS['spiders_L'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_L'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]--;

            if ($spiders[$k] < 0) {
                unset($spiders[$k]);
                continue;
            }

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }
}

<?php

$input = STDIN;
#$input = fopen('b_input2.txt', 'r');

fscanf($input, "%d %d %d\n", $rows, $cols, $spiders_num);

$spiders_U = $spiders_D = $spiders_L = $spiders_R = array();
for ($row = 0; $row < $rows; $row++) {
    $line = trim(fgets($input));
    $line = str_split($line);

    foreach ($line as $col => $direction) {
        if ($direction == '.') {
            continue;
        }

        switch ($direction)
        {
        case 'U':
            $spiders_U[$col][] = $row;
            break;
        case 'D':
            $spiders_D[$col][] = $row;
            break;
        case 'L':
            $spiders_L[$row][] = $col;
            break;
        case 'R':
            $spiders_R[$row][] = $col;
            break;
        }
    }
}

$seen = array_pad(array(), $cols, 0);
for ($row = 1; $row < $rows; $row++) {
    $timer = 0;
    calculate_state($row, $seen);
//    for ($col = 0; $col < $cols; $col++) {
//        $seen[$col] += find_spiders($row, $col);
//    }

    $timer++;
}

echo join(' ', $seen);

function calculate_state($min_row, &$seen) {
    foreach ($GLOBALS['spiders_U'] as $col => &$spiders) {
        foreach ($spiders as $k => $spider) {
            $spiders[$k]--;

            if ($spiders[$k] < $min_row) {
                unset($spiders[$k]);
            } elseif ($spiders[$k] == $min_row) {
                $seen[$col]++;
            }
        }
    }

    foreach ($GLOBALS['spiders_D'] as $col => &$spiders) {
        foreach ($spiders as $k => $spider) {
            $spiders[$k]++;

            if ($spiders[$k] < $min_row) {
                unset($spiders[$k]);
            } elseif ($spiders[$k] == $min_row) {
                $seen[$col]++;
            }
        }
    }

    foreach ($GLOBALS['spiders_R'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_R'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]++;

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }

    foreach ($GLOBALS['spiders_L'] as $row => &$spiders) {
        if ($row < $min_row) {
            unset($GLOBALS['spiders_L'][$row]);
            continue;
        }

        foreach ($spiders as $k => $spider) {
            $spiders[$k]--;

            if ($row == $min_row) {
                $seen[ $spiders[$k] ]++;
            }
        }
    }
}

function find_spiders($row, $col) {
    $spiders_U = $GLOBALS['spiders_U'];
    $spiders_D = $GLOBALS['spiders_D'];
    $spiders_R = $GLOBALS['spiders_R'];
    $spiders_L = $GLOBALS['spiders_L'];

    $num = 0;
    if (isset($spiders_U[$col])) {
        foreach ($spiders_U[$col] as $current_row) {
            if ($current_row == $row) {
                $num++;
            }
        }
    }

    if (isset($spiders_D[$col])) {
        foreach ($spiders_D[$col] as $current_row) {
            if ($current_row == $row) {
                $num++;
            }
        }
    }

    if (isset($spiders_R[$row])) {
        foreach ($spiders_R[$row] as $current_col) {
            if ($current_col == $col) {
                $num++;
            }
        }
    }

    if (isset($spiders_L[$row])) {
        foreach ($spiders_L[$row] as $current_col) {
            if ($current_col == $col) {
                $num++;
            }
        }
    }

    return $num;
}


You are given $$$q$$$ queries in the following form:Given three integers $$$l_i$$$, $$$r_i$$$ and $$$d_i$$$, find minimum positive integer $$$x_i$$$ such that it is divisible by $$$d_i$$$ and it does not belong to the segment $$$[l_i, r_i]$$$.Can you answer all the queries?Recall that a number $$$x$$$ belongs to segment $$$[l, r]$$$ if $$$l \le x \le r$$$.

The first line contains one integer $$$q$$$ ($$$1 \le q \le 500$$$) — the number of queries. Then $$$q$$$ lines follow, each containing a query given in the format $$$l_i$$$ $$$r_i$$$ $$$d_i$$$ ($$$1 \le l_i \le r_i \le 10^9$$$, $$$1 \le d_i \le 10^9$$$). $$$l_i$$$, $$$r_i$$$ and $$$d_i$$$ are integers.

For each query print one integer: the answer to this query.

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

for ($i = 1; $i <= $iCount; $i++) {
    list($a1, $a2, $a3) = explode(' ', trim(fgets(STDIN)));

    if($a3 < $a1 || $a3 > $a2) {
        echo $a3 . "\n";
    } else {
         $b = floor( $a2 / $a3 ) + 1;
         echo ($a3 * $b)  . "\n";
    }
}

<?php

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

$n = rtrim(fgets($in));

while($n--){
    $line = explode(" ", rtrim(fgets($in)));
    $l = $line[0];
    $r = $line[1];
    $d = $line[2];

    if ($d < $l) {
        echo $d . "\n";
        continue;
    }

    echo $r - $r % $d + $d . "\n";

}
function what($x){fprintf(STDERR, $x . "\n");}
?>

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

for ($i = 1; $i <= $iCount; $i++) {
    list($a1, $a2, $a3) = explode(' ', trim(fgets(STDIN)));

    if($a3 < $a1 || $a3 > $a2) {
        echo $a3;
    } else {
         $b = round( $a2 / $a3 ) + 1;
         echo $a3 * $b;
    }
}

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

for ($i = 1; $i <= $iCount; $i++) {
    list($a1, $a2, $a3) = explode(' ', trim(fgets(STDIN)));

    if($a3 < $a1 || $a3 > $a2) {
        echo $a3 . "\n";
    } else {
         $b = round( $a2 / $a3 ) + 1;
         echo ($a3 * $b)  . "\n";
    }
}

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

for ($i = 1; $i <= $iCount; $i++) {
    list($a1, $a2, $a3) = explode(' ', trim(fgets(STDIN)));

    if($a3 < $a1 || $a3 > $a2) {
        echo $a3;
    } else {
         $b = floor( $a2 / $a3 ) + 1;
         echo $a3 * $b;
    }
}

<?php

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

$n = rtrim(fgets($in));

while($n--){
    $line = explode(" ", rtrim(fgets($in)));
    $l = $line[0];
    $r = $line[1];
    $d = $line[2];

    if ($d < $l) {
        echo $d . "\n";
        continue;
    }

    echo $r - $r % $d + $d . "\n";

}
function what($x){fprintf(STDERR, $x . "\n");}
?>


Bob watches TV every day. He always sets the volume of his TV to $$$b$$$. However, today he is angry to find out someone has changed the volume to $$$a$$$. Of course, Bob has a remote control that can change the volume.There are six buttons ($$$-5, -2, -1, +1, +2, +5$$$) on the control, which in one press can either increase or decrease the current volume by $$$1$$$, $$$2$$$, or $$$5$$$. The volume can be arbitrarily large, but can never be negative. In other words, Bob cannot press the button if it causes the volume to be lower than $$$0$$$.As Bob is so angry, he wants to change the volume to $$$b$$$ using as few button presses as possible. However, he forgets how to do such simple calculations, so he asks you for help. Write a program that given $$$a$$$ and $$$b$$$, finds the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 1\,000$$$). Then the descriptions of the test cases follow. Each test case consists of one line containing two integers $$$a$$$ and $$$b$$$ ($$$0 \le a, b \le 10^{9}$$$) — the current volume and Bob's desired volume, respectively.

For each test case, output a single integer — the minimum number of presses to change the TV volume from $$$a$$$ to $$$b$$$. If Bob does not need to change the volume (i.e. $$$a=b$$$), then print $$$0$$$.

NoteIn the first example, Bob can press the $$$-2$$$ button twice to reach $$$0$$$. Note that Bob can not press $$$-5$$$ when the volume is $$$4$$$ since it will make the volume negative. In the second example, one of the optimal ways for Bob is to press the $$$+5$$$ twice, then press $$$-1$$$ once.In the last example, Bob can press the $$$+5$$$ once, then press $$$+1$$$.

<?php
$n = intval(fgets(STDIN));
$i = 0;
while($i < $n)
{
    $volumes = array_map("toint", explode(" ", fgets(STDIN)));
    $current = $volumes[0];
    $necessary = $volumes[1];
    $count = intdiv(abs($current - $necessary), 5);
    $z = 1;
    if($current > $necessary) $z = -1;
    $current = $current + 5 * $count * $z;
    while($current != $necessary)
    {
        $current = getCloser($current, $necessary);
        $count++;
    }
    echo $count."\n";

    $i++;
}

function getCloser($current, $necessary)
{
    $availiable = array(-5, -2, -1, 1, 2, 5);
    $diff = $current - $necessary;
    if(array_search($diff, $availiable))
        return $necessary;

    $minDiff = abs($diff);
    $minDiffIndex = 0;
    foreach ($availiable as $key => $value) {
        if(abs($diff + $value) < $minDiff && $current + $value >= 0)
        {
            $minDiffIndex = $key;
            $minDiff = abs($diff + $value);
        }

    }
    return $current + $availiable[$minDiffIndex];
}
function toint($num)
{
    return intval($num);
}
?>

<?php

$t = (int)fgets(STDIN);

while ($t--) {
    $input = explode(" ", fgets(STDIN));
    $a = (int)$input[0];
    $b = (int)$input[1];
    $diff = abs($a - $b);
    $q = intdiv($diff, 5);
    $rem = $diff % 5;
    print($q + (($rem > 2) ? (2) : ($rem ? 1 : 0)));
    print("\n");
}

<?php
    $j = trim(fgets(STDIN));
    for ($i = 0; $i < $j; $i++) {
        list($a, $b) = explode(" ", trim(fgets(STDIN)));
        if ($a === $b) {
            $n = 0;
        } elseif ($a > $b) {
            $n = $a - $b;
        } else {
            $n = $b - $a;
        }
        echo process($n) . "\n";
    }

    function process($n, $s = 0) {
        if ($n == 0) {
            return $s;
        }
        if ($n >= 5) {
            $s += floor($n/5);
            $k = $n%5;
            if ($k != 0) {
                return process($k, $s);
            } else {
                return $s;
            }
        } elseif($n >= 2) {
            $s += floor($n/2);
            $k = $n%2;
            if ($k != 0) {
                return process($k, $s);
            } else {
                return $s;
            }
        } else {
            return $s + 1;
        }
    }
?>

<?php

$t = (int)fgets(STDIN);

while ($t--) {
    $input = explode(" ", fgets(STDIN));
    $a = (int)$input[0];
    $b = (int)$input[1];
    $diff = abs($a - $b);
    $q = intdiv($diff, 5);
    $rem = $diff % 5;
    print($q + (($rem > 2) ? (2) : ($rem ? 1 : 0)));
}


You are given a bracket sequence $$$s$$$ of length $$$n$$$, where $$$n$$$ is even (divisible by two). The string $$$s$$$ consists of $$$\frac{n}{2}$$$ opening brackets '(' and $$$\frac{n}{2}$$$ closing brackets ')'.In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end of the string (i.e. you choose some index $$$i$$$, remove the $$$i$$$-th character of $$$s$$$ and insert it before or after all remaining characters of $$$s$$$).Your task is to find the minimum number of moves required to obtain regular bracket sequence from $$$s$$$. It can be proved that the answer always exists under the given constraints.Recall what the regular bracket sequence is:  "()" is regular bracket sequence;  if $$$s$$$ is regular bracket sequence then "(" + $$$s$$$ + ")" is regular bracket sequence;  if $$$s$$$ and $$$t$$$ are regular bracket sequences then $$$s$$$ + $$$t$$$ is regular bracket sequence. For example, "()()", "(())()", "(())" and "()" are regular bracket sequences, but ")(", "()(" and ")))" are not.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of the test case contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the length of $$$s$$$. It is guaranteed that $$$n$$$ is even. The second line of the test case containg the string $$$s$$$ consisting of $$$\frac{n}{2}$$$ opening and $$$\frac{n}{2}$$$ closing brackets.

For each test case, print the answer — the minimum number of moves required to obtain regular bracket sequence from $$$s$$$. It can be proved that the answer always exists under the given constraints.

NoteIn the first test case of the example, it is sufficient to move the first bracket to the end of the string.In the third test case of the example, it is sufficient to move the last bracket to the beginning of the string.In the fourth test case of the example, we can choose last three openning brackets, move them to the beginning of the string and obtain "((()))(())".

<?php
$t=readline();
while($t--){
    $n=readline();
    $s=readline();
    // while(preg_replace("\(\)","",$s)!=$s);
    while(preg_match("(\(\))",$s)){
     $s=preg_replace("(\(\))","",$s);
    }
    // echo $s;
    echo strlen($s)/2;
    echo"\n";
}

?>

<?php
$tc=readline();
while($tc--)
{
  fscanf(STDIN,"%d",$len);
  $str=trim(fgets(STDIN));
  $sum=0;
  for ($i=0; $i <$len ; $i++)
   {
	  	  if($str[$i]=='(')
	  	  	$sum++;
	  	  else
	  	  {
	  	  	if ($sum>0&&$str[$i]==')')

	  	  	$sum--;
	  	  }

   }
   echo "$sum\n";
}

<?php
$tc=readline();
while($tc--)
{
  fscanf(STDIN,"%d",$len);
  $str=trim(fgets(STDIN));
  $sum=0;
  for ($i=0; $i <$len ; $i++)
   {
	  	  if($str[$i]=='(')
	  	  	$sum++;
	  	  elseif ($sum>0&&$str[$i]==')')
	  	  $sum--;

   }
   echo "$sum\n";
}

<?php
$tc=readline();
while($tc--)
{
  $len=readline();
  $str=trim(fgets(STDIN));
  $sum=0;
  for ($i=0; $i <$len ; $i++)
   {
	  	  if($str[$i]=='(')
	  	  	$sum++;
	  	  else
	  	  {
	  	  	if ($sum>0&&$str[$i]==')')

	  	  	$sum--;
	  	  }

   }
   echo "$sum\n";
}

<?php
$tc=readline();
while($tc--)
{
  $len=readline();
  $str=trim(fgets(STDIN));
  $sum=0;
  for ($i=0; $i <$len ; $i++)
   {
	  	  if($str[$i]=='(')
	  	  	$sum++;
	  	  elseif ($sum>0&&$str[$i]==')')
	  	  {
	  	  	$sum--;
	  	  }

   }
   echo "$sum\n";
}

<?php
$tc=readline();
while($tc--)
{
  $len=readline();
  $str=trim(fgets(STDIN));
  $sum=0;
  for ($i=0; $i <$len ; $i++)
   {
	  	  if($str[$i]=='(')
	  	  	$sum++;
	  	  elseif ($sum>0&&$str[$i]==')')
	  	  {
	  	  	$sum--;
	  	  }

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


A well-known art union called "Kalevich is Alive!" manufactures objects d'art (pictures). The union consists of n painters who decided to organize their work as follows.Each painter uses only the color that was assigned to him. The colors are distinct for all painters. Let's assume that the first painter uses color 1, the second one uses color 2, and so on. Each picture will contain all these n colors. Adding the j-th color to the i-th picture takes the j-th painter tij units of time.Order is important everywhere, so the painters' work is ordered by the following rules:  Each picture is first painted by the first painter, then by the second one, and so on. That is, after the j-th painter finishes working on the picture, it must go to the (j + 1)-th painter (if j < n);  each painter works on the pictures in some order: first, he paints the first picture, then he paints the second picture and so on;  each painter can simultaneously work on at most one picture. However, the painters don't need any time to have a rest;  as soon as the j-th painter finishes his part of working on the picture, the picture immediately becomes available to the next painter. Given that the painters start working at time 0, find for each picture the time when it is ready for sale.

The first line of the input contains integers m, n (1 ≤ m ≤ 50000, 1 ≤ n ≤ 5), where m is the number of pictures and n is the number of painters. Then follow the descriptions of the pictures, one per line. Each line contains n integers ti1, ti2, ..., tin (1 ≤ tij ≤ 1000), where tij is the time the j-th painter needs to work on the i-th picture.

Print the sequence of m integers r1, r2, ..., rm, where ri is the moment when the n-th painter stopped working on the i-th picture.