According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time n snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top.Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower.  However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it.Write a program that models the behavior of Ankh-Morpork residents.

The first line contains single integer n (1 ≤ n ≤ 100 000) — the total number of snacks. The second line contains n integers, the i-th of them equals the size of the snack which fell on the i-th day. Sizes are distinct integers from 1 to n.

Print n lines. On the i-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the i-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty.

NoteIn the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right after that they placed the snack of size 1 which had fallen before.


You are given a sequence of $$$n$$$ digits $$$d_1d_2 \dots d_{n}$$$. You need to paint all the digits in two colors so that:  each digit is painted either in the color $$$1$$$ or in the color $$$2$$$;  if you write in a row from left to right all the digits painted in the color $$$1$$$, and then after them all the digits painted in the color $$$2$$$, then the resulting sequence of $$$n$$$ digits will be non-decreasing (that is, each next digit will be greater than or equal to the previous digit). For example, for the sequence $$$d=914$$$ the only valid coloring is $$$211$$$ (paint in the color $$$1$$$ two last digits, paint in the color $$$2$$$ the first digit). But $$$122$$$ is not a valid coloring ($$$9$$$ concatenated with $$$14$$$ is not a non-decreasing sequence).It is allowed that either of the two colors is not used at all. Digits painted in the same color are not required to have consecutive positions.Find any of the valid ways to paint the given sequence of digits or determine that it is impossible to do.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10000$$$) — the number of test cases in the input. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — the length of a given sequence of digits. The next line contains a sequence of $$$n$$$ digits $$$d_1d_2 \dots d_{n}$$$ ($$$0 \le d_i \le 9$$$). The digits are written in a row without spaces or any other separators. The sequence can start with 0. It is guaranteed that the sum of the values of $$$n$$$ for all test cases in the input does not exceed $$$2\cdot10^5$$$.

Print $$$t$$$ lines — the answers to each of the test cases in the input. If there is a solution for a test case, the corresponding output line should contain any of the valid colorings written as a string of $$$n$$$ digits $$$t_1t_2 \dots t_n$$$ ($$$1 \le t_i \le 2$$$), where $$$t_i$$$ is the color the $$$i$$$-th digit is painted in. If there are several feasible solutions, print any of them. If there is no solution, then the corresponding output line should contain a single character '-' (the minus sign).

NoteIn the first test case, $$$d=040425524644$$$. The output $$$t=121212211211$$$ is correct because $$$0022444$$$ (painted in $$$1$$$) concatenated with $$$44556$$$ (painted in $$$2$$$) is $$$002244444556$$$ which is a sorted sequence of $$$n$$$ given digits.


You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).

For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.

NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.

<?php
$f=fopen('php://stdin','r');
$tot = fgets($f);
//printf("Tot: %d\n",$tot);
for($t=1;$t<=$tot;++$t)
{
    $n=fgets($f);
    //printf("\tn: %d\n",$n);
    $line=fgets($f);
    $an = explode(' ',$line);
    //print_r($an);
    if(ok($an,0,1))
    {
        printf("1\n1\n");
    }elseif(ok($an,1,1))
    {
        printf("1\n2\n");
    }elseif(ok($an,0,2))
    {
        printf("2\n1 2\n");
    }else
    {
        printf("-1\n");
    }
}
fclose($f);

function ok($A,$pos,$len)
{
    if($pos+$len>count($A))
        return false;

    $sum=0;
    for($i=0;$i<$len;$i++)
    {
        $val = $A[$i+$pos];
        $sum += (int)$val;
    }
    return $sum % 2 == 0;
}

?>

<?php
$f=fopen('php://stdin','r');
$tot = fgets($f);
//printf("Tot: %d\n",$tot);
for($t=1;$t<=$tot;++$t)
{
    $n=fgets($f);
    //printf("\tn: %d\n",$n);
    $line=fgets($f);
    $an = explode(' ',$line);
    //print_r($an);
    if(ok($an,0,1))
    {
        echo "case 0 1\n";
        printf("1\n1\n");
    }elseif(ok($an,1,1))
    {
        echo "case 1 1\n";
        printf("1\n2\n");
    }elseif(ok($an,0,2))
    {
        echo "case 0 2\n";
        printf("2\n1 2\n");
    }else
    {
        printf("-1\n");
    }
}
fclose($f);

function ok($A,$pos,$len)
{
    if($pos+$len>count($A))
        return false;

    $sum=0;
    for($i=0;$i<$len;$i++)
    {
        $val = $A[$i+$pos];
        $sum += (int)$val;
    }
    return $sum % 2 == 0;
}

?>


Alice is playing with some stones.Now there are three numbered heaps of stones. The first of them contains $$$a$$$ stones, the second of them contains $$$b$$$ stones and the third of them contains $$$c$$$ stones.Each time she can do one of two operations:  take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);  take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones). She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has $$$0$$$ stones. Can you help her?

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases. Next $$$t$$$ lines describe test cases in the following format: Line contains three non-negative integers $$$a$$$, $$$b$$$ and $$$c$$$, separated by spaces ($$$0 \leq a,b,c \leq 100$$$) — the number of stones in the first, the second and the third heap, respectively. In hacks it is allowed to use only one test case in the input, so $$$t = 1$$$ should be satisfied.

Print $$$t$$$ lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer  — the maximum possible number of stones that Alice can take after making some operations.

NoteFor the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is $$$9$$$. It is impossible to make some operations to take more than $$$9$$$ stones, so the answer is $$$9$$$.

<?php
function solve()
{
    $server = "php://stdin";
    $local = "input.txt";
    $handle = fopen($server, "r");
    $a = ['a', 'b', 'c'];
    $t = trim(fgets($handle));
    for ($i = 0; $i < $t; $i++) {
        $s = trim(fgets($handle));
        $a=explode(' ',$s);
        $sum=0;
        $ans=(int)($a[2]/2);
        if($ans>$a[1])
        {
            $new=0;
            $sum=$sum+$a[1];
        }
        else
        {
            $sum=$sum+$ans;
            $new=$a[1]-$ans;
        }

        $ans1=(int)($new/2);
        if($ans1>$a[0])
        {
            $new1=0;
            $sum=$sum+$a[0];
        }else
        {
            $sum=$sum+$ans1;
        }
        echo $sum*3;
        echo "\n";
    }
}

solve();
?>

<?php
function solve()
{
    $server = "php://stdin";
    $local = "input.txt";
    $handle = fopen($server, "r");
    $a = ['a', 'b', 'c'];
    $t = trim(fgets($handle));
    for ($i = 0; $i < $t; $i++) {
        $s = trim(fgets($handle));
        $a=explode(' ',$s);
        $sum=0;
        $ans=(int)($a[2]/2);
        if($ans>$a[1])
        {
            $new=0;
            $sum=$sum+$a[1];
        }else
        {
            $sum=$sum+$ans;
            $new=$a[1]-$ans;
        }
        $ans1=(int)($new/2);
        if($ans1>$a[0])
        {
            $new1=0;
            $sum=$sum+$ans1;
        }else
        {
            $sum=$sum+$ans1;
        }
        echo $sum*3;
        echo "\n";
    }
}

solve();
?>


George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers b. During the game, George modifies the array by using special changes. Let's mark George's current array as b1, b2, ..., b|b| (record |b| denotes the current length of the array). Then one change is a sequence of actions:   Choose two distinct indexes i and j (1 ≤ i, j ≤ |b|; i ≠ j), such that bi ≥ bj.  Get number v = concat(bi, bj), where concat(x, y) is a number obtained by adding number y to the end of the decimal record of number x. For example, concat(500, 10) = 50010, concat(2, 2) = 22.  Add number v to the end of the array. The length of the array will increase by one.  Remove from the array numbers with indexes i and j. The length of the array will decrease by two, and elements of the array will become re-numbered from 1 to current length of the array. George played for a long time with his array b and received from array b an array consisting of exactly one number p. Now George wants to know: what is the maximum number of elements array b could contain originally? Help him find this number. Note that originally the array could contain only positive integers.

The first line of the input contains a single integer p (1 ≤ p < 10100000). It is guaranteed that number p doesn't contain any leading zeroes.

Print an integer — the maximum number of elements array b could contain originally.

NoteLet's consider the test examples:   Originally array b can be equal to {5, 9, 5, 5}. The sequence of George's changes could have been: {5, 9, 5, 5} → {5, 5, 95} → {95, 55} → {9555}.  Originally array b could be equal to {1000000000, 5}. Please note that the array b cannot contain zeros.  Originally array b could be equal to {800, 10, 1}.  Originally array b could be equal to {45}. It cannot be equal to {4, 5}, because George can get only array {54} from this array in one operation. Note that the numbers can be very large.


Polycarpus has n markers and m marker caps. Each marker is described by two numbers: xi is the color and yi is the diameter. Correspondingly, each cap is described by two numbers: aj is the color and bj is the diameter. Cap (aj, bj) can close marker (xi, yi) only if their diameters match, that is, bj = yi. Besides, a marker is considered to be beautifully closed, if the cap color and the marker color match, that is, aj = xi.Find the way to close the maximum number of markers. If there are several such ways, then choose the one that has the maximum number of beautifully closed markers.

The first input line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of markers and the number of caps, correspondingly.  Next n lines describe the markers. The i-th line contains two space-separated integers xi, yi (1 ≤ xi, yi ≤ 1000) — the i-th marker's color and diameter, correspondingly. Next m lines describe the caps. The j-th line contains two space-separated integers aj, bj (1 ≤ aj, bj ≤ 1000) — the color and diameter of the j-th cap, correspondingly.

Print two space-separated integers u, v, where u is the number of closed markers and v is the number of beautifully closed markers in the sought optimal way. Remember that you have to find the way to close the maximum number of markers, and if there are several such ways, you should choose the one where the number of beautifully closed markers is maximum.

NoteIn the first test sample the first marker should be closed by the fourth cap, the second marker should be closed by the first cap and the third marker should be closed by the second cap. Thus, three markers will be closed, and two of them will be beautifully closed — the first and the third markers.

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

list($n,$m) = explode(' ', $line1);
$n = (int) $n;
$m = (int) $m;

$i=0;
while($i<$n)
{
    $line = trim(fgets(STDIN));
    list($x,$y) = explode(' ', $line);

    if(isset($flom[$y]))
        $flom[$y]['cnt']++;
    else
        $flom[$y]['cnt'] = 1;

    if(isset($flom[$y]['color'][$x]))
        $flom[$y]['color'][$x]++;
    else
        $flom[$y]['color'][$x] = 1;
    $i++;
}

$i=0;
while($i<$m)
{
    $line = trim(fgets(STDIN));
    list($y,$x) = explode(' ', $line);

    if(isset($kolp[$x]))
        $kolp[$x]['cnt']++;
    else
        $kolp[$x]['cnt'] = 1;

    if(isset($kolp[$x]['color'][$y]))
        $kolp[$x]['color'][$y]++;
    else
        $kolp[$x]['color'][$y] = 1;
    $i++;
}

$u = 0;
$v = 0;
foreach($flom as $k => $val)
{
    if(isset($kolp[$k]['cnt']))
    {
        $u += min($val['cnt'],$kolp[$k]['cnt']);
        foreach($val['color'] as $k1 => $v1)
            if(isset($kolp[$k]['color'][$k1]))
                $v += min($v1,$kolp[$k]['color'][$k1]);
    }
}
fputs(STDOUT, $u." ".$v);
?>

<?php
error_reporting(0);

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

$flomasters = array();
$flomastersAll = array();
while( $n-- ){
	$flom = explode( " ", trim( str_replace( "\r\n", '', fgets($fp) ) ) );
	$flomasters[ $flom[1] ][ $flom[0] ]++;
	$flomastersAll[ $flom[1] ]++;
}

$caps = array();
$nonFormat = array();
$v = 0;
while( $m-- ){
	$cap = explode( " ", trim( str_replace( "\r\n", '', fgets($fp) ) ) );
	if( $flomasters[ $cap[1] ][ $cap[0] ] >= 1 ) {
		$flomasters[ $cap[1] ][ $cap[0] ] --;
		$v++;
		$flomastersAll[ $cap[1] ]--;
	} else {
		$nonFormat[ $cap[1] ]++;
	}
}

$u = $v;
foreach( $nonFormat as $key => $value ){
	$u += min( $flomastersAll[ $key ], $value);
}
echo $u . " " . $v;

fclose($fp);
?>

<?php

$input = STDIN;

