One night, Mark realized that there is an essay due tomorrow. He hasn't written anything yet, so Mark decided to randomly copy-paste substrings from the prompt to make the essay.More formally, the prompt is a string $$$s$$$ of initial length $$$n$$$. Mark will perform the copy-pasting operation $$$c$$$ times. Each operation is described by two integers $$$l$$$ and $$$r$$$, which means that Mark will append letters $$$s_l s_{l+1} \ldots s_r$$$ to the end of string $$$s$$$. Note that the length of $$$s$$$ increases after this operation.Of course, Mark needs to be able to see what has been written. After copying, Mark will ask $$$q$$$ queries: given an integer $$$k$$$, determine the $$$k$$$-th letter of the final string $$$s$$$.

The first line contains a single integer $$$t$$$ ($$$1\leq t\leq 1000$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$c$$$, and $$$q$$$ ($$$1\leq n\leq 2\cdot 10^5$$$, $$$1\leq c\leq 40$$$, and $$$1\leq q\leq 10^4$$$) — the length of the initial string $$$s$$$, the number of copy-pasting operations, and the number of queries, respectively. The second line of each test case contains a single string $$$s$$$ of length $$$n$$$. It is guaranteed that $$$s$$$ only contains lowercase English letters. The following $$$c$$$ lines describe the copy-pasting operation. Each line contains two integers $$$l$$$ and $$$r$$$ ($$$1\leq l\leq r\leq 10^{18}$$$). It is also guaranteed that $$$r$$$ does not exceed the current length of $$$s$$$. The last $$$q$$$ lines of each test case describe the queries. Each line contains a single integer $$$k$$$ ($$$1\leq k\leq 10^{18}$$$). It is also guaranteed that $$$k$$$ does not exceed the final length of $$$s$$$. It is guaranteed that the sum of $$$n$$$ and $$$q$$$ across all test cases does not exceed $$$2\cdot 10^5$$$ and $$$10^4$$$, respectively.

For each query, print the $$$k$$$-th letter of the final string $$$s$$$.

NoteIn the first test case, the copy-paste process is as follows.   The first step is pasting string $$$\texttt{mark}$$$ at the end, yielding the string $$$\texttt{mark}\color{red}{\texttt{mark}}$$$.  The second step is pasting string $$$\texttt{mar}$$$ at the end, yielding the string $$$\texttt{markmark}\color{red}{\texttt{mar}}$$$.  The third step is pasting string $$$\texttt{rkmark}$$$ at the end, yielding the string $$$\texttt{markmarkmar}\color{red}{\texttt{rkmark}}$$$. In the second test case, the copy-paste process is as follows.   The first step is pasting string $$$\texttt{re}$$$ at the end, yielding the string $$$\texttt{creamii}\color{red}{\texttt{re}}$$$.  The second step is pasting string $$$\texttt{ea}$$$ at the end, yielding the string $$$\texttt{creamiire}\color{red}{\texttt{ea}}$$$.  The third step is pasting string $$$\texttt{reamiire}$$$ at the end, yielding the string $$$\texttt{creamiireea}\color{red}{\texttt{reamiire}}$$$.

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
//101
//101
//001
function solve()
{
    list($n, $c, $q) = IO::getArray();
    $s = IO::get();
    $a = [];

    $ans = 0;

    $ll = [];
    $rr = [];
    $len = [];
    $len[] = $n;
     for($i=0; $i<$c; $i++) {
          list($l, $r) = IO::getArray();
        $ll[$i] = $l;
        $rr[$i] = $r;
         $len[] = $len[$i] + $r-$l+1;
     }

     for($i=0; $i<$q; $i++) {
          $k = IO::get();
          for ($j = $c - 1; $j >= 0; $j--) {
             if ($k > $len[$j]) {
               $k = $ll[$j] + ($k - $len[$j] - 1);
               if($k <= $n) {
                    break;
               }
             }
          }
          IO::pr($s[$k-1]);
     }

//    IO::pr($ans);

}

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

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

<?php

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

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

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

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

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

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

$t = readInt() ;
$ans = [] ;
while($t--) {
	[$n,$c,$k] = readIntArray() ;
	$st = read() ;
	$dic = array([1,$n,0]) ;
	for ($i=0; $i < $c; $i++) {
		[$l,$r] = readIntArray() ;
		$dic[] = array($dic[$i][1]+1,$dic[$i][1]+($r-$l+1),$dic[$i][1]+1-$l);
	}
	// printLine($dic);
	while($k--){
		$srs = readInt() ;
		for($i=$c;$i>-1;$i--) {
			if($srs >= $dic[$i][0]) {
				$srs -= $dic[$i][2] ;
			}
		}
		$ans[] = ($st[$srs-1]) ;
	}
}
printLine(implode("\n",$ans));


The map of the capital of Berland can be viewed on the infinite coordinate plane. Each point with integer coordinates contains a building, and there are streets connecting every building to four neighbouring buildings. All streets are parallel to the coordinate axes.The main school of the capital is located in $$$(s_x, s_y)$$$. There are $$$n$$$ students attending this school, the $$$i$$$-th of them lives in the house located in $$$(x_i, y_i)$$$. It is possible that some students live in the same house, but no student lives in $$$(s_x, s_y)$$$.After classes end, each student walks from the school to his house along one of the shortest paths. So the distance the $$$i$$$-th student goes from the school to his house is $$$|s_x - x_i| + |s_y - y_i|$$$.The Provision Department of Berland has decided to open a shawarma tent somewhere in the capital (at some point with integer coordinates). It is considered that the $$$i$$$-th student will buy a shawarma if at least one of the shortest paths from the school to the $$$i$$$-th student's house goes through the point where the shawarma tent is located. It is forbidden to place the shawarma tent at the point where the school is located, but the coordinates of the shawarma tent may coincide with the coordinates of the house of some student (or even multiple students).You want to find the maximum possible number of students buying shawarma and the optimal location for the tent itself.

The first line contains three integers $$$n$$$, $$$s_x$$$, $$$s_y$$$ ($$$1 \le n \le 200\,000$$$, $$$0 \le s_x, s_y \le 10^{9}$$$) — the number of students and the coordinates of the school, respectively. Then $$$n$$$ lines follow. The $$$i$$$-th of them contains two integers $$$x_i$$$, $$$y_i$$$ ($$$0 \le x_i, y_i \le 10^{9}$$$) — the location of the house where the $$$i$$$-th student lives. Some locations of houses may coincide, but no student lives in the same location where the school is situated.

The output should consist of two lines. The first of them should contain one integer $$$c$$$ — the maximum number of students that will buy shawarmas at the tent.  The second line should contain two integers $$$p_x$$$ and $$$p_y$$$ — the coordinates where the tent should be located. If there are multiple answers, print any of them. Note that each of $$$p_x$$$ and $$$p_y$$$ should be not less than $$$0$$$ and not greater than $$$10^{9}$$$.

NoteIn the first example, If we build the shawarma tent in $$$(4, 2)$$$, then the students living in $$$(4, 2)$$$, $$$(4, 1)$$$ and $$$(5, 1)$$$ will visit it.In the second example, it is possible to build the shawarma tent in $$$(1, 1)$$$, then both students living in $$$(0, 0)$$$ will visit it.


George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the m he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.

The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.

Print a single integer — the answer to the problem.

NoteIn the first sample the set of the prepared problems meets the requirements for a good round.In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
sort($d);
$e = 0;
for($x = count($c) - 1, $y = count($d) - 1; $x >= 0, $y >= 0; $x--, $y--)
{
    if($c[$x] <= $d[$y])
    {
        $e++;
    }
    else
    {
        array_splice($d, 0, 1);
    }
    if($x == 0)
    {
        break;
    }
}
print count($c) - $e;
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
sort($d);
$e = 0;
$f = count($d);
for($x = count($c) - 1, $y = $f - 1; $x >= 0, $y >= 0; $x--, $y--)
{
    if($c[$x] <= $d[$y])
    {
        $e++;
    }
    else
    {
        array_splice($d, 0, 1);
    }
    if(($x == 0) || ($y == 0))
    {
        break;
    }
}
print count($c) - $e;
?>

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

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
sort($d);
$e = 0;
for($x = count($c) - 1, $y = count($d) - 1; $x >= 0, $y >= 0; $x--, $y--)
{
    if($c[$x] <= $d[$y])
    {
        $e++;
    }
    else
    {
        array_splice($d, 0, 1);
    }
    if(($x == 0) && ($y == 0))
    {
        break;
    }
}
print count($c) - $e;
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = explode(" ", trim(fgets(STDIN)));
sort($c);
sort($d);
$e = 0;
for($x = count($c) - 1, $y = count($d) - 1; $x >= 0, $y >= 0; $x--, $y--)
{
    if($c[$x] <= $d[$y])
    {
        $e++;
    }
    else
    {
        array_splice($d, 0, 1);
    }
    if(($x == 0) || ($y == 0))
    {
        break;
    }
}
print count($c) - $e;
?>


Petya recieved a gift of a string s with length up to 105 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves:  Extract the first character of s and append t with this character.  Extract the last character of t and append u with this character. Petya wants to get strings s and t empty and string u lexicographically minimal.You should write a program that will help Petya win the game.

First line contains non-empty string s (1 ≤ |s| ≤ 105), consisting of lowercase English letters.


Three friends are going to meet each other. Initially, the first friend stays at the position $$$x = a$$$, the second friend stays at the position $$$x = b$$$ and the third friend stays at the position $$$x = c$$$ on the coordinate axis $$$Ox$$$.In one minute each friend independently from other friends can change the position $$$x$$$ by $$$1$$$ to the left or by $$$1$$$ to the right (i.e. set $$$x := x - 1$$$ or $$$x := x + 1$$$) or even don't change it.Let's introduce the total pairwise distance — the sum of distances between each pair of friends. Let $$$a'$$$, $$$b'$$$ and $$$c'$$$ be the final positions of the first, the second and the third friend, correspondingly. Then the total pairwise distance is $$$|a' - b'| + |a' - c'| + |b' - c'|$$$, where $$$|x|$$$ is the absolute value of $$$x$$$.Friends are interested in the minimum total pairwise distance they can reach if they will move optimally. Each friend will move no more than once. So, more formally, they want to know the minimum total pairwise distance they can reach after one minute.You have to answer $$$q$$$ independent test cases.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of test cases. The next $$$q$$$ lines describe test cases. The $$$i$$$-th test case is given as three integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^9$$$) — initial positions of the first, second and third friend correspondingly. The positions of friends can be equal.

For each test case print the answer on it — the minimum total pairwise distance (the minimum sum of distances between each pair of friends) if friends change their positions optimally. Each friend will move no more than once. So, more formally, you have to find the minimum total pairwise distance they can reach after one minute.

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for($j = 0; $j < $n; $j++) {
    list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
    $iMin = abs($a - $b) + abs($a - $c) + abs($b - $c);
    if ($iMin > 4) {
        $iMin = $iMin - 4;
    } else {
        $iMin = 0;
    }
    echo $iMin . "\n";
}


You are given a string $$$s$$$ of length $$$n$$$, which consists only of the first $$$k$$$ letters of the Latin alphabet. All letters in string $$$s$$$ are uppercase.A subsequence of string $$$s$$$ is a string that can be derived from $$$s$$$ by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not.A subsequence of $$$s$$$ called good if the number of occurences of each of the first $$$k$$$ letters of the alphabet is the same.Find the length of the longest good subsequence of $$$s$$$.

The first line of the input contains integers $$$n$$$ ($$$1\le n \le 10^5$$$) and $$$k$$$ ($$$1 \le k \le 26$$$). The second line of the input contains the string $$$s$$$ of length $$$n$$$. String $$$s$$$ only contains uppercase letters from 'A' to the $$$k$$$-th letter of Latin alphabet.

Print the only integer — the length of the longest good subsequence of string $$$s$$$.

NoteIn the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length.In the second example, none of the subsequences can have 'D', hence the answer is $$$0$$$.

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

<?php
fscanf(STDIN,"%d %d",$len,$k);
$str=trim(fgets(STDIN));
$alp="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$str1="";
for ($i=0; $i <strlen($alp) ; $i++)
{
	for ($j=0; $j <$len; $j++)
	{
		if($alp[$i]==$str[$j])
		{
			$str1.=$alp[$i];
			break;
		}

	}
}
$len1=strlen($str1);
if($len1!=$k)
  	echo "0";
else
 {
		for ($i=0; $i <strlen($str1) ; $i++)
	    {
		   $count=0;

			for ($j=0; $j <$len; $j++)
			{
				if($str1[$i]==$str[$j])
				{

					$count++;
				}

			}
			$occurrence[$i]=$count;
	    }
	    $min=$occurrence[0];
	    for ($i=0; $i <count($occurrence) ; $i++)
	    {
	    	if($occurrence[$i]<$min)
	    		$min=$occurrence[$i];
	    }
	    echo $min*$len1;
 }


Nezzar has $$$n$$$ balls, numbered with integers $$$1, 2, \ldots, n$$$. Numbers $$$a_1, a_2, \ldots, a_n$$$ are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that $$$a_i \leq a_{i+1}$$$ for all $$$1 \leq i < n$$$.Nezzar wants to color the balls using the minimum number of colors, such that the following holds.  For any color, numbers on balls will form a strictly increasing sequence if he keeps balls with this chosen color and discards all other balls.  Note that a sequence with the length at most $$$1$$$ is considered as a strictly increasing sequence.Please help Nezzar determine the minimum number of colors.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases.  The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$). The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le n$$$). It is guaranteed that $$$a_1 \leq a_2 \leq \ldots \leq a_n$$$.

For each test case, output the minimum number of colors Nezzar can use.

NoteLet's match each color with some numbers. Then:In the first test case, one optimal color assignment is $$$[1,2,3,3,2,1]$$$.In the second test case, one optimal color assignment is $$$[1,2,1,2,1]$$$.

<?php

$n = readline();

while ($n--) {
    $m = readline();
    $nums = explode(' ', readline());
    $cnt = 1;
    $mid = intdiv(count($nums), 2);
//    echo $del; exit;
    if (count($nums) == 1){
        $res[] = 1; continue;
    }

    $max = -1;
    for ($i = 0; $i < count($nums)-1; $i++) {
        if ($nums[$i] == $nums[$i+1]) {
            $cnt++;
        } else {
            $cnt = 1;
        }
        if ($max < $cnt) {
            $max = $cnt;
        }

    }
    $res[] = $max;
}

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

<?php

/**
 * @author Pablo Digiani <p.digiani@gmail.com>
 * @link https://codeforces.com/problemset/problem/1478/A
 * @version 1.0
 *
 * It took me some minutes to understand what was being requested, but then the solution comes instantly.
 * Note that the use of the explode function makes reading "n" unnecessary
 *
 */

$t = readline();
$responses = [];
for($i = 1; $i<= $t; $i++){

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

    $sequences = [];
    foreach ($numbers as $number){
        $added = false;
        foreach ($sequences as &$sequence){
            if(!in_array($number, $sequence)){
                $sequence[]= $number;
                $added = true;
                break;
            }
        }
        if(!$added) $sequences[] = [$number];
    }
    $responses[]= count($sequences);
}

foreach ($responses as $r) echo $r . PHP_EOL;

<?php

$t = readline();
$responses = [];
for($i = 1; $i<= $t; $i++){
    $n = readline();
    $numbers = explode(' ', readline());

    $sequences = [];
    foreach ($numbers as $number){
        if(empty($sequences)){
            $sequences[] = [$number];
        }else{
            $added = false;
            foreach ($sequences as &$sequence){
                if(!in_array($number, $sequence)){
                    $sequence[]= $number;
                    $added = true;
                    break;
                }
            }
            if(!$added) $sequences[] = [$number];

        }
    }
    $responses[]= count($sequences);
}

foreach ($responses as $r) echo $r . PHP_EOL;

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = explode(" ", trim(fgets(STDIN)));
     $d = array();
     for($y = 0; $y < $b; $y++)
     {
          $d[$c[$y]]++;
     }
     print max($d) . "\n";
}
?>

<?php

$t = (int) trim(fgets(STDIN));
for ($i = 0; $i < $t; ++$i) {
    $n[] = (int) trim(fgets(STDIN));
    $a[$i] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($i = 0; $i < $t; ++$i) {
    echo $cnt = max(array_count_values($a[$i])), PHP_EOL;
}

<?php

$iCount = read();

for($i=0; $i < $iCount; $i++) {
    read();
    $aTest = explode(' ', read());
    $aData = [];
    foreach ($aTest AS $iV) {
        $iV = (int)$iV;
        if(!isset($aData[$iV])) {
            $aData[$iV] = 1;
        } else {
            $aData[$iV]++;
        }
    }

    $aData = array_flip($aData);
    ksort($aData);
    $aData = array_flip($aData);
    $iMax = end($aData);
    write($iMax);
}

function write($a) {
    echo $a . "\n";
}

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

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

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

  $result = array_count_values($a);
  rsort($result);
  echo $result[0].PHP_EOL;
}
?>

<?php
# ╔══╗─╔═══╗╔╗╔═╗╔════╗╔═══╗╔════╗
# ║╔╗║─║╔══╝║║║╔╝╚══╗═║║╔═╗║║╔╗╔╗║
# ║╚╝╚╗║╚══╗║╚╝╝───╔╝╔╝║║─║║╚╝║║╚╝
# ║╔═╗║║╔══╝║╔╗║──╔╝╔╝─║╚═╝║──║║
# ║╚═╝║║╚══╗║║║╚╗╔╝═╚═╗║╔═╗║──║║
# ╚═══╝╚═══╝╚╝╚═╝╚════╝╚╝─╚╝──╚╝

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $n = IO::str();
    $a = IO::arr();
    $res = [];
    foreach ($a as $v) {
        if(isset($res[$v])) {
            $res[$v] += 1;
        } else {
            $res[$v] = 1;
        }
    }
    IO::line(max($res));
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($i = 0; $i < $n; $i++) {
    list($m) = explode(' ', trim(fgets(STDIN)));
    $aList = explode(' ', trim(fgets(STDIN)));
    $aCount = [];
    foreach ($aList as $sK => $sV) {
        if (!isset($aCount[$sV])) {
            $aCount[$sV] = 1;
        } else {
            $aCount[$sV] += 1;
        }
    }
    echo max($aCount). "\n";
}

<?php

$n = readline();

while ($n--) {
    $m = readline();
    $nums = explode(' ', readline());
    $cnt = 1;
    $mid = intdiv(count($nums), 2);
//    echo $del; exit;
    if (count($nums) == 1){
        $res[] = 1; break;
    }

    $max = -1;
    for ($i = 0; $i < count($nums)-1; $i++) {
        if ($nums[$i] == $nums[$i+1]) {
            $cnt++;
        } else {
                $cnt = 1;

        }
        if ($max < $cnt) {
            $max = $cnt;
        }

    }
    $res[] = $max;
}

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