$pens = array();
$penCount = array();
fscanf($input, "%d %d\n", $n, $m);
for($i=0; $i<$n; $i++) {
	fscanf($input, "%d %d\n", $color, $diameter);

	if (!isset($pens[$diameter][$color])) {
		$pens[$diameter][$color] = 1;
	} else {
		++$pens[$diameter][$color];
	}

	if (!isset($penCount[$diameter])) {
		$penCount[$diameter] = 1;
	} else {
		++$penCount[$diameter];
	}
}

$fail = array();
$nice = 0;
for ($i=0; $i<$m; $i++) {
	fscanf($input, "%d %d\n", $color, $diameter);

	if (!isset($fail[$diameter])) $fail[$diameter] = 0;

	if (!isset($pens[$diameter][$color]) || $pens[$diameter][$color] == 0) {
		++$fail[$diameter];
		continue;
	}
	if($pens[$diameter][$color] > 0) {
		--$pens[$diameter][$color];
		--$penCount[$diameter];
		++$nice;
	}
}

$total = $nice;
foreach($penCount as $diameter => $count) {
	if (isset($fail[$diameter])) {
		$total += ($count > $fail[$diameter]) ? $fail[$diameter] : $count;
	}
}

echo "$total $nice\n";
?>

<?php

$closed = 0;
$beautiful = 0;
error_reporting(0);

$stdin = fopen("php://stdin", "r");
$line1 = trim(fgets($stdin));
$line1Array = explode(' ', $line1);
$n = (int)$line1Array[0];
$m = (int)$line1Array[1];

$markers = array();
for($i = 0; $i < $n; $i++) {
    $marker = trim(fgets($stdin));
    $marker = explode(' ', $marker);

    $markers[$marker[1]]["closed"]++;
    $markers[$marker[1]][$marker[0]]++;
}

//var_dump($markers);

$caps = array();
for($i = 0; $i < $m; $i++) {
    $caps[$i] = trim(fgets($stdin));
    $caps[$i] = explode(' ', $caps[$i]);

    $size = $caps[$i][1];
    $color = $caps[$i][0];
    if( $markers[$size][$color] > 0) {
        $beautiful++;
        $closed++;
        $markers[$size][$color]--;
        $markers[$size]["closed"]--;
        unset($caps[$i]);
    }

}

foreach($caps as $cap) {
    if( $markers[$cap[1]]["closed"] > 0 ) {
        $closed++;
        $markers[$cap[1]]["closed"]--;
    }
}

echo $closed. " ".$beautiful;

?>

<?php
$arr = array();
while ($line = trim(fgets(STDIN)))
    $arr[] = $line;
$count = explode(' ', $arr[0]);
$CountMarker[0] = 0;
$CountMarker[1] = 0;
$CountColor = array();
$StackBad = array();
$curr = array();
$res = array();
for ($i = 1; $i <= $count[0]; $i++) {
    $exp = explode(" ", $arr[$i]);
    if(isset($curr[$exp[1]][$exp[0]]))
        $curr[$exp[1]][$exp[0]]++;
    else
        $curr[$exp[1]][$exp[0]] = 1;
    if(isset($CountColor[$exp[1]]))
        $CountColor[$exp[1]]++;
    else
        $CountColor[$exp[1]] = 1;
}
for ($i = $count[0] + 1; $i <= $count[0] + $count[1]; $i++) {
    $exp = explode(" ", $arr[$i]);
    if(isset($curr[$exp[1]][$exp[0]]) && $curr[$exp[1]][$exp[0]] > 0){
        $curr[$exp[1]][$exp[0]]--;
        $CountColor[$exp[1]]--;
        $CountMarker[0]++;
        $CountMarker[1]++;
    } else{
        if(isset($StackBad[$exp[1]]))
            $StackBad[$exp[1]]++;
        else
            $StackBad[$exp[1]] = 1;
    }
}
foreach($StackBad AS $key => $value){
    if($CountColor[$key] >= $value)
        $CountMarker[0]+= $value;
    else
        $CountMarker[0]+= $CountColor[$key];
}
echo $CountMarker[0]. ' '. $CountMarker[1] . "\n";

<?php
fscanf(STDIN, "%d %d\n", $iMarkers, $iCaps);

$aMarkers = array();
$aCaps = array();
$aUnbeautifulMarkers = array();
$aUnbeautifulCaps = array();
$iBeautifulCappedMarkers = 0;
$iCappedMarkers = 0;

for ($i = 1; $i <= $iMarkers; $i ++) {
	fscanf(STDIN, "%d %d", $iColor, $iDiameter);

	if (!isset($aMarkers[$iDiameter])) {
		$aMarkers[$iDiameter] = array();
		$aUnbeautifulMarkers[$iDiameter] = 1;
	} else {
		$aUnbeautifulMarkers[$iDiameter] += 1;
	}

	if (isset($aMarkers[$iDiameter][$iColor])) {
		$aMarkers[$iDiameter][$iColor] += 1;
	} else {
		$aMarkers[$iDiameter][$iColor] = 1;
	}
}

for ($i = 1; $i <= $iCaps; $i ++) {
	fscanf(STDIN, "%d %d", $iColor, $iDiameter);

	if (!isset($aCaps[$iDiameter])) {
		$aCaps[$iDiameter] = array();
		$aUnbeautifulCaps[$iDiameter] = 1;
	} else {
		$aUnbeautifulCaps[$iDiameter] += 1;
	}

	if (isset($aCaps[$iDiameter][$iColor])) {
		$aCaps[$iDiameter][$iColor] += 1;
	} else {
		$aCaps[$iDiameter][$iColor] = 1;
	}
}

foreach ($aMarkers as $iMarkerDiameter => $aMarkerColors) {
	foreach ($aMarkerColors as $iMarkerColor => $iTheMarkers) {

		if (isset($aCaps[$iMarkerDiameter][$iMarkerColor]) && $aCaps[$iMarkerDiameter][$iMarkerColor] > 0) {
			$iTheCaps = $aCaps[$iMarkerDiameter][$iMarkerColor];
			$iCapped = min($iTheCaps, $iTheMarkers);

			$iBeautifulCappedMarkers += $iCapped;
		}
	}
}

foreach ($aUnbeautifulMarkers as $iMarkerDiameter => $iTheMarkers) {
	if (isset($aUnbeautifulCaps[$iMarkerDiameter]) && $aUnbeautifulCaps[$iMarkerDiameter] > 0) {
		$iTheCaps = $aUnbeautifulCaps[$iMarkerDiameter];

		$iCapped = min($iTheCaps, $iTheMarkers);

		$iCappedMarkers += $iCapped;
	}
}

echo $iCappedMarkers . ' ' . $iBeautifulCappedMarkers;

<?php
error_reporting("off");
//159B: Matchmaker
list($n, $m) = explode(" ", trim(fgets(STDIN)));
$y = array();
$b = array();
$markerhash = array();
$caphash = array();
$capped = 0;
$beautifully = 0;
for ($i = 0; $i < $n; $i++) {
    list($color, $d) = explode(" ", trim(fgets(STDIN)));
    $y[] = $d;
    $markerhash[] = $d * 10000 + $color;
}
for ($i = 0; $i < $m; $i++) {
    list($color, $d) = explode(" ", trim(fgets(STDIN)));
    $b[] = $d;
    $caphash[] = $d * 10000 + $color;
}

$markerdiameters = array_count_values($y);
$capdiameters = array_count_values($b);

foreach ($markerdiameters as $key => $value) {
    if (isset($capdiameters[$key])) {
        $tmp = array();
        $tmp[] = $capdiameters[$key];
        $tmp[] = $markerdiameters[$key];
        $capped += min($tmp);
    }
}

$mhashcount = array_count_values($markerhash);
$chashcount = array_count_values($caphash);

foreach ($mhashcount as $key => $value) {
    if (isset($chashcount[$key])) {
        $tmp = array();
        $tmp[] = $chashcount[$key];
        $tmp[] = $mhashcount[$key];
        $beautifully += min($tmp);
    }
}

echo $capped." ".$beautifully;
?>

<?php

$closed = 0;
$beautiful = 0;
error_reporting(0);

$stdin = fopen("php://stdin", "r");
$line1 = trim(fgets($stdin));
$line1Array = explode(' ', $line1);
$n = (int)$line1Array[0];
$m = (int)$line1Array[1];

$markers = array();
for($i = 0; $i < $n; $i++) {
    $marker = trim(fgets($stdin));
    $marker = explode(' ', $marker);

    $markers[$marker[1]]["closed"]++;
    $markers[$marker[1]][$marker[0]]++;
}

//var_dump($markers);

$caps = array();
for($i = 0; $i < $m; $i++) {
    $caps[$i] = trim(fgets($stdin));
    $caps[$i] = explode(' ', $caps[$i]);

    if( $markers[ $caps[$i][1] ][ $caps[$i][0] ] > 0) {
        $beautiful++;
        $closed++;
        $markers[ $caps[$i][1] ][ $caps[$i][0] ]--;
        $markers[ $caps[$i][1] ]["closed"]--;
    }
    elseif( $markers[ $caps[$i][1] ]["closed"] > 0 ) {
        $closed++;
        $markers[ $caps[$i][1] ][ $caps[$i][0] ]--;
        $markers[ $caps[$i][1] ]["closed"]--;
    }
}

echo $closed. " ".$beautiful;

/*
5 5
1 5
2 4
1 5
3 4
1 6
3 4
2 4
6 4
8 5
1 6

5: [1]
4: [2,3]
6: [1]
*/

/*

5 5
1 2
1 3
1 2
1 3
1 3
1 2
1 2
1 3
1 2
1 2

*/

?>


The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company and the goods it produces) or its components: the name, the logo, the slogan. They decided to start with the name.For this purpose the corporation has consecutively hired m designers. Once a company hires the i-th designer, he immediately contributes to the creation of a new corporation name as follows: he takes the newest version of the name and replaces all the letters xi by yi, and all the letters yi by xi. This results in the new version. It is possible that some of these letters do no occur in the string. It may also happen that xi coincides with yi. The version of the name received after the work of the last designer becomes the new name of the corporation.Manager Arkady has recently got a job in this company, but is already soaked in the spirit of teamwork and is very worried about the success of the rebranding. Naturally, he can't wait to find out what is the new name the Corporation will receive.Satisfy Arkady's curiosity and tell him the final version of the name.

The first line of the input contains two integers n and m (1 ≤ n, m ≤ 200 000) — the length of the initial name and the number of designers hired, respectively. The second line consists of n lowercase English letters and represents the original name of the corporation. Next m lines contain the descriptions of the designers' actions: the i-th of them contains two space-separated lowercase English letters xi and yi.

11 6
abacabadaba
a b
b c
a d
e g
f a
b b

NoteIn the second sample the name of the corporation consecutively changes as follows:

<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
list($n, $m) = explode(" ", trim(fgets($file)));
$s = trim(fgets($file));
$aArray = array_fill(ord('a'), 26, array());
for ($i = 0; $i < $n; $i++) {
    $aArray[ord($s[$i])][] = $i;
}
while ($m--) {
    list($x, $y) = explode(" ", trim(fgets($file)));
    $x = ord($x);
    $y = ord($y);
    $temp = $aArray[$x];
    $aArray[$x] = $aArray[$y];
    $aArray[$y] = $temp;
}
$o = array();
foreach ($aArray as $c => $pArray) {
    if (count($pArray)==0) {
        continue;
    }
    foreach ($pArray as $p) {
        $o[$p] = chr($c);
    }
}
for ($i = 0; $i < $n; $i++) {
    echo $o[$i];
}


In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.For example, for n = 4 the sum is equal to  - 1 - 2 + 3 - 4 =  - 4, because 1, 2 and 4 are 20, 21 and 22 respectively.Calculate the answer for t values of n.

The first line of the input contains a single integer t (1 ≤ t ≤ 100) — the number of values of n to be processed. Each of next t lines contains a single integer n (1 ≤ n ≤ 109).

Print the requested sum for each of t integers n given in the input.

NoteThe answer for the first sample is explained in the statement.

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = 0;
     $d = 0;
     while(TRUE)
     {
          $e = pow(2, $d);
          $d++;
          $c += $e;
          if($e == $b)
          {
               break;
          }
          elseif($e > $b)
          {
               $c -= $e;
               break;
          }
     }
     $f = bcdiv(bcmul($b, bcadd($b, 1)), 2);
     $f = bcsub($f, bcmul($c, 2));
     print $f . "\n";
}
?>