<?php

$n = readline();

while ($n--) {
    $m = readline();
    $nums = explode(' ', readline());
    $cnt = 0;
    $del = intdiv(count($nums), 2);
//    echo $del; exit;
    if (count($nums) == 1){
        $res[] = 1; break;
    }

    for ($i = 0; $i < count($nums)-1; $i++) {
        $del--;
        if ($i >= intdiv(count($nums), 2)){
            break;
        }
        if ($del < 0) {
            if ($nums[$i] >= $nums[count($nums) - 1]) {
                $cnt++;
//                continue;
            }
            echo 'aaa';
            break;
        }
        if ($nums[$i] < $nums[count($nums) - $i - 1]) {
            $cnt++;
        } else {
            $cnt+=2;
        }
    }
    $res[] = $cnt;
}

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

<?php

$n = readline();

while ($n--) {
    $m = readline();
    $nums = explode(' ', readline());
    $cnt = 0;
    $del = intdiv(count($nums), 2);
//    echo $del; exit;
    if (count($nums) == 1){
        $res[] = 1; break;
    }

    for ($i = 0; $i < count($nums)-1; $i++) {
        $del--;
        if ($del < 0) {
            if ($nums[$i] >= $nums[count($nums) - 1]) {
                $cnt++;
                continue;
            }
            break;
        }
        if ($nums[$i] < $nums[count($nums) - $i - 1]) {
            $cnt++;
        } else {
            $cnt+=2;
        }
    }
    $res[] = $cnt;
}

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

<?php

$n = readline();

while ($n--) {
    $m = readline();
    $nums = explode(' ', readline());
    $cnt = 0;
    $del = intdiv(count($nums), 2);
//    echo $del; exit;
    if (count($nums) == 1){
        $res[] = 1; break;
    }

    for ($i = 0; $i < count($nums)-1; $i++) {
        $del--;
        if ($del < 0) {

            break;
        }

        if ($nums[$i] < $nums[count($nums) - $i - 1]) {
            $cnt++;
        } else {
            $cnt+=2;
        }
    }
    $res[] = $cnt;
}

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

<?php

/**
 * @author Pablo Digiani <p.digiani@gmail.com>
 * @link https://codeforces.com/problemset/problem/1478/A
 * @version 1.0
 *
 * It took me some minutes to understand what was being requested, but then the solution comes instantly.
 * Note that the use of the explode function makes reading "n" unnecessary
 *
 */

$t = readline();
$responses = [];
for($i = 1; $i<= $t; $i++){

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

    $sequences = [];
    foreach ($numbers as $number){
        $added = false;
        foreach ($sequences as $sequence){
            if(!in_array($number, $sequence)){
                $sequence[]= $number;
                $added = true;
                break;
            }
        }
        if(!$added) $sequences[] = [$number];
    }
    $responses[]= count($sequences);
}

foreach ($responses as $r) echo $r . PHP_EOL;

<?php
$t = readline();
$responses = [];
for($i = 1; $i<= $t; $i++){
    $n = readline();
    $numbers = explode(' ', readline());

    $sequences = [];
    foreach ($numbers as $number){
        $added = false;
        foreach ($sequences as $sequence){
            if(!in_array($number, $sequence)){
                $sequence[]= $number;
                $added = true;
                break;
            }
        }
        if(!$added) $sequences[] = [$number];
    }
    $responses[]= count($sequences);
}

foreach ($responses as $r) echo $r . PHP_EOL;


You are responsible for installing a gas pipeline along a road. Let's consider the road (for simplicity) as a segment $$$[0, n]$$$ on $$$OX$$$ axis. The road can have several crossroads, but for simplicity, we'll denote each crossroad as an interval $$$(x, x + 1)$$$ with integer $$$x$$$. So we can represent the road as a binary string consisting of $$$n$$$ characters, where character 0 means that current interval doesn't contain a crossroad, and 1 means that there is a crossroad.Usually, we can install the pipeline along the road on height of $$$1$$$ unit with supporting pillars in each integer point (so, if we are responsible for $$$[0, n]$$$ road, we must install $$$n + 1$$$ pillars). But on crossroads we should lift the pipeline up to the height $$$2$$$, so the pipeline won't obstruct the way for cars.We can do so inserting several zig-zag-like lines. Each zig-zag can be represented as a segment $$$[x, x + 1]$$$ with integer $$$x$$$ consisting of three parts: $$$0.5$$$ units of horizontal pipe + $$$1$$$ unit of vertical pipe + $$$0.5$$$ of horizontal. Note that if pipeline is currently on height $$$2$$$, the pillars that support it should also have length equal to $$$2$$$ units.  Each unit of gas pipeline costs us $$$a$$$ bourles, and each unit of pillar — $$$b$$$ bourles. So, it's not always optimal to make the whole pipeline on the height $$$2$$$. Find the shape of the pipeline with minimum possible cost and calculate that cost.Note that you must start and finish the pipeline on height $$$1$$$ and, also, it's guaranteed that the first and last characters of the input string are equal to 0.

The fist line contains one integer $$$T$$$ ($$$1 \le T \le 100$$$) — the number of queries. Next $$$2 \cdot T$$$ lines contain independent queries — one query per two lines. The first line contains three integers $$$n$$$, $$$a$$$, $$$b$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le a \le 10^8$$$, $$$1 \le b \le 10^8$$$) — the length of the road, the cost of one unit of the pipeline and the cost of one unit of the pillar, respectively. The second line contains binary string $$$s$$$ ($$$|s| = n$$$, $$$s_i \in \{0, 1\}$$$, $$$s_1 = s_n = 0$$$) — the description of the road. It's guaranteed that the total length of all strings $$$s$$$ doesn't exceed $$$2 \cdot 10^5$$$.

Print $$$T$$$ integers — one per query. For each query print the minimum possible cost of the constructed pipeline.

NoteThe optimal pipeline for the first query is shown at the picture above.The optimal pipeline for the second query is pictured below:  The optimal (and the only possible) pipeline for the third query is shown below:  The optimal pipeline for the fourth query is shown below:


A class of students got bored wearing the same pair of shoes every day, so they decided to shuffle their shoes among themselves. In this problem, a pair of shoes is inseparable and is considered as a single object.There are $$$n$$$ students in the class, and you are given an array $$$s$$$ in non-decreasing order, where $$$s_i$$$ is the shoe size of the $$$i$$$-th student. A shuffling of shoes is valid only if no student gets their own shoes and if every student gets shoes of size greater than or equal to their size. You have to output a permutation $$$p$$$ of $$$\{1,2,\ldots,n\}$$$ denoting a valid shuffling of shoes, where the $$$i$$$-th student gets the shoes of the $$$p_i$$$-th student ($$$p_i \ne i$$$). And output $$$-1$$$ if a valid shuffling does not exist.A permutation is an array consisting of $$$n$$$ distinct integers from $$$1$$$ to $$$n$$$ in arbitrary order. For example, $$$[2,3,1,5,4]$$$ is a permutation, but $$$[1,2,2]$$$ is not a permutation ($$$2$$$ appears twice in the array) and $$$[1,3,4]$$$ is also not a permutation ($$$n=3$$$ but there is $$$4$$$ in the array).

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1\leq n\leq10^5$$$) — the number of students. The second line of each test case contains $$$n$$$ integers $$$s_1, s_2,\ldots,s_n$$$ ($$$1\leq s_i\leq10^9$$$, and for all $$$1\le i<n$$$, $$$s_i\le s_{i+1}$$$) — the shoe sizes of the students. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print the answer in a single line using the following format. If a valid shuffling does not exist, print the number $$$-1$$$ as the answer. If a valid shuffling exists, print $$$n$$$ space-separated integers — a permutation $$$p$$$ of $$$1,2,\ldots,n$$$ denoting a valid shuffling of shoes where the $$$i$$$-th student gets the shoes of the $$$p_i$$$-th student. If there are multiple answers, then print any of them.

NoteIn the first test case, any permutation $$$p$$$ of $$$1,\ldots,n$$$ where $$$p_i\ne i$$$ would represent a valid shuffling since all students have equal shoe sizes, and thus anyone can wear anyone's shoes.In the second test case, it can be shown that no valid shuffling is possible.

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fgets(STDIN);
    $result = [];
    $arr = [1];
    foreach (fgetcsv(STDIN, 0, ' ') as $key => $value) {
        $key += 1;
        if ($arr[0] == $key) {
            $arr = [$key, $value, false];
        } elseif ($arr[1] != $value) {
            if ($arr[2]) {
                $result[] = $arr[0];
                $arr = [$key, $value, false];
            } else {
                $arr = [2 => false];
                $result = [];
                break;
            }
        } else {
            $result[] = $key;
            $arr[2] = true;
        }
    }
    if (empty($arr[2])) {
        $result = [];
    } else {
        $result[] = $arr[0];
    }
    echo ($result ? implode(' ', $result) : '-1'), "\n";
}

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

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

 function solve()
 {
     $n = IO::getInt();
     $s = IO::getArray();
     $ans = 0;
     $count= 0;

     $p = [];
    $ok = true;
    $beg = 0;
    while ($beg < $n) {
      $end = $beg;
      while ($end + 1 < $n && $s[$end + 1] == $s[$end]) {
        $end += 1;
      }
      if ($beg == $end) {
        $ok = false;
        break;
      }
      $p[$beg] = $end;
      for ($i = $beg + 1; $i <= $end; $i++) {
        $p[$i] = $i-1;
      }
      $beg = $end + 1;
    }
    if (!$ok) {
      IO::pr('-1');
    } else {
          for ($i = 0; $i < $n; $i++) {
               echo $p[$i] + 1, ' ';
         }
         echo "\n";
    }

 }

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

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

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

        return $d == $n;
    }

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

         return $a[$n];
     }

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

}

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

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

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

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

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

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

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

        return $aResult;

    }
}

class SolveArchive
{

}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fgets(STDIN);
    $result = [];
    $arr = [1];
    foreach (fgetcsv(STDIN, 0, ' ') as $key => $value) {
        $key += 1;
        if ($arr[0] == $key) {
            $arr[1] = $value;
            $arr[2] = false;
        } elseif ($arr[1] != $value) {
            if ($arr[2]) {
                $result[] = $arr[0];
                $arr = [$key, $value, false];
            } else {
                $arr = [2 => false];
                $result = [];
                break;
            }
        } else {
            $result[] = $key;
            $arr[2] = true;
        }
    }
    if ($arr[2]) {
        $result[] = $arr[0];
    }
    echo ($result ? implode(' ', $result) : '-1'), "\n";
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fgets(STDIN);
    $result = [];
    $arr = [1];
    foreach (fgetcsv(STDIN, 0, ' ') as $key => $value) {
        $key += 1;
        if ($arr[0] == $key) {
            $arr[1] = $value;
            $arr[2] = false;
        } elseif ($arr[1] != $value) {
            if ($arr[2]) {
                $result[] = $arr[0];
                $arr = [$key, $value, false];
            } else {
                $arr = [];
                $result = [-1];
                break;
            }
        } else {
            $result[] = $key;
            $arr[2] = true;
        }
    }
    if ($arr) {
        $result[] = $arr[0];
    }
    echo implode(' ', $result), "\n";
}


You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an n × n grid. The rows are numbered 1 through n from top to bottom, and the columns are numbered 1 through n from left to right. At the far side of the room lies a door locked with evil magical forces. The following inscriptions are written on the door: The cleaning of all evil will awaken the door! Being a very senior adventurer, you immediately realize what this means. You notice that every single cell in the grid are initially evil. You should purify all of these cells.The only method of tile purification known to you is by casting the "Purification" spell. You cast this spell on a single tile — then, all cells that are located in the same row and all cells that are located in the same column as the selected tile become purified (including the selected tile)! It is allowed to purify a cell more than once.You would like to purify all n × n cells while minimizing the number of times you cast the "Purification" spell. This sounds very easy, but you just noticed that some tiles are particularly more evil than the other tiles. You cannot cast the "Purification" spell on those particularly more evil tiles, not even after they have been purified. They can still be purified if a cell sharing the same row or the same column gets selected by the "Purification" spell.Please find some way to purify all the cells with the minimum number of spells cast. Print -1 if there is no such way.

The first line will contain a single integer n (1 ≤ n ≤ 100). Then, n lines follows, each contains n characters. The j-th character in the i-th row represents the cell located at row i and column j. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise.

If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts x "Purification" spells (where x is the minimum possible number of spells), output x lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purification" spell.

NoteThe first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.   In the second example, it is impossible to purify the cell located at row 1 and column 1.For the third example:

<?php
/** SECTION 0: NOTES **/
/*
Problem:
Codeforces Contest 192 Div 1 Problem A

Author          : chaotic_iak (http://chaoticiak.comlu.com/)
Language        : PHP 5.4
Released under  : CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
Template version: 20130717 (http://chaoticiak.comlu.com/prog/assorted/templates.phps)
                           (http://ideone.com/AV2T2U)
*/

/** SECTION 1: SET UP INPUT HANDLER **/
// 0: Don't output format at all
// 1: Trim newline characters only
// 2: Assume \x00..\x20 (accaw) as delimiters and output as array

if (isset($inputstream)) {$stdin = $inputstream;} else {$stdin = fopen("php://stdin", "r");}
function g($format = 2) {
    global $stdin;
    $input = fgets($stdin);
    if ($format == 0) {return $input;}
    $input = trim($input, "\n\r");
    if ($format == 1) {return $input;}
    $input = trim($input, "\x00..\x20");
    $input = preg_replace("/[\\x00-\\x20]+/", " ", $input);
    return explode(" ", $input);
}

/** SECTION 2: IMPORTING FUNCTIONS FROM chaotic_iak'S LIBRARY **/
// none

/** SECTION 3: SOLVING THE PROBLEM **/
$n = g(1);
for ($i = 0; $i < $n; $i++) {
	$temp = g(1);
	for ($j = 0; $j < $n; $j++) {
		$cell[$i][$j] = (substr($temp, $j, 1) == ".") ? 1 : 0;
	}
}

//attempt 1
$res = "";
$success = true;
for ($i = 0; $i < $n; $i++) {
	$flag = false;
	for ($j = 0; $j < $n; $j++) {
		if ($cell[$i][$j]) {
			if (!$flag) {$res .= ($i+1) . " " . ($j+1) . "\n";}
			$flag = true;
			break;
		}
	}
	if (!$flag) {$success = false; break;}
}
if ($success) {echo $res;}

//attempt 2
if (!$success) {

$res = "";
$success = true;
for ($i = 0; $i < $n; $i++) {
	$flag = false;
	for ($j = 0; $j < $n; $j++) {
		if ($cell[$j][$i]) {
			if (!$flag) {$res .= ($j+1) . " " . ($i+1) . "\n";}
			$flag = true;
			break;
		}
	}
	if (!$flag) {$success = false; break;}
}
if ($success) {echo $res;}

}

if (!$success) {echo "-1";}

<?php
/** SECTION 0: NOTES **/
/*
Problem:
Codeforces Contest 192 Div 1 Problem A

Author          : chaotic_iak (http://chaoticiak.comlu.com/)
Language        : PHP 5.4
Released under  : CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
Template version: 20130717 (http://chaoticiak.comlu.com/prog/assorted/templates.phps)
                           (http://ideone.com/AV2T2U)
*/

/** SECTION 1: SET UP INPUT HANDLER **/
// 0: Don't output format at all
// 1: Trim newline characters only
// 2: Assume \x00..\x20 (accaw) as delimiters and output as array

if (isset($inputstream)) {$stdin = $inputstream;} else {$stdin = fopen("php://stdin", "r");}
function g($format = 2) {
    global $stdin;
    $input = fgets($stdin);
    if ($format == 0) {return $input;}
    $input = trim($input, "\n\r");
    if ($format == 1) {return $input;}
    $input = trim($input, "\x00..\x20");
    $input = preg_replace("/[\\x00-\\x20]+/", " ", $input);
    return explode(" ", $input);
}

/** SECTION 2: IMPORTING FUNCTIONS FROM chaotic_iak'S LIBRARY **/
// none

/** SECTION 3: SOLVING THE PROBLEM **/
$n = g(1);
for ($i = 0; $i < $n; $i++) {
	$temp = g(1);
	for ($j = 0; $j < $n; $j++) {
		$cell[$i][$j] = (substr($temp, $j, 1) == ".") ? 1 : 0;
	}
}

//attempt 1
$res = "";
$success = true;
for ($i = 0; $i < $n; $i++) {
	$flag = false;
	for ($j = 0; $j < $n; $j++) {
		if ($cell[$i][$j]) {
			if (!$flag) {$res .= $i . " " . $j . "\n";}
			$flag = true;
			break;
		}
	}
	if (!$flag) {$success = false; break;}
}
if ($success) {echo $res;}

//attempt 2
if (!$success) {

$res = "";
$success = true;
for ($i = 0; $i < $n; $i++) {
	$flag = false;
	for ($j = 0; $j < $n; $j++) {
		if ($cell[$j][$i]) {
			if (!$flag) {$res .= $j . " " . $i . "\n";}
			$flag = true;
			break;
		}
	}
	if (!$flag) {$success = false; break;}
}
if ($success) {echo $res;}

}

if (!$success) {echo "-1";}


Two neighboring kingdoms decided to build a wall between them with some gates to enable the citizens to go from one kingdom to another. Each time a citizen passes through a gate, he has to pay one silver coin.The world can be represented by the first quadrant of a plane and the wall is built along the identity line (i.e. the line with the equation x = y). Any point below the wall belongs to the first kingdom while any point above the wall belongs to the second kingdom. There is a gate at any integer point on the line (i.e. at points (0, 0), (1, 1), (2, 2), ...). The wall and the gates do not belong to any of the kingdoms. Fafa is at the gate at position (0, 0) and he wants to walk around in the two kingdoms. He knows the sequence S of moves he will do. This sequence is a string where each character represents a move. The two possible moves Fafa will do are 'U' (move one step up, from (x, y) to (x, y + 1)) and 'R' (move one step right, from (x, y) to (x + 1, y)). Fafa wants to know the number of silver coins he needs to pay to walk around the two kingdoms following the sequence S. Note that if Fafa visits a gate without moving from one kingdom to another, he pays no silver coins. Also assume that he doesn't pay at the gate at point (0, 0), i. e. he is initially on the side he needs.

The first line of the input contains single integer n (1 ≤ n ≤ 105) — the number of moves in the walking sequence. The second line contains a string S of length n consisting of the characters 'U' and 'R' describing the required moves. Fafa will follow the sequence S in order from left to right.

On a single line, print one integer representing the number of silver coins Fafa needs to pay at the gates to follow the sequence S.