This is the easy version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.Tokitsukaze has a binary string $$$s$$$ of length $$$n$$$, consisting only of zeros and ones, $$$n$$$ is even.Now Tokitsukaze divides $$$s$$$ into the minimum number of contiguous subsegments, and for each subsegment, all bits in each subsegment are the same. After that, $$$s$$$ is considered good if the lengths of all subsegments are even.For example, if $$$s$$$ is "11001111", it will be divided into "11", "00" and "1111". Their lengths are $$$2$$$, $$$2$$$, $$$4$$$ respectively, which are all even numbers, so "11001111" is good. Another example, if $$$s$$$ is "1110011000", it will be divided into "111", "00", "11" and "000", and their lengths are $$$3$$$, $$$2$$$, $$$2$$$, $$$3$$$. Obviously, "1110011000" is not good.Tokitsukaze wants to make $$$s$$$ good by changing the values of some positions in $$$s$$$. Specifically, she can perform the operation any number of times: change the value of $$$s_i$$$ to '0' or '1'($$$1 \leq i \leq n$$$). Can you tell her the minimum number of operations to make $$$s$$$ good?

The first contains a single positive integer $$$t$$$ ($$$1 \leq t \leq 10\,000$$$) — the number of test cases. For each test case, the first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$) — the length of $$$s$$$, it is guaranteed that $$$n$$$ is even. The second line contains a binary string $$$s$$$ of length $$$n$$$, consisting only of zeros and ones. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single line with one integer — the minimum number of operations to make $$$s$$$ good.

NoteIn the first test case, one of the ways to make $$$s$$$ good is the following.Change $$$s_3$$$, $$$s_6$$$ and $$$s_7$$$ to '0', after that $$$s$$$ becomes "1100000000", it can be divided into "11" and "00000000", which lengths are $$$2$$$ and $$$8$$$ respectively. There are other ways to operate $$$3$$$ times to make $$$s$$$ good, such as "1111110000", "1100001100", "1111001100".In the second, third and fourth test cases, $$$s$$$ is good initially, so no operation is required.

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

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

  for($q=0; $q <$t; $q++) {
      $ans = 0;
      $n = getT();
      $s = getT();

    $tt = 0;
    $it = $s[0];
    $a[$tt] = 1;
    for($i=1; $i<strlen($s); $i++) {
        if($s[$i] == $it) {
            $a[$tt] += 1;
        } else {
            $it = $s[$i];
            $tt++;
            $a[$tt] = 1;
        }
    }
    // var_dump($a);
    for($i=0; $i<$tt; $i++) {
        if($a[$i] > 0) {
            if($a[$i] == 1) {
                $a[$i+1] = $a[$i+1]-1;
                $ans++;
            } elseif(($a[$i] % 2) != 0) {
                $a[$i+1] = $a[$i+1]-1;
                $ans++;
            }
        }
    }
    pr($ans);

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

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

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

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

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

        return $a[$n];
    }


You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column from the tableabcdedfghijk we obtain the table:acdefghjk A table is called good if its rows are ordered from top to bottom lexicographically, i.e. each row is lexicographically no larger than the following one. Determine the minimum number of operations of removing a column needed to make a given table good.

The first line contains two integers  — n and m (1 ≤ n, m ≤ 100). Next n lines contain m small English letters each — the characters of the table.

Print a single number — the minimum number of columns that you need to remove in order to make the table good.

NoteIn the first sample the table is already good.In the second sample you may remove the first and third column.In the third sample you have to remove all the columns (note that the table where all rows are empty is considered good by definition).Let strings s and t have equal length. Then, s is lexicographically larger than t if they are not equal and the character following the largest common prefix of s and t (the prefix may be empty) in s is alphabetically larger than the corresponding character of t.

<?php
list ($n, $m) = explode(" ", trim(fgets(STDIN)));

$a = array();
for ($i = 0; $i < $n; $i++) {
  $a[] = trim(fgets(STDIN));
}

$stillEq = array_fill(0, $n, true);
$dels = 0;

for ($j = 0; $j < $m; $j++) {
  $ok = true;
  $nStillEq = $stillEq;
  for ($i = 1; $i < $n; $i++) {
    if (! $stillEq[$i]) {
      continue;
    }
    if (ord($a[$i][$j]) > ord($a[$i - 1][$j])) {
      $nStillEq[$i] = false;
    } elseif (ord($a[$i][$j]) < ord($a[$i - 1][$j])) {
      $dels++;
      $ok = false;
      break;
    }
  }
  if ($ok) {
    $stillEq = $nStillEq;
  }
}

echo "$dels\n";


You are given an array $$$a[0 \dots n-1]$$$ of $$$n$$$ integers. This array is called a "valley" if there exists exactly one subarray $$$a[l \dots r]$$$ such that:  $$$0 \le l \le r \le n-1$$$,  $$$a_l = a_{l+1} = a_{l+2} = \dots = a_r$$$,  $$$l = 0$$$ or $$$a_{l-1} > a_{l}$$$,  $$$r = n-1$$$ or $$$a_r < a_{r+1}$$$. Here are three examples:  The first image shows the array [$$$3, 2, 2, 1, 2, 2, 3$$$], it is a valley because only subarray with indices $$$l=r=3$$$ satisfies the condition.The second image shows the array [$$$1, 1, 1, 2, 3, 3, 4, 5, 6, 6, 6$$$], it is a valley because only subarray with indices $$$l=0, r=2$$$ satisfies the codition.The third image shows the array [$$$1, 2, 3, 4, 3, 2, 1$$$], it is not a valley because two subarrays $$$l=r=0$$$ and $$$l=r=6$$$ that satisfy the condition.You are asked whether the given array is a valley or not.Note that we consider the array to be indexed from $$$0$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 2\cdot10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases is smaller than $$$2\cdot10^5$$$.

For each test case, output "YES" (without quotes) if the array is a valley, and "NO" (without quotes) 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).

NoteThe first three test cases are explained in the statement.

<?php
$T = (int)fgets(STDIN);
for ($t = 0; $t < $T; $t++) {
    $n = (int)fgets(STDIN);
    $ary = array_map('intval', explode(" ", fgets(STDIN)));
    $mn = 0;
    for($i = 0; $i < $n; $i++)
        if ($ary[$i] < $ary[$mn])
            $mn = $i;
    $can = true;
    for($i = $mn; $i > 0; $i--)
        if ($ary[$i-1] < $ary[$i])
            $can = false;
    for($i = $mn; $i < $n-1; $i++)
        if ($ary[$i] > $ary[$i+1])
            $can = false;
    echo ($can ? "YES" : "NO") . PHP_EOL;
}

<?php

$tests = getLineInt();

$results = array();

for ($test = 0; $test < $tests; $test++)
{
    $n = getLineInt();

    $a = getLineInts();

    $openL = false;

    $openLValue = 0;

    $valeyCount = 0;

    for ($index = 0; $index < $n; $index++)
    {
        if ($index == 0 || $a[$index - 1] > $a[$index])
        {
            $openL = true;
            $openLValue = $a[$index];
        }

        if ($openL && $openLValue != $a[$index])
        {
            $openL = false;
            $openLValue = 0;
        }

        if ($openL && ($index == $n - 1 || $a[$index + 1] > $a[$index]))
        {
            $openL = false;
            $openLValue = 0;

            $valeyCount++;
        }
    }

    $results[$test] = $valeyCount == 1 ? "YES" : "NO";
}

echo(implode(PHP_EOL, $results));

// Helpers

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

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

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

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

function max2(array $array)
{
    $max1 = $max2 = 0;

    for ($index = 0; $index < count($array); $index++)
    {
        if ($array[$index] > $max1)
        {
            $max2 = $max1;
            $max1 = $array[$index];
        }

        else if ($array[$index] > $max2)
        {
            $max2 = $array[$index];
        }
    }

    return array($max1, $max2);
}


Two people are playing a game with a string $$$s$$$, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only one possible turn: delete "aa", so the string will become "xx". A player not able to make a turn loses.Your task is to determine which player will win if both play optimally.

The only line contains the string $$$s$$$, consisting of lowercase latin letters ($$$1 \leq |s| \leq 100\,000$$$), where $$$|s|$$$ means the length of a string $$$s$$$.

If the first player wins, print "Yes". If the second player wins, print "No".

NoteIn the first example the first player is unable to make a turn, so he loses.In the second example first player turns the string into "q", then second player is unable to move, so he loses.

<?

class DllItem{
	protected $val = null;
	protected $next = null;
	protected $prev = null;

	function __construct($val){
		$this->val = $val;
	}

	function setNext(DllItem $next){
		$this->next = $next;
	}

	function setPrev(DllItem $prev){
		$this->prev = $prev;
	}

	function getNext(){
		return $this->next;
	}

	function getPrev(){
		return $this->prev;
	}

	function getValue(){
		return $this->val;
	}

	function deleteNext(){
		$this->next = null;
	}

	function deletePrev(){
		$this->prev = null;
	}

}

class DLL{
	protected $head = null;
	protected $tail = null;
	//protected $key = null;
	protected $current = null;

	protected function getCurrentNode(){
		return $this->current;
	}

	public function current(){
		return $this->current;
	}

	public function valid(){
		return !is_null($this->current);
	}

	public function next(){
		if($this->valid()){
			$this->current = $this->current->getNext();
		}
	}
	public function prev(){
		if($this->valid()){
			$this->current = $this->current->getPrev();
		}
	}

	public function rewind(){
		$this->current = $this->head;
	}

	public function append($value){
		$item = new DllItem($value);
		if (is_null($this->head)){
			$this->head = $item;
			$this->tail = $item;
			$this->current = $item;
		}else{
			$item->setPrev($this->tail);
			$this->tail->setNext($item);
			$this->tail = $item;
			$this->current = $item;
		}
	}

	public function appendLeft($value){
		$item = new DllItem($value);
		if (is_null($this->head)){
			$this->head = $item;
			$this->tail = $item;
			$this->current = $item;
		}else{
			$item->setNext($this->head);
			$this->head->setPrev($item);
			$this->head = $item;
			$this->current = $item;
		}
	}

	public function insert($value){
		if ($this->current!=$this->tail){
			$item = new DllItem($value);
			$next = $this->current->getNext();
			$next->setPrev($item);
			$item->setNext($next);
			$this->current->setNext($item);
			$this->current = $item;
		}else{
			$this->append($value);
		}
	}

	public function pop(){
		if(!is_null($this->tail)){
			$tail = $this->tail;
			$prev = $tail->getPrev();
			if(!is_null($prev)){
				$prev->deleteNext();
				$this->tail = $prev;
			}else{
				$this->tail = null;
				$this->head = null;
				$this->current = null;
			}
			return $tail->getValue();
		}else{
			//exception
		}
	}

	public function popLeft(){
		if(!is_null($this->head)){
			$head = $this->head;
			$next = $head->getNext();
			if(!is_null($next)){
				$next->deletePrev();
				$this->head = $next;
			}else{
				$this->tail = null;
				$this->head = null;
				$this->current = null;
			}
			return $head->getValue();
		}else{
			//exception
		}
	}

	public function delete(){
		if($this->valid()){
			$cur = $this->current;
			$next = $cur->getNext();
			$prev = $cur->getPrev();

			if(!is_null($next)&&!is_null($prev)){
				$next->setPrev($prev);
				$prev->setNext($next);
				$this->current = $next;

			}elseif(!is_null($prev)&&is_null($next)){
				$this->pop();
				$this->current = $prev;
			}elseif(!is_null($next)&&is_null($prev)){
				$this->popLeft();
				$this->current = $next;
			}else{
				$this->pop();
			}
		}
	}

	public function print(){
		$cur = $this->head;
		if(!is_null($cur)){
			echo " ".$cur->getValue()." ";
			while(!is_null($cur->getNext())){

				$cur = $cur->getNext();
				echo " ".$cur->getValue()." ";
			}
		}
		echo "\n";
	}

}

$dll = new DLL();

$sarr = str_split(trim(fgets(STDIN)));
foreach($sarr as $char){
	$dll->append($char);
}
$dll->rewind();

function canPlay(&$dll){
	//echo $dll->count()." cnt \n";
	//print_r($dll);
	$iter_n = 1;
	if(!$dll->valid()){
		$dll->rewind();
	}
	while ($dll->valid()){
		//echo "!";
		//Print current node's value
		$cur = $dll->current();
		$next = $cur->getNext();
		if(!is_null($next)){

			if($cur->getValue()==$next->getValue()){
				$dll->delete();
				$dll->delete();
				if($dll->valid()&&!is_null($dll->current()->getPrev())){
					$dll->prev();
				}
				return true;
			}
		}
		//Turn the cursor to next node
		$dll->next();
		/*
		if(!$dll->valid()&&$iter_n>0){
			$dll->rewind();
			$iter_n--;
		}*/

	}
	return false;
}

$res = 2;
while(true){
	$cp = canPlay($dll);
	//echo "cp ".$cp."\n";
	if($cp==true){
		if($res==2){
			$res=1;
		}else{
			$res=2;
		}
	}else{
		break;
	}
}