NoteThe figure below describes the third sample. The red arrows represent the sequence of moves Fafa will follow. The green gates represent the gates at which Fafa have to pay silver coins.


You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice.The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists either from intact or from cracked ice. From each cell you can move to cells that are side-adjacent with yours (due to some limitations of the game engine you cannot make jumps on the same place, i.e. jump from a cell to itself). If you move to the cell with cracked ice, then your character falls down through it and if you move to the cell with intact ice, then the ice on this cell becomes cracked.Let's number the rows with integers from 1 to n from top to bottom and the columns with integers from 1 to m from left to right. Let's denote a cell on the intersection of the r-th row and the c-th column as (r, c). You are staying in the cell (r1, c1) and this cell is cracked because you've just fallen here from a higher level. You need to fall down through the cell (r2, c2) since the exit to the next level is there. Can you do this?

The first line contains two integers, n and m (1 ≤ n, m ≤ 500) — the number of rows and columns in the cave description. Each of the next n lines describes the initial state of the level of the cave, each line consists of m characters "." (that is, intact ice) and "X" (cracked ice). The next line contains two integers, r1 and c1 (1 ≤ r1 ≤ n, 1 ≤ c1 ≤ m) — your initial coordinates. It is guaranteed that the description of the cave contains character 'X' in cell (r1, c1), that is, the ice on the starting cell is initially cracked. The next line contains two integers r2 and c2 (1 ≤ r2 ≤ n, 1 ≤ c2 ≤ m) — the coordinates of the cell through which you need to fall. The final cell may coincide with the starting one.

If you can reach the destination, print 'YES', otherwise print 'NO'.

NoteIn the first sample test one possible path is:After the first visit of cell (2, 2) the ice on it cracks and when you step there for the second time, your character falls through the ice as intended.


You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence.We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|.String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y|, if either |x| > |y| and x1 = y1, x2 = y2, ... , x|y| = y|y|, or exists such number r (r < |x|, r < |y|), that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 > yr + 1. Characters in lines are compared like their ASCII codes.

The single line contains a non-empty string s, consisting only of lowercase English letters. The string's length doesn't exceed 105.

Print the lexicographically maximum subsequence of string s.

NoteLet's look at samples and see what the sought subsequences look like (they are marked with uppercase bold letters).The first sample: aBaBBAThe second sample: abbCbCCaCbbCBaaBA


Ksusha is a beginner coder. Today she starts studying arrays. She has array a1, a2, ..., an, consisting of n positive integers.Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number!

The first line contains integer n (1 ≤ n ≤ 105), showing how many numbers the array has. The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the array elements.

Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them.

<?php
# A. Ксюша и массив

$count = trim(fgets(STDIN));
$arr = trim(fgets(STDIN));
$arr = explode(' ', $arr);

$arr = array_unique($arr);
$arr = array_values($arr);
$count = count($arr);
$result = -1;

for ($i = 0; $i < $count; $i++) {
    if ($arr[$i] == 1) {
        $result = 1;
        break;
    } else {
        for ($j = 0; $j < $count; $j++) {
            if ($arr[$j] % $arr[$i] != 0) {
                break;
            }
            if ($j == $count-1) {
                $result = $arr[$i];
                break;
            }
        }
    }
}

echo $result;

<?php
# A. Ксюша и массив

$count = trim(fgets(STDIN));
$arr = trim(fgets(STDIN));
$arr = explode(' ', $arr);

$arr = array_unique($arr);
$count = count($arr);
$result = -1;
for ($i = 0; $i < $count; $i++) {
    if ($arr[$i] == 1) {
        $result = 1;
        break;
    } else {
        for ($j = 0; $j < $count; $j++) {
            if ($arr[$j] % $arr[$i] != 0) {
                break;
            }
            if ($j == $count-1) {
                $result = $arr[$i];
                break;
            }
        }
    }
}

echo $result;

<?php
# A. Ксюша и массив

$count = trim(fgets(STDIN));
$arr = trim(fgets(STDIN));

$arr = explode(' ', $arr);

sort($arr);

$result = -1;

if ($count > 2 && $arr[$count-2] > floor($arr[$count-1]/2) && $arr[$count-2] != $arr[$count-1]) {

} else {
    for ($i = 0; $i < $count; $i++) {
        if ($arr[$i] == 1) {
            $result = 1;
            break;
        } else {
            for ($j = 0; $j < count($arr); $j++) {
                if ($arr[$j] % $arr[$i] != 0) {
                    break;
                }
                if ($j == count($arr)-1) {
                    $result = $arr[$i];
                    break;
                }
            }
        }
    }
}

echo $result;

<?php
# A. Ксюша и массив

$count = trim(fgets(STDIN));
$arr = trim(fgets(STDIN));

$arr = explode(' ', $arr);

$result = -1;
for ($i = 0; $i < count($arr); $i++) {
    if ($arr[$i] == 1) {
        $result = 1;
        break;
    } else {
        for ($j = 0; $j < count($arr); $j++) {
            if ($arr[$i] % $arr[$j] != 0) {
                break;
            }
            if ($j == count($arr)-1) {
                $result = $i;
                break;
            }
        }
    }
}

echo $result;

<?php
# A. Ксюша и массив

#define('STDIN',fopen("php://stdin","r"));

$arr = trim(fgets(STDIN));

/*$arr = array();
for ($i = 0; $i < 5; $i++) {
    array_push($arr, rand(2, 10));
}*/

$arr = explode(' ', $arr);

$result = -1;
for ($i = 0; $i < count($arr); $i++) {
    if ($arr[$i] == 1) {
        $result = 1;
        break;
    } else {
        for ($j = 0; $j < count($arr); $j++) {
            if ($arr[$i] % $arr[$j] != 0) {
                break;
            }
            if ($j == count($arr)) {
                $result = $i;
                break;
            }
        }
    }
}

echo $result;

<?php
# A. Ксюша и массив

$arr = trim(fgets(STDIN));

$arr = explode(' ', $arr);

$result = -1;
for ($i = 0; $i < count($arr); $i++) {
    if ($arr[$i] == 1) {
        $result = 1;
        break;
    } else {
        for ($j = 0; $j < count($arr); $j++) {
            if ($arr[$i] % $arr[$j] != 0) {
                break;
            }
            if ($j == count($arr)-1) {
                $result = $i;
                break;
            }
        }
    }
}

echo $result;

<?php
# A. Ксюша и массив

$count = trim(fgets(STDIN));
$arr = trim(fgets(STDIN));

$arr = explode(' ', $arr);

$result = -1;
for ($i = 0; $i < count($arr); $i++) {
    if ($arr[$i] == 1) {
        $result = 1;
        break;
    } else {
        for ($j = 0; $j < count($arr); $j++) {
            if ($arr[$i] % $arr[$j] != 0) {
                break;
            }
            if ($j == count($arr)-1) {
                $result = $arr[$i];
                break;
            }
        }
    }
}

echo $result;

<?php
# A. Ксюша и массив

$count = trim(fgets(STDIN));
$arr = trim(fgets(STDIN));

$arr = explode(' ', $arr);

$result = -1;
$last = 0;
for ($i = 0; $i < $count; $i++) {
    if ($a[$i] == $last) {
        continue;
    }
    if ($arr[$i] == 1) {
        $result = 1;
        break;
    } else {
        for ($j = 0; $j < $count; $j++) {
            if ($arr[$j] % $arr[$i] != 0) {
                break;
            }
            if ($j == $count-1) {
                $result = $arr[$i];
                break;
            }
        }
    }
}

echo $result;

<?php
# A. Ксюша и массив

$count = trim(fgets(STDIN));
$arr = trim(fgets(STDIN));
$arr = explode(' ', $arr);

$arr = array_unique($arr);
$result = -1;
for ($i = 0; $i < $count; $i++) {
    if ($arr[$i] == 1) {
        $result = 1;
        break;
    } else {
        for ($j = 0; $j < $count; $j++) {
            if ($arr[$j] % $arr[$i] != 0) {
                break;
            }
            if ($j == $count-1) {
                $result = $arr[$i];
                break;
            }
        }
    }
}

echo $result;


Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi (xi ≠ yi).In the tournament, each team plays exactly one home game and exactly one away game with each other team (n(n - 1) games in total). The team, that plays the home game, traditionally plays in its home kit. The team that plays an away game plays in its away kit. However, if two teams has the kits of the same color, they cannot be distinguished. In this case the away team plays in its home kit.Calculate how many games in the described tournament each team plays in its home kit and how many games it plays in its away kit.

The first line contains a single integer n (2 ≤ n ≤ 105) — the number of teams. Next n lines contain the description of the teams. The i-th line contains two space-separated numbers xi, yi (1 ≤ xi, yi ≤ 105; xi ≠ yi) — the color numbers for the home and away kits of the i-th team.

For each team, print on a single line two space-separated integers — the number of games this team is going to play in home and away kits, correspondingly. Print the answers for the teams in the order they appeared in the input.

<?php
error_reporting("off");
//432B: Football Kit
$n = trim(fgets(STDIN));
$x = array();
$y = array();
for ($i = 0; $i < $n; $i++) {
  list($a, $b) = explode(" ", trim(fgets(STDIN)));
  $x[] = $a;
  $y[] = $b;
}
$xcount = array_count_values($x);
for ($i = 0; $i < $n; $i++) {
  $home = $n - 1;
  $home += $xcount[$y[$i]];
  $away = 2 * ($n - 1) - $home;
  echo $home." ".$away."\n";
}
?>

<?php
error_reporting("off");
//432B: Football Kit
$n = trim(fgets(STDIN));
$x = array();
$y = array();
for ($i = 0; $i < $n; $i++) {
  list($a, $b) = explode(" ", trim(fgets(STDIN)));
  $x[] = $a;
  $y[] = $b;
}
$ycount = array_count_values($y);
for ($i = 0; $i < $n; $i++) {
  $home = $n - 1;
  $home += $ycount[$x[$i]];
  $away = 2 * ($n - 1) - $home;
  echo $home." ".$away."\n";
}
?>


You are given two matrices $$$A$$$ and $$$B$$$. Each matrix contains exactly $$$n$$$ rows and $$$m$$$ columns. Each element of $$$A$$$ is either $$$0$$$ or $$$1$$$; each element of $$$B$$$ is initially $$$0$$$.You may perform some operations with matrix $$$B$$$. During each operation, you choose any submatrix of $$$B$$$ having size $$$2 \times 2$$$, and replace every element in the chosen submatrix with $$$1$$$. In other words, you choose two integers $$$x$$$ and $$$y$$$ such that $$$1 \le x < n$$$ and $$$1 \le y < m$$$, and then set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$.Your goal is to make matrix $$$B$$$ equal to matrix $$$A$$$. Two matrices $$$A$$$ and $$$B$$$ are equal if and only if every element of matrix $$$A$$$ is equal to the corresponding element of matrix $$$B$$$.Is it possible to make these matrices equal? If it is, you have to come up with a sequence of operations that makes $$$B$$$ equal to $$$A$$$. Note that you don't have to minimize the number of operations.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n, m \le 50$$$). Then $$$n$$$ lines follow, each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$A_{i, j}$$$. Each integer is either $$$0$$$ or $$$1$$$.

If it is impossible to make $$$B$$$ equal to $$$A$$$, print one integer $$$-1$$$. Otherwise, print any sequence of operations that transforms $$$B$$$ into $$$A$$$ in the following format: the first line should contain one integer $$$k$$$ — the number of operations, and then $$$k$$$ lines should follow, each line containing two integers $$$x$$$ and $$$y$$$ for the corresponding operation (set $$$B_{x, y}$$$, $$$B_{x, y + 1}$$$, $$$B_{x + 1, y}$$$ and $$$B_{x + 1, y + 1}$$$ to $$$1$$$). The condition $$$0 \le k \le 2500$$$ should hold.

<?php

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

list($n, $m) = array_map('intval', explode(' ', fgets($__fp)));

$martix = [];
$sum = 0;
for ($i = 0; $i < $n; $i++) {
    $martix[$i] = array_map('intval', explode(' ', fgets($__fp)));
    $sum += array_sum($martix[$i]);
}

if ($sum == 0) {
    echo 0;
    exit;
}

$checked = [];

$found = [];

$res = [];

for ($i = 0; $i < $n - 1; $i++) {
    for ($j = 0; $j < $m - 1; $j++) {
        if ($martix[$i][$j] == 1) {

            $r = $martix[$i][$j + 1] + $martix[$i + 1][$j] + $martix[$i + 1][$j + 1];

            $qq = [
                $i . '_' . $j => 1,
                $i . '_' . ($j + 1) => $martix[$i][$j + 1] ,
                ($i + 1) . '_' . $j => $martix[$i + 1][$j],
                ($i + 1) . '_' . ($j + 1) => $martix[$i + 1][$j + 1]
            ];

            $found = array_merge($found, array_filter($qq));
            if ($r == 3) {
                $res[] = ($i + 1) . ' ' . ($j + 1);
                $checked = array_merge($checked, array_filter($qq));
            }
        }
    }
}

if (count($res) == 0 || count($checked) != count($found)) {

    echo -1;
    exit;
}

echo count($res), PHP_EOL, implode(PHP_EOL, $res), PHP_EOL;

<?php

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

list($n, $m) = array_map('intval', explode(' ', fgets($__fp)));

$martix = [];
$sum = 0;
for ($i = 0; $i < $n; $i++) {
    $martix[$i] = array_map('intval', explode(' ', fgets($__fp)));
    $sum += array_sum($martix[$i]);
}

if ($sum == 0) {
    echo 0;
    exit;
}

$res = [];

for ($i = 0; $i < $n - 1; $i++) {
    for ($j = 0; $j < $m - 1; $j++) {
        if ($martix[$i][$j] == 1) {
            if ($martix[$i][$j + 1] && $martix[$i + 1][$j] && $martix[$i + 1][$j + 1]) {
                $res[] = ($i + 1) . ' ' . ($j + 1);
            }
        }
    }
}

if(count($res) == 0)
{
    echo -1;exit;
}

echo count($res), PHP_EOL, implode(PHP_EOL, $res), PHP_EOL;


Each day in Berland consists of $$$n$$$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $$$a_1, a_2, \dots, a_n$$$ (each $$$a_i$$$ is either $$$0$$$ or $$$1$$$), where $$$a_i=0$$$ if Polycarp works during the $$$i$$$-th hour of the day and $$$a_i=1$$$ if Polycarp rests during the $$$i$$$-th hour of the day.Days go one after another endlessly and Polycarp uses the same schedule for each day.What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.

The first line contains $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of hours per day. The second line contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i=0$$$ if the $$$i$$$-th hour in a day is working and $$$a_i=1$$$ if the $$$i$$$-th hour is resting. It is guaranteed that $$$a_i=0$$$ for at least one $$$i$$$.

Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.

NoteIn the first example, the maximal rest starts in last hour and goes to the first hour of the next day.In the second example, Polycarp has maximal rest from the $$$4$$$-th to the $$$5$$$-th hour.In the third example, Polycarp has maximal rest from the $$$3$$$-rd to the $$$5$$$-th hour.In the fourth example, Polycarp has no rest at all.

<?php
# 1141B

$input = fopen('php://stdin', 'rb');
$count = (int)fgets($input);
$line = explode('0', str_repeat(str_replace(' ', '', trim(fgets($input))), 3));
sort($line);
echo strlen(array_pop($line));

<?php
// var_dump(3/26);die();

$n = intval(trim(fgets(STDIN)));
$hours = explode(" ",strval(trim(fgets(STDIN))));
$hours = array_merge($hours,$hours);
$continuous_resting_hours_arr = [];
$continuous_resting_hours = 0;
for ($i=0; $i < count($hours); $i++) {

	if($hours[$i]){
		$continuous_resting_hours++;
		// if($i==$n-1){
		// 	if($hours[0]){
		// 		$continuous_resting_hours++;
		// 	}

		// 	$continuous_resting_hours_arr[]=$continuous_resting_hours;
		// }
	}else{
		$continuous_resting_hours_arr[]=$continuous_resting_hours;
		$continuous_resting_hours=0;
		if($i>=$n){
			break;
		}
	}
}
echo max($continuous_resting_hours_arr);

<?php
$time = readline();
$hours = readline();
//$time = 7;
//$hours = '1 0 1 1 1 0 1';
$hours = explode (' ',$hours);
$resting = 0;
$max_resting = 0;
foreach ($hours as $v) {
    $hours[] = $v;
}
foreach ($hours as $v) {
    if ($v == 1) {
        $resting += 1;
    } else {
        $resting = 0;
    }
    if ($resting > $max_resting) {
        $max_resting = $resting;
        }
}
echo $max_resting;

<?php

$n = trim(fgets(STDIN));

$day = trim(fgets(STDIN));

$d = explode(' ', $day.' '.$day);

$lgst = 0;
$l = 0;

for($i = 0; $i<2*$n; $i++){
	if($d[$i] == 1){
		$l++;
	}else{
		if($l > $lgst) $lgst = $l;
		$l = 0;
	}
}

fwrite(STDOUT, $lgst);

<?php
$n = intval(trim(fgets(STDIN)));
$hours = explode(" ",strval(trim(fgets(STDIN))));

$continuous_resting_hours_arr = [];
$continuous_resting_hours = 0;
for ($i=0; $i < $n; $i++) {

	if($hours[$i]){
		$continuous_resting_hours++;
		if($i==$n-1&&$hours[$i]){
			$continuous_resting_hours++;
			$continuous_resting_hours_arr[]=$continuous_resting_hours;
		}
	}else{
		$continuous_resting_hours_arr[]=$continuous_resting_hours;
		$continuous_resting_hours=0;
	}
}
echo max($continuous_resting_hours_arr);

<?php
// var_dump(3/26);die();

$n = intval(trim(fgets(STDIN)));
$hours = explode(" ",strval(trim(fgets(STDIN))));

$continuous_resting_hours_arr = [];
$continuous_resting_hours = 0;
for ($i=0; $i < $n; $i++) {

	if($hours[$i]){
		$continuous_resting_hours++;
		if($i==$n-1){
			if($hours[0]){
				$continuous_resting_hours++;
			}

			$continuous_resting_hours_arr[]=$continuous_resting_hours;
		}
	}else{
		$continuous_resting_hours_arr[]=$continuous_resting_hours;
		$continuous_resting_hours=0;
	}
}
echo max($continuous_resting_hours_arr);

<?php
// var_dump(3/26);die();

$n = intval(trim(fgets(STDIN)));
$hours = explode(" ",strval(trim(fgets(STDIN))));