if($res==1){
	echo "Yes";
}else{
	echo "No";
}

<?
$sarr = str_split(trim(fgets(STDIN)));
$dll = new SplDoublyLinkedList();
foreach($sarr as $char){
	$dll->push($char);
}

function canPlay(&$dll){
	if($dll->count()<2){
		return false;
	}
	while ($dll->valid()){
		//Print current node's value
		$cur = $dll->current();
		if($dll->offsetExists($dll->key()+1)){

			$next = $dll->offsetGet($dll->key()+1);
			echo $dll->current()."\n";
			if ($next == $cur){
				$dll->offsetUnset($dll->key());
				$dll->offsetUnset($dll->key());
				$dll->rewind();
				return true;
			}
		}
		//Turn the cursor to next node
		$dll->next();
	}
	return false;
}

$res = 2;
while(canPlay($dll)){
	if($res==2){
		$res=1;
	}else{
		$res=2;
	}
}

if($res==1){
	echo "Yes";
}else{
	echo "No";
}

<?

class DllItem{
	protected $val = null;
	protected $next = null;
	protected $prev = null;

	function __construct($val){
		$this->val = $val;
	}

	function setNext(DllItem $next){
		$this->next = $next;
	}

	function setPrev(DllItem $prev){
		$this->prev = $prev;
	}

	function getNext(){
		return $this->next;
	}

	function getPrev(){
		return $this->prev;
	}

	function getValue(){
		return $this->val;
	}

	function deleteNext(){
		$this->next = null;
	}

	function deletePrev(){
		$this->prev = null;
	}

}

class DLL{
	protected $head = null;
	protected $tail = null;
	//protected $key = null;
	protected $current = null;

	protected function getCurrentNode(){
		return $this->current;
	}

	public function current(){
		return $this->current;
	}

	public function valid(){
		return !is_null($this->current);
	}

	public function next(){
		if($this->valid()){
			$this->current = $this->current->getNext();
		}
	}

	public function rewind(){
		$this->current = $this->head;
	}

	public function append($value){
		$item = new DllItem($value);
		if (is_null($this->head)){
			$this->head = $item;
			$this->tail = $item;
			$this->current = $item;
		}else{
			$item->setPrev($this->tail);
			$this->tail->setNext($item);
			$this->tail = $item;
			$this->current = $item;
		}
	}

	public function appendLeft($value){
		$item = new DllItem($value);
		if (is_null($this->head)){
			$this->head = $item;
			$this->tail = $item;
			$this->current = $item;
		}else{
			$item->setNext($this->head);
			$this->head->setPrev($item);
			$this->head = $item;
			$this->current = $item;
		}
	}

	public function insert($value){
		if ($this->current!=$this->tail){
			$item = new DllItem($value);
			$next = $this->current->getNext();
			$next->setPrev($item);
			$item->setNext($next);
			$this->current->setNext($item);
			$this->current = $item;
		}else{
			$this->append($value);
		}
	}

	public function pop(){
		if(!is_null($this->tail)){
			$tail = $this->tail;
			$prev = $tail->getPrev();
			if(!is_null($prev)){
				$prev->deleteNext();
				$this->tail = $prev;
			}else{
				$this->tail = null;
				$this->head = null;
				$this->current = null;
			}
			return $tail->getValue();
		}else{
			//exception
		}
	}

	public function popLeft(){
		if(!is_null($this->head)){
			$head = $this->head;
			$next = $head->getNext();
			if(!is_null($next)){
				$next->deletePrev();
				$this->head = $next;
			}else{
				$this->tail = null;
				$this->head = null;
				$this->current = null;
			}
			return $head->getValue();
		}else{
			//exception
		}
	}

	public function delete(){
		if($this->valid()){
			$cur = $this->current;
			$next = $cur->getNext();
			$prev = $cur->getPrev();

			if(!is_null($next)&&!is_null($prev)){
				$next->setPrev($prev);
				$prev->setNext($next);
				$this->current = $next;

			}elseif(!is_null($prev)&&is_null($next)){
				$this->pop();
				$this->current = $prev;
			}elseif(!is_null($next)&&is_null($prev)){
				$this->popLeft();
				$this->current = $next;
			}else{
				$this->pop();
			}
		}
	}

	public function print(){
		$cur = $this->head;
		if(!is_null($cur)){
			echo " ".$cur->getValue()." ";
			while(!is_null($cur->getNext())){

				$cur = $cur->getNext();
				echo " ".$cur->getValue()." ";
			}
		}
		echo "\n";
	}

}

$dll = new DLL();

$sarr = str_split(trim(fgets(STDIN)));
foreach($sarr as $char){
	$dll->append($char);
}
$dll->rewind();

function canPlay(&$dll){
	//echo $dll->count()." cnt \n";
	//print_r($dll);
	$iter_n = 1;
	if(!$dll->valid()){
		$dll->rewind();
	}
	while ($dll->valid()){
		//echo "!";
		//Print current node's value
		$cur = $dll->current();
		$next = $cur->getNext();
		if(!is_null($next)){

			if($cur->getValue()==$next->getValue()){
				$dll->delete();
				$dll->delete();
				return true;
			}
		}
		//Turn the cursor to next node
		$dll->next();
		/*
		if(!$dll->valid()&&$iter_n>0){
			$dll->rewind();
			$iter_n--;
		}*/

	}
	return false;
}

$res = 2;
while(true){
	$cp = canPlay($dll);
	//echo "cp ".$cp."\n";
	if($cp==true){
		if($res==2){
			$res=1;
		}else{
			$res=2;
		}
	}else{
		break;
	}
}

if($res==1){
	echo "Yes";
}else{
	echo "No";
}

<?

$sarr = str_split(trim(fgets(STDIN)));
$dll = new SplDoublyLinkedList();
foreach($sarr as $char){
	$dll->push($char);
}
$dll->rewind();
//print_r($dll);

function canPlay(&$dll){
	//echo $dll->count()." cnt \n";
	//print_r($dll);
	$iter_n = 1;
	while ($dll->valid()){
		//echo "!";
		//Print current node's value
		$cur = $dll->current();
		//echo $cur."\n";
		if($dll->offsetExists($dll->key()+1)){

			$next = $dll->offsetGet($dll->key()+1);
			//echo $dll->current()."\n";
			if ($next == $cur){
				$dll->offsetUnset($dll->key());
				$dll->offsetUnset($dll->key());
				//print_r($dll);
				if ($iter_n <=1 ) {
					$iter_n++;

				}

				return true;
			}
		}
		//Turn the cursor to next node
		$dll->next();
		if(!$dll->valid()&&$iter_n>=0){
			$dll->rewind();
			$iter_n--;
		}

	}
	return false;
}

$res = 2;
while(true){
	$cp = canPlay($dll);
	if($cp){
		if($res==2){
			$res=1;
		}else{
			$res=2;
		}
	}else{
		break;
	}
}

if($res==1){
	echo "Yes";
}else{
	echo "No";
}

<?
$sarr = str_split(trim(fgets(STDIN)));
$dll = new SplDoublyLinkedList();
foreach($sarr as $char){
	$dll->push($char);
}

print_r($dll);

function canPlay(&$dll){
	if($dll->count()<2){
		return false;
	}
	while ($dll->valid()){
		//Print current node's value
		$cur = $dll->current();
		if($dll->offsetExists($dll->key()+1)){

			$next = $dll->offsetGet($dll->key()+1);
			echo $dll->current()."\n";
			if ($next == $cur){
				$dll->offsetUnset($dll->key());
				$dll->offsetUnset($dll->key());
				$dll->rewind();
				return true;
			}
		}
		//Turn the cursor to next node
		$dll->next();
	}
	return false;
}

$res = 2;
while(canPlay($dll)){
	if($res==2){
		$res=1;
	}else{
		$res=2;
	}
}

if($res==1){
	echo "Yes";
}else{
	echo "No";
}

<?

$sarr = str_split(trim(fgets(STDIN)));
$dll = new SplDoublyLinkedList();
foreach($sarr as $char){
	$dll->push($char);
}

//print_r($dll);

function canPlay(&$dll){
	//echo $dll->count()." cnt \n";
	$iter_n = 0;
	while ($dll->valid()){
		//echo "!";
		//Print current node's value
		$cur = $dll->current();
		//echo $cur."\n";
		if($dll->offsetExists($dll->key()+1)){

			$next = $dll->offsetGet($dll->key()+1);
			//echo $dll->current()."\n";
			if ($next == $cur){
				$dll->offsetUnset($dll->key());
				$dll->offsetUnset($dll->key());
				//print_r($dll);
				if ($iter_n == 0 ) {
					$iter_n = 1;

				}

				return true;
			}
		}
		//Turn the cursor to next node
		$dll->next();
		if(!$dll->valid()&&$iter_n>0){
			$dll->rewind();
		}

	}
	return false;
}

$res = 2;
while(true){
	$cp = canPlay($dll);
	if($cp){
		if($res==2){
			$res=1;
		}else{
			$res=2;
		}
	}else{
		break;
	}
}

if($res==1){
	echo "Yes";
}else{
	echo "No";
}

<?

$sarr = str_split(trim(fgets(STDIN)));
$dll = new SplDoublyLinkedList();
foreach($sarr as $char){
	$dll->push($char);
}

//print_r($dll);

function canPlay(&$dll){
	//echo $dll->count()." cnt \n";
	$iter_n = 1;
	while ($dll->valid()){
		//echo "!";
		//Print current node's value
		$cur = $dll->current();
		//echo $cur."\n";
		if($dll->offsetExists($dll->key()+1)){

			$next = $dll->offsetGet($dll->key()+1);
			//echo $dll->current()."\n";
			if ($next == $cur){
				$dll->offsetUnset($dll->key());
				$dll->offsetUnset($dll->key());
				//print_r($dll);
				if ($iter_n <=1 ) {
					$iter_n++;

				}

				return true;
			}
		}
		//Turn the cursor to next node
		$dll->next();
		if(!$dll->valid()&&$iter_n>0){
			$dll->rewind();
			$iter_n--;
		}

	}
	return false;
}

$res = 2;
while(true){
	$cp = canPlay($dll);
	if($cp){
		if($res==2){
			$res=1;
		}else{
			$res=2;
		}
	}else{
		break;
	}
}

if($res==1){
	echo "Yes";
}else{
	echo "No";
}


Vanya walks late at night along a straight street of length l, lit by n lanterns. Consider the coordinate system with the beginning of the street corresponding to the point 0, and its end corresponding to the point l. Then the i-th lantern is at the point ai. The lantern lights all points of the street that are at the distance of at most d from it, where d is some positive number, common for all lanterns. Vanya wonders: what is the minimum light radius d should the lanterns have to light the whole street?

The first line contains two integers n, l (1 ≤ n ≤ 1000, 1 ≤ l ≤ 109) — the number of lanterns and the length of the street respectively.  The next line contains n integers ai (0 ≤ ai ≤ l). Multiple lanterns can be located at the same point. The lanterns may be located at the ends of the street.

Print the minimum light radius d, needed to light the whole street. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 9.

NoteConsider the second sample. At d = 2 the first lantern will light the segment [0, 4] of the street, and the second lantern will light segment [3, 5]. Thus, the whole street will be lit.

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

sort($a, SORT_NUMERIC);

$maxDist = 0;

for ($i = 1; $i < $n; $i++) {
  $maxDist = max($maxDist, $a[$i] - $a[$i - 1]);
}
$maxDist /= 2;
$maxDist = max($maxDist, $a[0]);
$maxDist = max($maxDist, $l - $a[$n - 1]);

printf("%.10f", $maxDist);

<?php
list($nn,$l) = explode(" ",trim(fgets(STDIN)));
$rdh = explode(" ",trim(fgets(STDIN)));
sort($rdh);
if ($nn>1){
if ($rdh[0] != 0)
$rfyjmd []= 2*$rdh[0];
if ($rdh[$nn-1] != $l)
$rfyjmd []= 2*($l-$rdh[$nn-1]);
for ($i=0;$i<$nn-1;$i++){
$rfyjmd []= abs($rdh[$i+1]-$rdh[$i]);
}

$val = max($rfyjmd)/2;
}else{
$val = max($l-$rdh[0],$rdh[0]);
}
printf("%0.10f",$val);
?>

<?php
list ($n,$L) = explode(" ",trim(fgets(STDIN)));
$lights = explode(" ",trim(fgets(STDIN)));
sort($lights);
for ($i=1;$i<count($lights);$i++)
{
    $ds[]=$lights[$i]-$lights[$i-1];
}
$edgeL = $lights[0];
$edgeR = $L - $lights[count($lights)-1];
$answer = max(max($ds)/2,$edgeL,$edgeR);
echo $answer = number_format($answer,10,'.',"");

<?php
list($nnnnnn,$l) = explode(" ",trim(fgets(STDIN)));
$rdh = explode(" ",trim(fgets(STDIN)));
sort($rdh);
if ($nnnnnn>1){
if ($rdh[0] != 0)
$rfyjmd []= 2*$rdh[0];
if ($rdh[$nnnnnn-1] != $l)
$rfyjmd []= 2*($l-$rdh[$nnnnnn-1]);
for ($i=0;$i<$nnnnnn-1;$i++){
$rfyjmd []= abs($rdh[$i+1]-$rdh[$i]);
}

$ololol = max($rfyjmd)/2;
}else{
$ololol = max($l-$rdh[0],$rdh[0]);
}
printf("%0.10f",$ololol);
?>

<?php
$d = readline();
$fonari = readline();
//$d = '7 15';
$d = explode(' ',$d);
$n = $d[0];
$l = $d[1];
//$fonari = '15 5 3 7 9 14 0';
$fonari = explode(' ',$fonari);  // 2 5
sort($fonari);
$summa = array();
$i = 0;
$f_start = min($fonari);
$f_finish = $l - max($fonari);
 foreach ($fonari as $v){
           $summa[] = $fonari[$i + 1] - $v;
         $i += 1;
         if ($i == count($fonari) - 1) {
             break;
         }
      }
 $max_distanse = max($summa)/2;
  if ($max_distanse > $f_start && $max_distanse > $f_finish) {
     echo $max_distanse;
  } elseif ($f_start > $max_distanse  && $f_start > $f_finish){
     echo $f_start;
  } else {
     echo $f_finish;
  }

<?php
// 462A     Яблов и простая задача

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

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

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

sort($arrN);

$maxLen = 0;

for ($i=0; $i < $n-1; $i++) {
    if (($arrN[$i+1] - $arrN[$i]) > $maxLen) {
        $maxLen = $arrN[$i+1] - $arrN[$i];
    }
}

if ((($arrN[0] - 0) * 2) > $maxLen) {
    $maxLen = $arrN[0] * 2;
}

if ((($l - $arrN[$n-1]) * 2) > $maxLen) {
    $maxLen = ($l - $arrN[$n-1]) * 2;
}

echo $maxLen / 2;

?>

<?php
    $stdin = fopen("php://stdin", "r");
    fscanf(STDIN, "%d%d", $n, $l);
    $line = trim(fgets(STDIN));
    $arr = explode(' ', $line);
    fclose(STDIN);

    sort($arr);

    $dp = array();

    $dp[0] = $arr[0];
    for($i=1; $i<sizeof($arr); $i++)
        $dp[$i] = ($arr[$i] - $arr[$i-1])/2;
    $dp[sizeof($arr)] = $l - $arr[sizeof($arr)-1];

    rsort($dp);

    echo $dp[0] . PHP_EOL;
?>

$d = readline();
$fonari = readline();
//$d = '2 5';
$d = explode(' ',$d);
$n = $d[0];
$l = $d[1];
//$fonari = '2 5';
$fonari = explode(' ',$fonari);  // 2 5
sort($fonari);
$summa = array();
$i = 0;
$f_start = min($fonari);
$f_finish = $l - max($fonari);
 foreach ($fonari as $v){
           $summa[] = $fonari[$i + 1] - $v;
         $i += 1;
         if ($i == count($fonari) - 1) {
             break;
         }
      }
 $max_distanse = max($summa)/2;
  if ($max_distanse > $f_start && $max_distanse > $f_finish) {
     echo $max_distanse;
  } elseif ($f_start > $max_distanse  && $f_start > $f_finish){
     echo $f_start;
  } else {
     echo $f_finish;
  }


You are given four integers $$$n$$$, $$$c_0$$$, $$$c_1$$$ and $$$h$$$ and a binary string $$$s$$$ of length $$$n$$$.A binary string is a string consisting of characters $$$0$$$ and $$$1$$$.You can change any character of the string $$$s$$$ (the string should be still binary after the change). You should pay $$$h$$$ coins for each change.After some changes (possibly zero) you want to buy the string. To buy the string you should buy all its characters. To buy the character $$$0$$$ you should pay $$$c_0$$$ coins, to buy the character $$$1$$$ you should pay $$$c_1$$$ coins.Find the minimum number of coins needed to buy the string.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10$$$) — the number of test cases. Next $$$2t$$$ lines contain descriptions of test cases. The first line of the description of each test case contains four integers $$$n$$$, $$$c_{0}$$$, $$$c_{1}$$$, $$$h$$$ ($$$1 \leq n, c_{0}, c_{1}, h \leq 1000$$$). The second line of the description of each test case contains the binary string $$$s$$$ of length $$$n$$$.

For each test case print a single integer — the minimum number of coins needed to buy the string.

NoteIn the first test case, you can buy all characters and pay $$$3$$$ coins, because both characters $$$0$$$ and $$$1$$$ costs $$$1$$$ coin.In the second test case, you can firstly change $$$2$$$-nd and $$$4$$$-th symbols of the string from $$$1$$$ to $$$0$$$ and pay $$$2$$$ coins for that. Your string will be $$$00000$$$. After that, you can buy the string and pay $$$5 \cdot 10 = 50$$$ coins for that. The total number of coins paid will be $$$2 + 50 = 52$$$.

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

// $handle = fopen('buythestring_input.txt', 'r');
// echo '<pre>';

$t = intval(fgets($handle));

for ($tI = 0; $tI < $t; $tI++) {
    list($n, $c0, $c1, $h) = sscanf(fgets($handle), "%d %d %d %d");
    $s = fgets($handle);

    $minCoins = 0;

    for ($i = 0; $i < $n; $i++) {
        $defaultAmountNeeded = ($s{$i} == '0' ? $c0 : $c1);
        $amountNeededIfChange = ($s{$i} == '0' ? $c1 : $c0) + $h;

        $minCoins += $defaultAmountNeeded <= $amountNeededIfChange ? $defaultAmountNeeded : $amountNeededIfChange;
    }

    echo $minCoins;
    echo "\n";
}

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

// $handle = fopen('buythestring_input.txt', 'r');
// echo '<pre>';

$t = intval(fgets($handle));

for ($tI = 0; $tI < $t; $tI++) {
    list($n, $c0, $c1, $h) = sscanf(fgets($handle), "%d %d %d %d");
    $s = fgets($handle);

    $minCoins = 0;

    for ($i = 0; $i < $n; $i++) {
        $defaultAmountNeeded = ($s{$i} == '0' ? $c0 : $c1);
        $amountNeededIfChange = ($s{$i} == '0' ? $c1 : $c0) + $h;

        $minCoins += $defaultAmountNeeded <= $amountNeededIfChange ? $defaultAmountNeeded : $amountNeededIfChange;
    }

    echo $minCoins;
    echo "\n";
}


After finding and moving to the new planet that supports human life, discussions started on which currency should be used. After long negotiations, Bitcoin was ultimately chosen as the universal currency.These were the great news for Alice, whose grandfather got into Bitcoin mining in 2013, and accumulated a lot of them throughout the years. Unfortunately, when paying something in bitcoin everyone can see how many bitcoins you have in your public address wallet. This worried Alice, so she decided to split her bitcoins among multiple different addresses, so that every address has at most $$$x$$$ satoshi (1 bitcoin = $$$10^8$$$ satoshi). She can create new public address wallets for free and is willing to pay $$$f$$$ fee in satoshi per transaction to ensure acceptable speed of transfer. The fee is deducted from the address the transaction was sent from. Tell Alice how much total fee in satoshi she will need to pay to achieve her goal.

First line contains number $$$N$$$ ($$$1 \leq N \leq 200\,000$$$) representing total number of public addresses Alice has. Next line contains $$$N$$$ integer numbers $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$) separated by a single space, representing how many satoshi Alice has in her public addresses. Last line contains two numbers $$$x$$$, $$$f$$$ ($$$1 \leq f < x \leq 10^9$$$) representing maximum number of satoshies Alice can have in one address, as well as fee in satoshies she is willing to pay per transaction.

Output one integer number representing total fee in satoshi Alice will need to pay to achieve her goal.

NoteAlice can make two transactions in a following way:0. 13 7 6 (initial state)1. 6 7 6 5 (create new address and transfer from first public address 5 satoshies)2. 6 4 6 5 1 (create new address and transfer from second address 1 satoshi)Since cost per transaction is 2 satoshies, total fee is 4.


The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are arranged in a circle at equal distances from each other, so they form a regular n-gon. They are numbered in clockwise order with numbers from 1 to n.The site of the University has already conducted a voting that estimated each sculpture's characteristic of ti — the degree of the sculpture's attractiveness. The values of ti can be positive, negative or zero.When the university rector came to evaluate the work, he said that this might be not the perfect arrangement. He suggested to melt some of the sculptures so that:   the remaining sculptures form a regular polygon (the number of vertices should be between 3 and n),  the sum of the ti values of the remaining sculptures is maximized. Help the Vice Rector to analyze the criticism — find the maximum value of ti sum which can be obtained in this way. It is allowed not to melt any sculptures at all. The sculptures can not be moved.

The first input line contains an integer n (3 ≤ n ≤ 20000) — the initial number of sculptures. The second line contains a sequence of integers t1, t2, ..., tn, ti — the degree of the i-th sculpture's attractiveness ( - 1000 ≤ ti ≤ 1000). The numbers on the line are separated by spaces.

Print the required maximum sum of the sculptures' attractiveness.

NoteIn the first sample it is best to leave every second sculpture, that is, leave sculptures with attractivenesses: 2, 4, 5 и 3.

<?php
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$data = explode("\n",$datatxt);

$n=trim($data[0]);

$array = explode(' ', trim($data[1]));

$rating=0;

$i=1;
while(ceil($n/$i)>=3)
{
    if($n/$i==floor($n/$i))
    {
        for($sdvig=0;$sdvig<$i;$sdvig++)
        {
            for($ii=$sdvig;$ii<$n;$ii=$ii+$i)
            {
                $rating+=$array[$ii];
            }
            if(isset($ratingMax))
            {
                if($rating>$ratingMax)
                {
                    $ratingMax=$rating;
                }
            }
            else
            {
                $ratingMax=$rating;
            }
            $rating=0;
        }
    }
    $i++;
}
echo $ratingMax;
?>

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

$max = array_sum($a);
for ($i = 2; $i < $n * 2 / 3; $i++) {
	if ($n % ($i + 1) == 0) {
		$sector = $n / ($i + 1);
		for ($offset = 0; $offset < $sector; $offset++) {
			$c = 0;
			for ($k = 0; $k <= $i; $k++)
				$c += (int) $a[ $offset + $sector * $k ];
			if ($c > $max) $max = $c;
		}
	}
}
printf("%d", $max);

<?php
fscanf(STDIN, "%d", $n);
$arr=explode(' ',trim(fgets(STDIN)));
function sum ($a, $start, $step){
    GLOBAL $n;
    $result = 0;
    for($k=$start; $k<$n; $k+=$step)
        $result+=$a[$k];
    return $result;
}

$max=sum($arr,0, 1);
for($i=2; $i<=$n/2; $i++){
    if ($n%$i==0 && $n/$i>=3 ){
        for ($j = 0; $j < $i; $j++)
            $max=max($max, sum($arr,$j, $i));
    }
}
fprintf(STDOUT, "%.0f", $max);

<?php
$n =(int) trim(fgets(STDIN));
$line = trim(fgets(STDIN));
$t = explode( ' ', $line);

$k = $n/2+$n%2;
$dlm = array();
for($i=3;$i<=$k;$i++)
    if($n%$i == 0)
        $dlm[]= $i;
$dlm[] = $n;

$lastMax = -1000*20000;
foreach($dlm as $key => $val)
{
    $kv = $n / $val;
    for($i=0;$i<$kv;$i++)
    {
        for($j=0;$j<$val;$j++)
        {
            $sum[$i] += (int)$t[$i+$kv*$j];
        }
    }
    $sum[] = $lastMax;
    $lastMax = max($sum);
    unset($sum);
}
fputs(STDOUT, $lastMax);
?>

<?
error_reporting(0);

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

$group = searchGroup( $count );

$maxFind = array();
foreach( $group as $key => $val ){
	$max = searchMax( $rating, $key );
	$maxFind[] = max( $max );
}

echo max( $maxFind );

fclose($fp);