$continuous_resting_hours_arr = [];
$continuous_resting_hours = 0;
for ($i=0; $i < $n; $i++) {

	if($hours[$i]){
		$continuous_resting_hours++;
		if($i==$n-1&&$hours[0]){
			$continuous_resting_hours++;
			$continuous_resting_hours_arr[]=$continuous_resting_hours;
		}
	}else{
		$continuous_resting_hours_arr[]=$continuous_resting_hours;
		$continuous_resting_hours=0;
	}
}
echo max($continuous_resting_hours_arr);


A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.B now gives this string to C and he appends some number of letters 'c' to the end of the string. However, since C is a good friend of A and B, the number of letters 'c' he appends is equal to the number of 'a' or to the number of 'b' in the string. It is also possible that the number of letters 'c' equals both to the number of letters 'a' and to the number of letters 'b' at the same time.You have a string in your hands, and you want to check if it is possible to obtain the string in this way or not. If it is possible to obtain the string, print "YES", otherwise print "NO" (without the quotes).

The first and only line consists of a string $$$S$$$ ($$$ 1 \le |S| \le 5\,000 $$$). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'.

Print "YES" or "NO", according to the condition.

NoteConsider first example: the number of 'c' is equal to the number of 'a'. Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.Consider third example: the number of 'c' is equal to the number of 'b'.

<?php

$str = trim(fgets(STDIN));

if (!preg_match("#^(a+)(b+)(c+)$#", $str, $matches)) {
    echo "NO\n";
    die;
}

if (strlen($matches[3]) == strlen($matches[2])
    || strlen($matches[3]) == strlen($matches[1])) {
    echo "YES\n";
    die;
}

echo "NO\n";


Vasya is developing his own programming language VPL (Vasya Programming Language). Right now he is busy making the system of exceptions. He thinks that the system of exceptions must function like that.The exceptions are processed by try-catch-blocks. There are two operators that work with the blocks: The try operator. It opens a new try-catch-block.  The catch(<exception_type>, <message>) operator. It closes the try-catch-block that was started last and haven't yet been closed. This block can be activated only via exception of type <exception_type>. When we activate this block, the screen displays the <message>. If at the given moment there is no open try-catch-block, then we can't use the catch operator.The exceptions can occur in the program in only one case: when we use the throw operator. The throw(<exception_type>) operator creates the exception of the given type.Let's suggest that as a result of using some throw operator the program created an exception of type a. In this case a try-catch-block is activated, such that this block's try operator was described in the program earlier than the used throw operator. Also, this block's catch operator was given an exception type a as a parameter and this block's catch operator is described later that the used throw operator. If there are several such try-catch-blocks, then the system activates the block whose catch operator occurs earlier than others. If no try-catch-block was activated, then the screen displays message "Unhandled Exception".To test the system, Vasya wrote a program that contains only try, catch and throw operators, one line contains no more than one operator, the whole program contains exactly one throw operator.Your task is: given a program in VPL, determine, what message will be displayed on the screen.

The first line contains a single integer: n (1 ≤ n ≤ 105) the number of lines in the program. Next n lines contain the program in language VPL. Each line contains no more than one operator. It means that input file can contain empty lines and lines, consisting only of spaces. The program contains only operators try, catch and throw. It is guaranteed that the program is correct. It means that each started try-catch-block was closed, the catch operators aren't used unless there is an open try-catch-block. The program has exactly one throw operator. The program may have spaces at the beginning of a line, at the end of a line, before and after a bracket, a comma or a quote mark. The exception type is a nonempty string, that consists only of upper and lower case english letters. The length of the string does not exceed 20 symbols. Message is a nonempty string, that consists only of upper and lower case english letters, digits and spaces. Message is surrounded with quote marks. Quote marks shouldn't be printed. The length of the string does not exceed 20 symbols. Length of any line in the input file does not exceed 50 symbols.

Print the message the screen will show after the given program is executed.

8
try
    try
        throw ( AE )
    catch ( BE, "BE in line 3")

    try
    catch(AE, "AE in line 5")
catch(AE,"AE somewhere")

8
try
    try
        throw ( AE )
    catch ( AE, "AE in line 3")

    try
    catch(BE, "BE in line 5")
catch(AE,"AE somewhere")

8
try
    try
        throw ( CE )
    catch ( BE, "BE in line 3")

    try
    catch(AE, "AE in line 5")
catch(AE,"AE somewhere")

AE somewhere
AE in line 3
Unhandled Exception

NoteIn the first sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(BE,"BE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so the second block will be activated, because operator catch(AE,"AE somewhere") has exception type AE as parameter and operator catch(BE,"BE in line 3") has exception type BE.In the second sample there are 2 try-catch-blocks such that try operator is described earlier than throw operator and catch operator is described later than throw operator: try-catch(AE,"AE in line 3") and try-catch(AE,"AE somewhere"). Exception type is AE, so both blocks can be activated, but only the first one will be activated, because operator catch(AE,"AE in line 3") is described earlier than catch(AE,"AE somewhere")In the third sample there is no blocks that can be activated by an exception of type CE.


Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches.The current state of the wall can be respresented by a sequence $$$a$$$ of $$$n$$$ integers, with $$$a_i$$$ being the height of the $$$i$$$-th part of the wall.Vova can only use $$$2 \times 1$$$ bricks to put in the wall (he has infinite supply of them, however).Vova can put bricks only horizontally on the neighbouring parts of the wall of equal height. It means that if for some $$$i$$$ the current height of part $$$i$$$ is the same as for part $$$i + 1$$$, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part $$$1$$$ of the wall or to the right of part $$$n$$$ of it).Note that Vova can't put bricks vertically.Vova is a perfectionist, so he considers the wall completed when:  all parts of the wall has the same height;  the wall has no empty spaces inside it. Can Vova complete the wall using any amount of bricks (possibly zero)?

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of parts in the wall. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the initial heights of the parts of the wall.

Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero). Print "NO" otherwise.

NoteIn the first example Vova can put a brick on parts 2 and 3 to make the wall $$$[2, 2, 2, 2, 5]$$$ and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it $$$[5, 5, 5, 5, 5]$$$.In the second example Vova can put no bricks in the wall.In the third example the wall is already complete.

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

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

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

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$a = $ir->readArrayOfInt($n,1);
$m = max($a);
$a[0] = $m;
$a[] = $m;

$stack = [];
$lh = $m;
for ($k=1; $k<=$n+1; $k++) {
	$v = $a[$k];
	if ($v<$lh) {
		$stack[] = [$k-1, $lh-$v];
		//var_dump($stack);

		$lh = $v;
	} elseif ($v>$lh) {
		$c = $v-$lh;
		while ($c>0) {
			//echo $c . "\n";
			$e = array_pop($stack);
			if (($k-$e[0]-1)%2==0) {
				$c -= $e[1];
				if ($c<0){
					$stack[]=[$e[0], $e[1]-$c];
				}
				//var_dump($stack);
			} else {
				echo 'NO';
				exit();
			}
		}
		$lh = $v;
	}
}

echo 'YES';

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

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

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

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$a = $ir->readArrayOfInt($n,1);
$m = max($a);
$a[0] = $m;
$a[] = $m;

$stack = [];
$lh = $m;
for ($k=1; $k<=$n; $k++) {
	$v = $a[$k];
	if ($v<$lh) {
		$stack[] = [$k-1, $lh-$v];
		//var_dump($stack);

		$lh = $v;
	} elseif ($v>$lh) {
		$c = $v-$lh;
		while ($c>0) {
			echo $c . "\n";
			$e = array_pop($stack);
			if (($k-$e[0]-1)%2==0) {
				$c -= $e[1];
				if ($c<0){
					$stack[]=[$e[0], $e[1]-$c];
				}
				//var_dump($stack);
			} else {
				echo 'NO';
				exit();
			}
		}
		$lh = $v;
	}
}

echo 'YES';

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

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

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

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

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

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

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

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$a = $ir->readArrayOfInt($n,1);
$m = max($a);
$a[0] = $m;
$a[] = $m;

$stack = [];
$lh = $m;
for ($k=1; $k<=$n; $k++) {
	$v = $a[$k];
	if ($v<$lh) {
		$stack[] = [$k-1, $lh-$v];
		//var_dump($stack);

		$lh = $v;
	} elseif ($v>$lh) {
		$c = $v-$lh;
		while ($c>0) {
			//echo $c . "\n";
			$e = array_pop($stack);
			if (($k-$e[0]-1)%2==0) {
				$c -= $e[1];
				if ($c<0){
					$stack[]=[$e[0], $e[1]-$c];
				}
				//var_dump($stack);
			} else {
				echo 'NO';
				exit();
			}
		}
		$lh = $v;
	}
}

echo 'YES';


School holidays come in Berland. The holidays are going to continue for n days. The students of school №N are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State Examination) results, has finally taken a vacation break! Some people are in charge of the daily watering of flowers in shifts according to the schedule. However when Marina Sergeyevna was making the schedule, she was so tired from work and so lost in dreams of the oncoming vacation that she perhaps made several mistakes. In fact, it is possible that according to the schedule, on some days during the holidays the flowers will not be watered or will be watered multiple times. Help Marina Sergeyevna to find a mistake.

The first input line contains two numbers n and m (1 ≤ n, m ≤ 100) — the number of days in Berland holidays and the number of people in charge of the watering respectively. The next m lines contain the description of the duty schedule. Each line contains two integers ai and bi (1 ≤ ai ≤ bi ≤ n), meaning that the i-th person in charge should water the flowers from the ai-th to the bi-th day inclusively, once a day. The duty shifts are described sequentially, i.e. bi ≤ ai + 1 for all i from 1 to n - 1 inclusively.