function searchMax( $rating, $period )
{
	$groupSum = array();
	$i = 1;
	foreach( $rating as $value ){
		$groupSum[$i] += $value;
		$i++;
		if( $i > $period )
		{
			$i = 1;
		}
	}
	return $groupSum;
}

function searchGroup( $number )
{
	$aResult = array();
	$middle = $number / 2;
	$i = 1;
	while( $i <= $middle )
	{
		if( $number % $i == 0 ){
			if( $number / $i > 2 )
			{
				$aResult[$i] = true;
			}
			if( $i > 2 )
			{
				$aResult[$number / $i] = true;
			}
		}
		$i++;
	}

	return $aResult;
}
?>

<?php
$n = trim(fgets(STDIN));
$balls = explode(' ', trim(fgets(STDIN)));
$max = array_sum($balls);
for ($i = 2; $i < $n * 2 / 3; $i++) {
        if ($n % ($i + 1) == 0) {
                $sector = $n / ($i + 1);
                for ($offset = 0; $offset < $sector; $offset++) {
                        $sum = 0;
                        for ($k = 0; $k <= $i; $k++) {
                                $sum += (int) $balls[ $offset + $sector * $k ];
                        }
                        if ($sum > $max){
                            $max = $sum;
                       }
                }
        }
}
echo $max."\n";
?>

<?php
    while(($line = fgets(STDIN)) != false)
    {
        $arr[] = $line;
    }
    $input = explode(" ", $arr[1]);
    $temp = 0;
    if (count($input) == 3)
    {
        $temp = $input[0] + $input[1] + $input[2];
        fputs(STDOUT, $temp);
        return;
    }
    $chislo = count($input) / 2 - 1;
    $sums = array();
    for ($i = 1; $i <= $chislo; $i++)
    {
        if (count($input) % $i != 0)
        {
            continue;
        }
        for ($k = 0; $k < $i; $k++)
        {
            $temp = 0;
            $j = $k;
            while ($j < count($input))
            {
                if (($j - $k) % $i == 0)
                {
                    $temp = $temp + $input[$j];
                }
                $j = $j + $i;
            }
            $sums[] = $temp;
        }
    }
    $max = $sums[0];
    for ($i = 1; $i < count($sums); $i++)
    {
        if ($max < $sums[$i])
        {
            $max = $sums[$i];
        }
    }
    fputs(STDOUT, $max);
?>

<?php

fscanf(STDIN ,"%d" , $n);
$a = explode(" " , trim(fgets(STDIN)));
$ans = array_sum($a);
for($i=2;$i<$n/2;$i++) {
	if($n % $i != 0) continue;
	for($j=0;$j<$i;$j++) {
		$tmp = 0;
		for($k=$j;$k<$n;$k+=$i) {
			$tmp += $a[$k];
		}
		if($tmp > $ans) $ans = $tmp;
	}
}
echo $ans;
?>

<?php
//set_time_limit(10);
/**
 * @author icyken
 * @copyright 2012
 */

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

//$stdin = fopen("input.txt",'r');

$inputFirstLine     = explode(" ",trim(fgets($stdin)));
$n = $inputFirstLine[0];

$values = explode(" ",trim(fgets($stdin)));

for ($i=3; $i<$n; $i++)
if ($n % $i==0) $del[] = $i;

function sumP($arr)
{
    foreach ($arr as $keyA=>$valueA) $r = $r + $valueA;
    return $r;
}

$aP = sumP($values);

$i = count($del);
while ($i>0)
{
    $ugolnik = $del[$i-1];
    $countUgolnik = $n / $ugolnik;
    while ($countUgolnik>0)
    {
        $sx = $countUgolnik-1;

        $summa = 0;
        while ($sx<=$n)
        {
            $summa = $summa + $values[$sx];
            $sx =  $sx + ($n/$ugolnik);
        }

//        echo $summa."\n";

        if ($aP<$summa) $aP = $summa;
        $countUgolnik--;
    }

    $i--;
}

echo $aP;

?>

<?php
          $stdin = file_get_contents('php://stdin');
          $lines = explode("\n", $stdin, 2);
          $lines[1] = explode(' ', $lines[1]);
          $input = array(
            'n' => intval($lines[0]),
            'items' => $lines[1],
          );
  $i = 0;
  $sums = array();
    $n = $input['n'];
    for ($i = 1; $i <= $n / 3; $i++) {
        if ($n % $i) { continue; }
        for($k = 1; $k <= $i; $k++) {
            $sums[] = getSum($k, $i);
        }
  }
  function getSum($start, $step)
  {
      global $input;
      $sum = 0;
      for($i = $start - 1; $i < count($input['items']); $i = $i+$step) {
        $sum += $input['items'][$i];
      }
      return $sum;
  }

    file_put_contents('php://stdout', max($sums));
 ?>

<?php
    function InputNumbers($count) {
        return explode(' ', fgets(STDIN));
    }

    $columns_count = intval(fgets(STDIN));
    $columns = InputNumbers($columns_count);

    $indexes = array();

    for ($i = 2; $i <= $columns_count/3; ++$i) {
        if ($columns_count % $i == 0) {
            $indexes[] = $i;
        }
    }

    $max_sum = false;
    foreach ($indexes as $index) {
        $chunks = array_chunk($columns, $index);
        $sum = array();

        foreach ($chunks as $chunk) {
            foreach ($chunk as $key=>$item) {
                if (!isset($sum[$key])) {
                    $sum[$key] = 0;
                }
                $sum[$key] += $item;
            }
        }

        rsort($sum);

        if ($max_sum === false || $max_sum < $sum[0]) {
            $max_sum = $sum[0];
        }
    }

    $sum = array_sum($columns);
    if ($max_sum === false || $sum > $max_sum) {
        echo $sum;
    } else {
        echo $max_sum;
    }
?>

<?php
$fp = fopen('php://stdin', 'r');
$tmp='';
while($line = fgets($fp)) { $tmp.=$line; }
$tmp=explode("\n",$tmp);
$num=(int)$tmp[0];
$scarray=explode(" ",$tmp[1]);
$vars=array();
$res=array();
$result=0;
if ($num<6) {
	for($i=0;$i<$num;$i++) $result+=(int)$scarray[$i];
} else {
	array_push($vars,0);
	for($i=1;$i<$num/3;$i++) {
		if ($num % ($i+1)==0)
			array_push($vars,$i);
	}
	for ($i=0;$i<count($vars);$i++) {
		for($k=0;$k<$vars[$i]+1;$k++){
			$temp=0;
			for($j=$k;$j<$num;$j+=$vars[$i]+1) {
				$temp+=(int)$scarray[$j];
			}
			array_push($res,$temp);
		}
	}
	$result=max($res);
}
echo $result;
?>

<?php
    $n = trim(fgets(STDIN));
    $ball=explode(' ',trim(fgets(STDIN)));
   $min=null;
    for ($i=1; $i<=$n; $i++){
        if (($n%$i>0) or ($n/$i<3)) {continue;}
        for ($t=0; $t<=$i-1; $t++){
            $j=$t; $count=$ball[$j];
            while ($j<$n){

               $j=$j+$i;

               $count=$count+$ball[$j];

            }
            if ($min<=$count) $min=$count;
        }
    }
    print($min);

?>

<?php
    $sum=0;
    $max=0;

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

        $line = trim(fgets(STDIN));
        $line_array=explode(" ",$line);
        for($i=0;$i<$sculpture_number;$i++){
            $max+=intval($line_array[$i]);
        }

     for($i=1;$i<$sculpture_number;$i++){
         if ($sculpture_number % $i==0 && $sculpture_number/$i!=2){
             for($j=1;$j<=$i;$j++){
                $sum=0;
                 for ($k=$j-1;$k<$sculpture_number;$k=$k+$i){
                    $sum+=intval($line_array[$k]);
                 }
                if($sum>$max){$max=$sum;}
             }
         }
     }

   echo $max;
?>

<?
fscanf(STDIN, "%d\n", $number);
$line=trim(fgets(STDIN));
$t=explode(" ",$line);
$count=count($t);
if($count!=$number||$number<3||$number>20000)exit();
$res=array();
for($i=1;$i<$count;$i++){
	if($count%$i!=0 || ($count/$i)<3)continue;
	$count/$i;
	for($n=0;$n<$i;$n++){
		for($a=$n;$a<$count;$a+=$i){
			$val=$t[$a];
			if($val<-1000||$val>1000)exit();
			$res[$i.$n]+=$val;
		}
	}
}
echo max($res);
?>

<?php
fscanf(STDIN, "%d\n", $iSculptures);

$sRates = fgets(STDIN, 122880);

$aRates = explode(' ', $sRates);

if ($iSculptures != count($aRates) || $iSculptures < 3 || $iSculptures > 20000) {
	die;
}

foreach ($aRates as &$iRate) {
	$iRate = (int) $iRate;

	if ($iRate < 0) {
		$bHaveNegative = true;
	}
}

$iIterations = floor($iSculptures / 3);

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

	$aTempRates = $aRates;
	if ($iSculptures % $i == 0) {
		for ($fi = 1; $fi <= $i; $fi ++) {

			$iReplaced = $aTempRates[$fi - 1];
			array_push($aTempRates, $iReplaced);

			$iCurRate = 0;
			$iTop = $iSculptures + $fi;

			for ($j = $fi; $j < $iTop ; $j += $i) {
				$iCurRate += $aTempRates[$j];
			}

			if (!isset($iMaxRate)) {
				$iMaxRate = $iCurRate;

				if (!isset($bHaveNegative)) {
					break 2;
				}
			} else {
				$iMaxRate = max($iCurRate, $iMaxRate);
			}
		}
	}
}

echo $iMaxRate;

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

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

$points=trim($lines[0]);
$dots=explode(" ", $lines[1]);

$max=array_sum($dots);
if ($points>5)
{
    $dels=del($points);
    foreach ($dels as $d)
    {
        for ($c=1; $c<=$d; $c++)
        {
            $tmp=0;
            $n=0;
            for ($i=0+$c; $i<=$points; $i=$i+$d)
            {
                $tmp+=$dots[$i-1];
                $n++;
                //echo "{$dots[$i-1]} ";
            }
            //echo " = $tmp<br>";
            if($n>=3)
            if ($tmp>$max)
                $max=$tmp;
        }
    }
}

echo $max;

function del($chislo)
{
    for($i = 1; $i < $chislo; $i++)
    {
     if(($chislo % $i)==0)
       $dels[]=$i;
    }
    return $dels;
}
?>

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

$number = $arr[0];
$array = explode(" ", $arr[1]);
$delitels = array();
$summa = 0;
$sum = 0;

//найдём делители числа 8
for ($i=2; $i<$number; $i++) {
    if ($number%$i == 0 && $number/$i >= 3) {
        $delitels[] = $i;
    }
}

for ($i=0; $i<$number; $i++) {
    $summa += $array[$i];
}

//1 - Если число простое - то ответ - начальная сумма

if (!empty($delitels)) {
    foreach ($delitels as $del) {
        for ($j=0; $j<$del; $j++) { //Пройдём по делителю с шагом = 1
            $sum = 0;
            for ($i=$j; $i<$number; $i+=$del) {
                $sum += $array[$i];
            }
            if ($sum > $summa) {
                $summa = $sum;
            }
        }
    }
}

    fputs(STDOUT, $summa);
?>

<?php
error_reporting("off");
//158D: Ice Sculptures
//Lesson of the day: When you have a computer do arithmetic for you, it's practically always right. Do not question it when it tells you that 1 + 1 + (-1) + 1 is 2 (and, surprisingly enough, not 3).
$n = trim(fgets(STDIN)); //$n = 8;
$t = explode(" ", trim(fgets(STDIN))); //$t = explode(" ", "1 1 1 1 -1 -1 1 1");
$total = array();
for ($i = 1; $i < $n; $i++) {
    if ($n % $i == 0 && $n / $i > 2) { //needs to divide into the num of statues and also be >= 3 after that.
        $sums = array();
        $leftstanding = $n / $i;
        for ($k = 0; $k < $i; $k++) {
            $sum = 0;
            for ($j = $k; $j < $n; $j += $i) {
                $sum += $t[$j];
            }
            $sums[] = $sum;
        }
        rsort($sums);
        $total[] = $sums[0]; //only the top dogs need to move to the next round
    }
}
rsort($total);
echo $total[0];
?>

<?php
  $input = dataProvider::get();
  $i = 0;
  $sums = array();
    $n = $input['n'];
    for ($i = 1; $i <= $n / 3; $i++) {
        if ($n % $i) {
            continue;
        }

        for($k = 1; $k <= $i; $k++) {
            $sums[] = getSum($k, $i);
        }
  }

  function getSum($start, $step)
  {
      global $input;
      $sum = 0;
      for($i = $start - 1; $i < count($input['items']); $i = $i+$step) {
        $sum += $input['items'][$i];
      }
      return $sum;
  }

  dataProvider::set(max($sums));

  class dataProvider
  {
      public static function get()
      {
          $stdin = file_get_contents('php://stdin');
          $lines = explode("\n", $stdin, 2);
          $lines[1] = explode(' ', $lines[1]);
          return array(
            'n' => intval($lines[0]),
            'items' => $lines[1],
          );
      }

      public static function set($data)
      {
        file_put_contents('php://stdout', $data);
      }
  }
?>

<?php
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$data = explode("\n",$datatxt);

$n=trim($data[0]);

$array = explode(' ', trim($data[1]));

$rating=0;
$ratingMax=0;

$i=1;
while(ceil($n/$i)>=3)
{
    for($sdvig=0;$sdvig<=$i;$sdvig++)
    {
        for($ii=$sdvig;$ii<$n;$ii=$ii+$i)
        {
            $rating+=$array[$ii];

        }
        if($rating>$ratingMax)
        {
            $ratingMax=$rating;
        }
        $rating=0;
    }
    $i++;
}

echo $ratingMax;
?>

<?php
$dir = fopen("php://stdin", 'r');
$datatxt = stream_get_contents($dir);
$data = explode("\n",$datatxt);

$n=trim($data[0]);

$array = explode(' ', trim($data[1]));

$rating=0;

$i=1;
while(ceil($n/$i)>=3)
{
    for($sdvig=0;$sdvig<=$i;$sdvig++)
    {
        for($ii=$sdvig;$ii<$n;$ii=$ii+$i)
        {
            $rating+=$array[$ii];

        }
        if(!empty($ratingMax))
        {
            if($rating>$ratingMax)
            {
                $ratingMax=$rating;
            }
        }
        else
        {
            $ratingMax=$rating;
        }
        $rating=0;
    }
    $i++;
}
echo $ratingMax;
?>

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

$max = 0;
for ($i = 2; $i < $n * 2 / 3; $i++) {
	if ($n % ($i + 1) == 0) {
		$sector = $n / ($i + 1);
		for ($offset = 0; $offset < $sector; $offset++) {
			$c = 0;
			for ($k = 0; $k <= $i; $k++)
				$c += (int) $a[ $offset + $sector * $k ];
			if ($c > $max) $max = $c;
		}
	}
}
printf("%d", $max);

<?php
fscanf(STDIN, "%d", $n);
$arr=explode(' ',trim(fgets(STDIN)));
function sum ($a, $start, $step){
    $result = 0;
    for($k=$start; $k<count($a); $k+=$step)
        $result+=$a[$k];
    return $result;
}

$max=0;
for($i=3; $i<=floor($n/2); $i++){
    if ($n%$i==0){
        for ($j = 0; $j < $i-1; $j++)
            $max=max($max, sum($arr,$j, $n/$i));
    }
}
$max=max($max, sum($arr,0, 1));
fprintf(STDOUT, "%.0f", $max);

<?php
fscanf(STDIN, "%d", $n);
$arr=explode(' ',trim(fgets(STDIN)));
function sum ($a, $start, $step){
    GLOBAL $n;
    $result = 0;
    for($k=$start; $k<$n; $k+=$step)
        $result+=$a[$k];
    return $result;
}

$max=sum($arr,0, 1);
for($i=2; $i<=$n/2; $i++){
    if ($n%$i==0){
        for ($j = 0; $j < $i; $j++)
            $max=max($max, sum($arr,$j, $i));
    }
}
fprintf(STDOUT, "%.0f", $max);

<?php
fscanf(STDIN, "%d", $n);
$arr=explode(' ',trim(fgets(STDIN)));
function sum ($a, $start, $step){
    $result = 0;
    for($k=$start; $k<count($a); $k+=$step)
        $result+=$a[$k];
    return $result;
}
$max=0;
for($i=3; $i<=floor($n/2); $i++){
    if ($n%$i==0){
        for ($j = 0; $j < $i-1; $j++)
            $max=max($max, sum($arr,$j, $n/$i));
    }
}
fprintf(STDOUT, "%.0f", $max);

<?php
fscanf(STDIN, "%d", $n);
$arr=explode(' ',trim(fgets(STDIN)));
function sum ($a, $start, $step){
    GLOBAL $n;
    $result = 0;
    for($k=$start; $k<$n; $k+=$step)
        $result+=$a[$k];
    return $result;
}

$max=sum($arr,0, 1);
for($i=2; $i<=$n/2; $i++){
    if ($n%$i==0){
        for ($j = 0; $j < $i-1; $j++)
            $max=max($max, sum($arr,$j, $i));
    }
}
fprintf(STDOUT, "%.0f", $max);

<?php
$n =(int) trim(fgets(STDIN));
$line = trim(fgets(STDIN));
$t = explode( ' ', $line);

$k = $n/2+$n%2;
$dlm = array();
for($i=3;$i<=$k;$i++)
    if($n%$i == 0)
        $dlm[]= $i;
$dlm[] = $n;

$lastMax = 0;
foreach($dlm as $key => $val)
{
    $kv = $n / $val;
    for($i=0;$i<$kv;$i++)
    {
        for($j=0;$j<$val;$j++)
        {
            $sum[$i] += (int)$t[$i+$kv*$j];
        }
    }
    $sum[] = $lastMax;
    $lastMax = max($sum);
    unset($sum);
}
fputs(STDOUT, $lastMax);
?>

<?php

function getVariants($n){
    $a=$n;
    $res=array($n);
    if($n%5==0){
        while($a>5){
            $res[]=$a/2;
            $a=$a/2;
        }
        return $res;
    }elseif($n%4==0){
        while($a>4){
            $res[]=$a/2;
            $a=$a/2;
        }
        return $res;
    }elseif($n%3==0){
        while($a>3){
            $res[]=$a/2;
            $a=$a/2;
        }
        return $res;
    }else{
        return $n;
    }

}

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

$max=array_sum($balls);
$variants=getVariants($n);

$c=count($variants);
if($c==1){
    echo array_sum($balls);
}else{
    for($i=1;$i<$c;$i++){
        $maxEven=0;
        $maxOdd=0;
        for($j=0;$j<$n;$j=$j+$n/$variants[$i]){
            $maxOdd+=$balls[$j];
        }
        for($j=1;$j<$n;$j=$j+$n/$variants[$i]){
            $maxEven+=$balls[$j];
        }
        if($maxEven>$max){
            $max=$maxEven;
        }
        if($maxOdd>$max){
            $max=$maxOdd;
        }
    }
    echo $max;
}

?>

<?php
    while(($line = fgets(STDIN)) != false)
    {
        $arr[] = $line;
    }
    $input = explode(" ", $arr[1]);
    $chislo = floor(sqrt(count($input)));
    $sums = array();
    for ($i = 1; $i <= $chislo; $i++)
    {
        for ($k = 0; $k < $i; $k++)
        {
            $temp = 0;
            $j = $k;
            while ($j < count($input))
            {
                if (($j - $k) % $i == 0)
                {
                    $temp = $temp + $input[$j];
                }
                $j = $j + $i;
            }
            $sums[] = $temp;
        }
    }
    $max = $sums[0];
    for ($i = 1; $i < count($sums); $i++)
    {
        if ($max < $sums[$i])
        {
            $max = $sums[$i];
        }
    }
    fputs(STDOUT, $max);
?>

<?php
    while(($line = fgets(STDIN)) != false)
    {
        $arr[] = $line;
    }
    $input = explode(" ", $arr[1]);
    $chislo = floor(sqrt(count($input)));
    $sums = array();
    for ($i = 1; $i <= $chislo; $i++)
    {
        if (count($input) % $i != 0)
        {
            continue;
        }
        for ($k = 0; $k < $i; $k++)
        {
            $temp = 0;
            $j = $k;
            while ($j < count($input))
            {
                if (($j - $k) % $i == 0)
                {
                    $temp = $temp + $input[$j];
                }
                $j = $j + $i;
            }
            $sums[] = $temp;
        }
    }
    $max = $sums[0];
    for ($i = 1; $i < count($sums); $i++)
    {
        if ($max < $sums[$i])
        {
            $max = $sums[$i];
        }
    }
    fputs(STDOUT, $max);
?>

<?php
    while(($line = fgets(STDIN)) != false)
    {
        $arr[] = $line;
    }
    $input = explode(" ", $arr[1]);
    $chislo = count($input) / 2;
    $sums = array();
    for ($i = 1; $i <= $chislo; $i++)
    {
        if (count($input) % $i != 0)
        {
            continue;
        }
        for ($k = 0; $k < $i; $k++)
        {
            $temp = 0;
            $j = $k;
            while ($j < count($input))
            {
                if (($j - $k) % $i == 0)
                {
                    $temp = $temp + $input[$j];
                }
                $j = $j + $i;
            }
            $sums[] = $temp;
        }
    }
    $max = $sums[0];
    for ($i = 1; $i < count($sums); $i++)
    {
        if ($max < $sums[$i])
        {
            $max = $sums[$i];
        }
    }
    fputs(STDOUT, $max);
?>

<?php
    while(($line = fgets(STDIN)) != false)
    {
        $arr[] = $line;
    }
    $input = explode(" ", $arr[1]);
    $chislo = count($input) / 2 - 1;;
    $sums = array();
    for ($i = 1; $i <= $chislo; $i++)
    {
        if (count($input) % $i != 0)
        {
            continue;
        }
        for ($k = 0; $k < $i; $k++)
        {
            $temp = 0;
            $j = $k;
            while ($j < count($input))
            {
                if (($j - $k) % $i == 0)
                {
                    $temp = $temp + $input[$j];
                }
                $j = $j + $i;
            }
            $sums[] = $temp;
        }
    }
    $max = $sums[0];
    for ($i = 1; $i < count($sums); $i++)
    {
        if ($max < $sums[$i])
        {
            $max = $sums[$i];
        }
    }
    fputs(STDOUT, $max);
?>

<?php

fscanf(STDIN ,"%d" , $n);
$a = explode(" " , trim(fgets(STDIN)));
$ans = array_sum($a);
for($i=2;$i<=$n;$i++) {
	if($n % $i != 0) continue;
	for($j=0;$j<$i;$j++) {
		$tmp = 0;
		for($k=$j;$k<$n;$k+=$i) {
			$tmp += $a[$k];
		}
		if($tmp > $ans) $ans = $tmp;
	}
}
echo $ans;
?>

<?php
    function InputNumbers($count) {
        return explode(' ', fgets(STDIN));
    }

    $columns_count = intval(fgets(STDIN));
    $columns = InputNumbers($columns_count);

    $indexes = array();

    for ($i = 2; $i <= $columns_count/3; ++$i) {
        if ($columns_count % $i == 0) {
            $indexes[] = $i;
        }
    }

    $max_sum = 0;
    foreach ($indexes as $index) {
        $chunks = array_chunk($columns, $index);
        $sum = array();

        foreach ($chunks as $chunk) {
            foreach ($chunk as $key=>$item) {
                if (!isset($sum[$key])) {
                    $sum[$key] = 0;
                }
                $sum[$key] += $item;
            }
        }

        rsort($sum);
        if ($max_sum < $sum[0]) {
            $max_sum = $sum[0];
        }
    }

    $sum = array_sum($columns);
    if ($sum > $max_sum) {
        echo $sum;
    } else {
        echo $max_sum;
    }
?>

<?php
    function InputNumbers($count) {
        return explode(' ', fgets(STDIN));
    }

    $columns_count = intval(fgets(STDIN));
    $columns = InputNumbers($columns_count);

    $indexes = array();

    for ($i = 2; $i <= $columns_count/3; ++$i) {
        $indexes[] = $i;
    }

    $max_sum = 0;
    foreach ($indexes as $index) {
        $chunks = array_chunk($columns, $index);
        $sum = array();

        foreach ($chunks as $chunk) {
            foreach ($chunk as $key=>$item) {
                if (!isset($sum[$key])) {
                    $sum[$key] = 0;
                }
                $sum[$key] += $item;
            }
        }

        rsort($sum);
        if ($max_sum < $sum[0]) {
            $max_sum = $sum[0];
        }
    }

    $sum = array_sum($columns);
    if ($sum > $max_sum) {
        echo $sum;
    } else {
        echo $max_sum;
    }
?>