Print "OK" (without quotes), if the schedule does not contain mistakes. Otherwise you have to find the minimal number of a day when the flowers will not be watered or will be watered multiple times, and output two integers — the day number and the number of times the flowers will be watered that day.

NoteKeep in mind that in the second sample the mistake occurs not only on the second day, but also on the sixth day, when nobody waters the flowers. However, you have to print the second day, i.e. the day with the minimal number.


Given an array $$$a=[a_1,a_2,\dots,a_n]$$$ of $$$n$$$ positive integers, you can do operations of two types on it:  Add $$$1$$$ to every element with an odd index. In other words change the array as follows: $$$a_1 := a_1 +1, a_3 := a_3 + 1, a_5 := a_5+1, \dots$$$.  Add $$$1$$$ to every element with an even index. In other words change the array as follows: $$$a_2 := a_2 +1, a_4 := a_4 + 1, a_6 := a_6+1, \dots$$$.Determine if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers. In other words, determine if you can make all elements of the array have the same parity after any number of operations.Note that you can do operations of both types any number of times (even none). Operations of different types can be performed a different number of times.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ ($$$2 \leq n \leq 50$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^3$$$) — the elements of the array. Note that after the performed operations the elements in the array can become greater than $$$10^3$$$.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. As an answer, output "YES" if after any number of operations it is possible to make the final array contain only even numbers or only odd numbers, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteFor the first test case, we can increment the elements with an even index, obtaining the array $$$[1, 3, 1]$$$, which contains only odd numbers, so the answer is "YES".For the second test case, we can show that after performing any number of operations we won't be able to make all elements have the same parity, so the answer is "NO".For the third test case, all elements already have the same parity so the answer is "YES".For the fourth test case, we can perform one operation and increase all elements at odd positions by $$$1$$$, thus obtaining the array $$$[1001, 1, 1001, 1, 1001]$$$, and all elements become odd so the answer is "YES".

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fgets(STDIN);
    $arr = [];
    $result = 'YES';
    foreach (fgetcsv(STDIN, 0, ' ') as $key => $value) {
     if (($value&1) != ($arr[$key&1] ?? ($arr[$key&1] = $value&1))) {
         $result = 'NO';
         break;
     }
    }
    echo $result, "\n";
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fgets(STDIN);
    $arr = [];
    $result = 'YES';
    foreach (fgetcsv(STDIN, 0, ' ') as $key => $value) {
        if ($value&1 != ($arr[$key&1] ?? ($arr[$key&1] = $value&1))) {
            $result = 'NO';
            break;
        }
    }
    echo $result, "\n";
}


Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly n characters.   Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the i-th letter of her name should be 'O' (uppercase) if i is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to n. Fibonacci sequence is the sequence f where  f1 = 1,  f2 = 1,  fn = fn - 2 + fn - 1 (n > 2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name.

The first and only line of input contains an integer n (1 ≤ n ≤ 1000).

Print Eleven's new name on the first and only line of output.

<?php

// თუ თავი შენი შენ გახლავს, ღარიბად არ იხსენები.

// მადლობა გუგას ანდაზისათვის ( : )

$n = fgets(STDIN);

$fib1 =1;
$fib2 =1;

$arr[1]=1;

for($i=1;$i<1001;$i++){
      $fib = $fib2;
      $fib2 = $fib2 + $fib1;
      $fib1 = $fib;
      $arr[$fib]=1;
}

for($i=1;$i<=$n;$i++)
      if(array_key_exists($i,$arr))
            echo 'O';
      else
            echo 'o';

?>


You are given an array $$$a$$$ of $$$n$$$ positive integers.You can use the following operation as many times as you like: select any integer $$$1 \le k \le n$$$ and do one of two things:   decrement by one $$$k$$$ of the first elements of the array.  decrement by one $$$k$$$ of the last elements of the array. For example, if $$$n=5$$$ and $$$a=[3,2,2,1,4]$$$, then you can apply one of the following operations to it (not all possible options are listed below):   decrement from the first two elements of the array. After this operation $$$a=[2, 1, 2, 1, 4]$$$;  decrement from the last three elements of the array. After this operation $$$a=[3, 2, 1, 0, 3]$$$;  decrement from the first five elements of the array. After this operation $$$a=[2, 1, 1, 0, 3]$$$; Determine if it is possible to make all the elements of the array equal to zero by applying a certain number of operations.

The first line contains one positive integer $$$t$$$ ($$$1 \le t \le 30000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case begins with a line containing one integer $$$n$$$ ($$$1 \le n \le 30000$$$) — the number of elements in the array. The second line of each test case contains $$$n$$$ integers $$$a_1 \ldots a_n$$$ ($$$1 \le a_i \le 10^6$$$). The sum of $$$n$$$ over all test cases does not exceed $$$30000$$$.

For each test case, output on a separate line:    YES, if it is possible to make all elements of the array equal to zero by applying a certain number of operations.  NO, otherwise.  The letters in the words YES and NO can be outputed in any case.

<?php
$T = fgets(STDIN);
for($t = 0; $t < $T; $t++) {
    $n = fgets(STDIN);
    $a = explode(" ", trim(fgets(STDIN)));
    $mn = $a[0];
    $minus = 0;
    $answer = "YES";
    for($i = 1; $i < $n; $i++) {

        $a[$i] -= $minus;
        if($a[$i] < 0) {
            $answer = "NO";
            break;
        }
        if($a[$i] > $mn) {
            $minus += $a[$i] - $mn;
        }
        $mn = min($mn, $a[$i]);
    }
    echo ($answer)."\n";
}

?>


A PIN code is a string that consists of exactly $$$4$$$ digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.Polycarp has $$$n$$$ ($$$2 \le n \le 10$$$) bank cards, the PIN code of the $$$i$$$-th card is $$$p_i$$$.Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all $$$n$$$ codes would become different.Formally, in one step, Polycarp picks $$$i$$$-th card ($$$1 \le i \le n$$$), then in its PIN code $$$p_i$$$ selects one position (from $$$1$$$ to $$$4$$$), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different.Polycarp quickly solved this problem. Can you solve it?

The first line contains integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then test cases follow. The first line of each of $$$t$$$ test sets contains a single integer $$$n$$$ ($$$2 \le n \le 10$$$) — the number of Polycarp's bank cards. The next $$$n$$$ lines contain the PIN codes $$$p_1, p_2, \dots, p_n$$$ — one per line. The length of each of them is $$$4$$$. All PIN codes consist of digits only.

Print the answers to $$$t$$$ test sets. The answer to each set should consist of a $$$n + 1$$$ lines In the first line print $$$k$$$ — the least number of changes to make all PIN codes different. In the next $$$n$$$ lines output the changed PIN codes in the order corresponding to their appearance in the input. If there are several optimal answers, print any of them.


Alicia has an array, $$$a_1, a_2, \ldots, a_n$$$, of non-negative integers. For each $$$1 \leq i \leq n$$$, she has found a non-negative integer $$$x_i = max(0, a_1, \ldots, a_{i-1})$$$. Note that for $$$i=1$$$, $$$x_i = 0$$$.For example, if Alicia had the array $$$a = \{0, 1, 2, 0, 3\}$$$, then $$$x = \{0, 0, 1, 2, 2\}$$$.Then, she calculated an array, $$$b_1, b_2, \ldots, b_n$$$: $$$b_i = a_i - x_i$$$.For example, if Alicia had the array $$$a = \{0, 1, 2, 0, 3\}$$$, $$$b = \{0-0, 1-0, 2-1, 0-2, 3-2\} = \{0, 1, 1, -2, 1\}$$$.Alicia gives you the values $$$b_1, b_2, \ldots, b_n$$$ and asks you to restore the values $$$a_1, a_2, \ldots, a_n$$$. Can you help her solve the problem?

The first line contains one integer $$$n$$$ ($$$3 \leq n \leq 200\,000$$$) – the number of elements in Alicia's array. The next line contains $$$n$$$ integers, $$$b_1, b_2, \ldots, b_n$$$ ($$$-10^9 \leq b_i \leq 10^9$$$). It is guaranteed that for the given array $$$b$$$ there is a solution $$$a_1, a_2, \ldots, a_n$$$, for all elements of which the following is true: $$$0 \leq a_i \leq 10^9$$$.

Print $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$), such that if you calculate $$$x$$$ according to the statement, $$$b_1$$$ will be equal to $$$a_1 - x_1$$$, $$$b_2$$$ will be equal to $$$a_2 - x_2$$$, ..., and $$$b_n$$$ will be equal to $$$a_n - x_n$$$. It is guaranteed that there exists at least one solution for the given tests. It can be shown that the solution is unique.

<?php
    define("MAXN", 1024) ;
    define("GAP_VAL", 1e-7) ;

    function gap($n)
    {
        return $n < GAP_VAL ;
    }

//     $t = intval(trim(fgets(STDIN))) ;
//     while($t --)
//     {
//         $n = intval(trim(fgets(STDIN))) ;

//         if($n == 1) echo "-1\n" ;
//         else echo str_repeat("5", $n - 1) . "4\n" ;
//     }
    $n = intval(trim(fgets(STDIN))) ;

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

    $b = array() ;

    array_push($b, intval($in_str[0])) ;
    $x = 0 ;
    for($i = 1; $i < $n; $i ++)
    {
        $in_str[$i] = intval($in_str[$i]) ;

        $x = max($x, $b[$i - 1]) ;
        array_push($b, $in_str[$i] + $x) ;
    }

    echo implode(" ", $b) . "\n" ;
?>