<?php
    $n = trim(fgets(STDIN));
    $ball=explode(' ',trim(fgets(STDIN)));
   $min=-1000000;
    for ($i=1; $i<=$n; $i++){
        if (($n%$i>0) or ($n/$i<3)) {continue;}
        for ($t=0; $t<=$i; $t++){
            $j=$t; $count=$ball[$j];
            while ($j<=$n){
               $j=$j+$i;
               $count=$count+$ball[$j];

               if ($min<=$count) $min=$count;
            }
        }
    }
    print($min);

?>

<?php
    $n = trim(fgets(STDIN));
    $ball=explode(' ',trim(fgets(STDIN)));
   $min=-1000000;
    for ($i=1; $i<=$n; $i++){
        if (($n%$i>0) or ($n/$i<3)) {continue;}
        for ($t=0; $t<=$i-1; $t++){
            $j=$t; $count=$ball[$j];
            while ($j<$n){

               $j=$j+$i;

               $count=$count+$ball[$j];

            }
            if ($min<=$count) $min=$count;
        }
    }
    print($min);

?>

<?php
    $sum=0;
    $max=0;

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

        $line = trim(fgets(STDIN));
        $line_array=explode(" ",$line);
        for($i=0;$i<$sculpture_number;$i++){
            $max+=intval($line_array[$i]);
        }

     for($i=1;$i<$sculpture_number;$i++){
         if ($sculpture_number % $i==0){
             for($j=1;$j<=$i;$j++){
                $sum=0;
                 for ($k=$j-1;$k<$sculpture_number;$k=$k+$i){
                    $sum+=intval($line_array[$k]);
                 }
                if($sum>$max){$max=$sum;}
             }
         }
     }

   echo $max;
?>

<?
fscanf(STDIN, "%d\n", $number);
$line=trim(fgets(STDIN));
$t=explode(" ",$line);
$count=count($t);
if($count!=$number||$number<3||$number>20000)exit();
$res=array();
for($i=1;$i<$count;$i++){
	if($count%$i!=0)continue;
	for($n=0;$n<=$i;$n++){
		for($a=$n;$a<$count;$a+=$i){
			$val=$t[$a];
			if($val<-1000||$val>1000)exit();
			$res[$i.$n]+=$val;
		}
	}
}
echo max($res);
?>

<?
fscanf(STDIN, "%d\n", $number);
$line=trim(fgets(STDIN));
$t=explode(" ",$line);
$count=count($t);
if($count!=$number||$number<3||$number>20000)exit();
$res=array();
for($i=1;$i<$count;$i++){
	if($count%$i!=0 && $count/$i<3)continue;
	for($n=0;$n<$i;$n++){
		for($a=$n;$a<$count;$a+=$i){
			$val=$t[$a];
			if($val<-1000||$val>1000)exit();
			$res[$i.$n]+=$val;
		}
	}
}
echo max($res);
?>

<?
fscanf(STDIN, "%d\n", $number);
$line=trim(fgets(STDIN));
$t=explode(" ",$line);
$count=count($t);
if($count!=$number||$number<3||$number>20000)exit();
$res=array();
for($i=1;$i<$count;$i++){
	if($count%$i!=0 && $count/$i<3)continue;
	for($n=0;$n<$i;$n++){
		for($a=$n;$a<$count;$a+=$i){
			$val=$t[$a];
			if($val<-1000||$val>1000)exit();
			$res[$i.$n]+=$val;
		}
	}
}
var_dump($res);
echo max($res);
?>

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

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

$points=trim($lines[0]);
$dots=explode(" ", $lines[1]);

$max=array_sum($dots);
if ($points%2==0)
{
    $dels=del($points);
    foreach ($dels as $d)
    {
        for ($c=1; $c<=$d; $c++)
        {
            $tmp=0;
            for ($i=0+$c; $i<=$points; $i=$i+$d)
            {
                $tmp+=$dots[$i-1];
                //echo "{$dots[$i-1]} ";
            }
            //echo " = $tmp<br>";
            if ($tmp>$max)
                $max=$tmp;
        }
    }
}

echo $max;

function del($chislo)
{
    for($i = 2; $i < $chislo; $i++)
    {
     if(($chislo % $i)==0)
       $dels[]=$i;
    }
    return $dels;
}

?>

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

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

$points=trim($lines[0]);
$dots=explode(" ", $lines[1]);

//$points=44;
$dels=del($points);

$max=array_sum($dots);

foreach ($dels as $d)
{
    for ($c=1; $c<=$d; $c++)
    {
        $tmp=0;
        for ($i=0+$c; $i<=$points; $i=$i+$d)
        {
            $tmp+=$dots[$i-1];

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

echo $max;

function del($chislo)
{
    for($i = 2; $i < $chislo; $i++)
    {
     if(($chislo % $i)==0)
       $dels[]=$i;
    }
    return $dels;
}
?>

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

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

$points=trim($lines[0]);
$dots=explode(" ", $lines[1]);

$max=array_sum($dots);
if ($points%2==0 and $points>5)
{
    $dels=del($points);
    foreach ($dels as $d)
    {
        for ($c=1; $c<=$d; $c++)
        {
            $tmp=0;
            for ($i=0+$c; $i<=$points; $i=$i+$d)
            {
                $tmp+=$dots[$i-1];
                //echo "{$dots[$i-1]} ";
            }
            //echo " = $tmp<br>";
            if ($tmp>$max)
                $max=$tmp;
        }
    }
}

echo $max;

function del($chislo)
{
    for($i = 2; $i < $chislo; $i++)
    {
     if(($chislo % $i)==0)
       $dels[]=$i;
    }
    return $dels;
}
?>

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

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

$points=trim($lines[0]);
$dots=explode(" ", $lines[1]);

$max=array_sum($dots);
if ($points%2==0 and $points>5)
{
    $dels=del($points);
    foreach ($dels as $d)
    {
        for ($c=1; $c<=$d; $c++)
        {
            $tmp=0;
            $n=0;
            for ($i=0+$c; $i<=$points; $i=$i+$d)
            {
                $tmp+=$dots[$i-1];
                $n++;
                //echo "{$dots[$i-1]} ";
            }
            //echo " = $tmp<br>";
            if($n>=3)
            if ($tmp>$max)
                $max=$tmp;
        }
    }
}

echo $max;

function del($chislo)
{
    for($i = 1; $i < $chislo; $i++)
    {
     if(($chislo % $i)==0)
       $dels[]=$i;
    }
    return $dels;
}
?>

<?PHP
$putdata = fopen("php://stdin", "r");
$data = fread($putdata, 500000);
fclose($putdata);
$tr = fopen('php://output', 'w');
$t = explode("\n",$data);
$input = $t[0];
$input2 = $t[1];
$r=explode(' ',$input2);
$sum=0;
for($i=0;$i<=count($r)-1;$i++){
$sum+=$r[$i];
}
$count=count($r);
$dels=array();
$max=$sum;
for ($i=2;$i<=$count;$i++){
If ($count % $i ==0){$dels[]=$i;}
}
If (sizeof($dels)<1){
$output=$sum;
}else{
$sums=array();
for ($z=0;$z<=count($dels)-1;$z++){
$del=$dels[$z];
for($h=0;$h<=$count-1;$h++){
for($s=0;$s<=$del-1;$s++){
$sums[$s]+=$r[$del*$h+$s];
}
}
for ($h=0;$h<=$del-1;$h++){
if($sums[$h]>$max){
$max=$sums[$h];}
}
}
$output=$max;
}
fputs($tr, $output );

<?php
//$t2 = time();

$line1 = (int)trim(fgets(STDIN));
$line2 = trim(fgets(STDIN));

//error_reporting(null);

$f = function ($n, $points) {
    //var_dump($n);
    //var_dump($points);

    $sum = array();
    $len = count($points);
    $d = findDel((int)$len);
    //var_dump($d);exit();
    $sum['0_1'] = 0;

    /*for($i=0; $i<$len; $i++) {
        $sum['0_1'] += (int)$points[$i];

        for($j = 0; $j <= count($d); $j++) {
            foreach($d as $item) {
                if($j<$item && (($i+$j) % $item === 0)) {
                    //echo $item===4 && $j==4 ?'<'.$points[$i].'|'.$item.'|'.$j.">\r\n":'';
                    if(!isset($sum[$j.'_'.$item]))
                        $sum[$j.'_'.$item] = 0;
                    $sum[$j.'_'.$item] += (int)$points[$i];
                }
            }
        }
    }*/

    foreach($d as $item) {
        for($i = 0; $i < $len; $i+=$item) {
            for($j = 0; $j <= count($d); $j++) {
                if($j<$item) {
                    if(isset($points[$i+$j])) {
                        //echo $item===4 && $j==0 ?'<'.$points[$i+$j].'|'.$item.'|'.$j.">\r\n":'';
                        if(!isset($sum[$j.'_'.$item]))
                            $sum[$j.'_'.$item] = 0;
                        $sum[$j.'_'.$item]+=$points[$i+$j];
                    }
                }
            }
        }
    }

    //var_dump($sum);

    return max(array_sum($points), max($sum));
};

function findDel($ch) {
    $arr = array();
    for($s = 2; $s < $ch; $s++) {
        if ($s< floor($ch/2) && $ch % $s==0) {
            $arr[] = $s;
        }
        if($s>floor($ch/2))
            break;
    }
    return $arr;
}

//$line1 = 9;
//$line2 = '';
$lineArray2 = explode(' ', $line2);

echo $f($line1, $lineArray2);

//echo "\r\n|=>", (time() - $t2), "\r\n";


You are given a string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters.A substring of a string is a contiguous subsequence of that string. So, string "forces" is substring of string "codeforces", but string "coder" is not.Your task is to calculate the number of ways to remove exactly one substring from this string in such a way that all remaining characters are equal (the number of distinct characters either zero or one).It is guaranteed that there is at least two different characters in $$$s$$$.Note that you can remove the whole string and it is correct. Also note that you should remove at least one character.Since the answer can be rather large (not very large though) print it modulo $$$998244353$$$.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the string $$$s$$$. The second line of the input contains the string $$$s$$$ of length $$$n$$$ consisting only of lowercase Latin letters. It is guaranteed that there is at least two different characters in $$$s$$$.

Print one integer — the number of ways modulo $$$998244353$$$ to remove exactly one substring from $$$s$$$ in such way that all remaining characters are equal.

NoteLet $$$s[l; r]$$$ be the substring of $$$s$$$ from the position $$$l$$$ to the position $$$r$$$ inclusive.Then in the first example you can remove the following substrings:   $$$s[1; 2]$$$;  $$$s[1; 3]$$$;  $$$s[1; 4]$$$;  $$$s[2; 2]$$$;  $$$s[2; 3]$$$;  $$$s[2; 4]$$$. In the second example you can remove the following substrings:   $$$s[1; 4]$$$;  $$$s[1; 5]$$$;  $$$s[1; 6]$$$;  $$$s[1; 7]$$$;  $$$s[2; 7]$$$;  $$$s[3; 7]$$$. In the third example you can remove the following substrings:   $$$s[1; 1]$$$;  $$$s[1; 2]$$$;  $$$s[2; 2]$$$.


You've got a robot, its task is destroying bombs on a square plane. Specifically, the square plane contains n bombs, the i-th bomb is at point with coordinates (xi, yi). We know that no two bombs are at the same point and that no bomb is at point with coordinates (0, 0). Initially, the robot is at point with coordinates (0, 0). Also, let's mark the robot's current position as (x, y). In order to destroy all the bombs, the robot can perform three types of operations:  Operation has format "1 k dir". To perform the operation robot have to move in direction dir k (k ≥ 1) times. There are only 4 directions the robot can move in: "R", "L", "U", "D". During one move the robot can move from the current point to one of following points: (x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1) (corresponding to directions). It is forbidden to move from point (x, y), if at least one point on the path (besides the destination point) contains a bomb.  Operation has format "2". To perform the operation robot have to pick a bomb at point (x, y) and put it in a special container. Thus, the robot can carry the bomb from any point to any other point. The operation cannot be performed if point (x, y) has no bomb. It is forbidden to pick a bomb if the robot already has a bomb in its container.  Operation has format "3". To perform the operation robot have to take a bomb out of the container and destroy it. You are allowed to perform this operation only if the robot is at point (0, 0). It is forbidden to perform the operation if the container has no bomb. Help the robot and find the shortest possible sequence of operations he can perform to destroy all bombs on the coordinate plane.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of bombs on the coordinate plane. Next n lines contain two integers each. The i-th line contains numbers (xi, yi) ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th bomb. It is guaranteed that no two bombs are located at the same point and no bomb is at point (0, 0).

In a single line print a single integer k — the minimum number of operations needed to destroy all bombs. On the next lines print the descriptions of these k operations. If there are multiple sequences, you can print any of them. It is guaranteed that there is the solution where k ≤ 106.