You are given the string s of length n and the numbers p, q. Split the string s to pieces of length p and q.For example, the string "Hello" for p = 2, q = 3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".Note it is allowed to split the string s to the strings only of length p or to the strings only of length q (see the second sample test).

The first line contains three positive integers n, p, q (1 ≤ p, q ≤ n ≤ 100). The second line contains the string s consists of lowercase and uppercase latin letters and digits.

If it's impossible to split the string s to the strings of length p and q print the only number "-1". Otherwise in the first line print integer k — the number of strings in partition of s. Each of the next k lines should contain the strings in partition. Each string should be of the length p or q. The string should be in order of their appearing in string s — from left to right. If there are several solutions print any of them.

<?php

$line = fgets(STDIN);
list($n, $p, $q) = explode(' ', $line);
$n = intval($n);
$p = intval($p);
$q = intval($q);
$s = trim(fgets(STDIN));

$ans = false;

for ($i = 0; $i <= $n; $i++) {
	for ($j = 0; $j <= $n; $j++) {
		if ($i * $p + $j * $q == $n) {
			$ans = true;
			break;
		}
	}
	if ($ans)
		break;
}

if ($ans) {
	echo $i + $j . "\n";
	$start = 0;
	for ($ii = 0; $ii < $i; $ii++) {
		echo substr($s, $start, $p) . "\n";
		$start += $p;
	}
	for ($jj = 0; $jj < $j; $jj++) {
		echo substr($s, $start, $q) . "\n";
		$start += $q;
	}
} else {
	echo -1;
}

<?php

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

fscanf($handle, "%d %d %d", $n, $p, $q);
fscanf($handle, "%s", $s);
fclose($handle);

echo $n." ".$p." ".$q."\n";
echo $s."\n";

?>


Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can.But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend it on reading.Help Luba to determine the minimum number of day when she finishes reading.It is guaranteed that the answer doesn't exceed n.Remember that there are 86400 seconds in a day.

The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 106) — the number of days and the time required to read the book. The second line contains n integers ai (0 ≤ ai ≤ 86400) — the time Luba has to spend on her work during i-th day.

Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed n.

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

<?php

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

list($numberOfDays, $timeRequired) = explode(' ', $line1);
$blockedTimePerDay = explode(' ', $line2);

foreach ($blockedTimePerDay as $day => $time) {
    $freeTime = 86400 - $time;

    $timeRequired -= $freeTime;

    if($timeRequired <= 0) {
        echo $day + 1;
        break;
    }
}

<?php
list($days, $needSeconds) = explode(" ", trim(fgets(STDIN)));
$dayWorkTimes =  explode(" ", trim(fgets(STDIN)));
$counter = 0;
for($i = 0; $i < $days; $i++) {
    $needSeconds -= (86400-$dayWorkTimes[$i]);
    $counter++;
    if($needSeconds <= 0) {
        break;
    }
}
print $counter;
?>

<?php //rextester.com:7.0.8--codeforces.com:7.0.12
list($totalTime,$requiredTime)=explode(' ',fgets(STDIN));$workTime=explode(' ',fgets(STDIN));$nonWorkingTime=0;$minRequiredTime=0;
for($i=0;$i<count($workTime);$i++){
    $nonWorkingTime+=86400-$workTime[$i];$minRequiredTime++;
    if($nonWorkingTime>=$requiredTime){echo$minRequiredTime;break;}
}

<?php //7.0.8(rextester.com)7.0.12(codeforces.com)2018-01-04
list($totalTime,$requiredTime)=explode(' ',fgets(STDIN));
$workTime=explode(' ',fgets(STDIN));
$nonWorkingTime=0;
$minRequiredDay=0;
for($i=0;$i<count($workTime);$i++){
    $nonWorkingTime+=86400-$workTime[$i];
    $minRequiredDay++;
    if($nonWorkingTime>=$requiredTime){
        echo$minRequiredDay;
        break;
    }
}

<?php //7.0.8 | RexTester.Com & 7.0.12 | CodeForces.Com
list($totalTime, $requiredTime) = explode(' ', fgets(STDIN));

$workTime = explode(' ', fgets(STDIN));
$nonWorkingTime = 0;
$minRequiredDay = 0;

for ($i=0; $i<count($workTime); $i++) {
    $nonWorkingTime += 86400 - $workTime[$i];
    $minRequiredDay++;

    if ($nonWorkingTime >= $requiredTime) {
        echo $minRequiredDay;
        break;
    }
}

<?php //7.0.8 | RexTester.Com & 7.0.12 | CodeForces.Com
list($a,$b)=explode(' ',fgets(STDIN));$c=explode(' ',fgets(STDIN));$d=0;$e=0;for($i=0;$i<count($c);$i++){$d+=86400-$c[$i];$e++;if($d>=$b){echo$e;break;}}

<?php

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

list($n, $t) = fscanf($fp, '%d %d');
$busy = explode(' ', fgets($fp));

$secondsInDay = 60 * 60 * 24;

for($i = 0; $i < $n; $i++)
{
	$t -= ($secondsInDay - $busy[$i]);
	if($t <= 0)
	{
		echo ($i + 1) . PHP_EOL;
		break;
	}
}

fclose($fp);
?>


The All-Berland Team Programming Contest will take place very soon. This year, teams of four are allowed to participate.There are $$$a$$$ programmers and $$$b$$$ mathematicians at Berland State University. How many maximum teams can be made if:  each team must consist of exactly $$$4$$$ students,  teams of $$$4$$$ mathematicians or $$$4$$$ programmers are unlikely to perform well, so the decision was made not to compose such teams. Thus, each team must have at least one programmer and at least one mathematician.Print the required maximum number of teams. Each person can be a member of no more than one team.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) —the number of test cases. This is followed by descriptions of $$$t$$$ sets, one per line. Each set is given by two integers $$$a$$$ and $$$b$$$ ($$$0 \le a,b \le 10^9$$$).

Print $$$t$$$ lines. Each line must contain the answer to the corresponding set of input data — the required maximum number of teams.

NoteIn the first test case of the example, two teams can be composed. One way to compose two teams is to compose two teams of $$$2$$$ programmers and $$$2$$$ mathematicians.In the second test case of the example, only one team can be composed: $$$3$$$ programmers and $$$1$$$ mathematician in the team.

<?php
//摆烂，摆大烂
//123
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $tmp = explode(' ', trim($datum));
    $a = max((int)$tmp[0], (int)$tmp[1]);
    $b = min((int)$tmp[0], (int)$tmp[1]);

    if ($b === 0) {
        $result[] = 0;
        continue;
    }
    $n = $a - $b;
    $i = 0;
    if($n >= 2) {
        $m=(int)($n/2);
        if ($m >= $b) {
            $result[]=$b;
            continue;
        }
        $i+=$m;
        $b-=$m;
        $a-=$m*3;
    }
    $i += (int)(min($a,$b) / 2);
    $result[] = $i;
}
echo implode("\n", $result);

<?php
//摆烂，摆大烂
//之前提交的版本的魔改版，所以没用readline
//写不动了，nnd
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $tmp = explode(' ', trim($datum));
    $a = max((int)$tmp[0], (int)$tmp[1]);
    $b = min((int)$tmp[0], (int)$tmp[1]);

    if ($b === 0) {
        $result[] = 0;
        continue;
    }
    $n = $a - $b;
    $i = 0;
    if($n >= 2) {
        $m=(int)($n/2);
        if ($m >= $b) {
            $result[]=$b;
            continue;
        }
        $i+=$m;
        $b-=$m;
        $a-=$m*3;
    }
    $i += (int)(min($a,$b) / 2);
    $result[] = $i;
}
echo implode("\n", $result);

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

$t = trim(fgets($file));

for ($i = 0; $i < $t; $i++) {
  list($m, $p) = explode(" ", trim(fgets($file)));

  $min = min($m, $p);
  $res = floor(($m + $p) / 4);

  echo min($min, $res).PHP_EOL;
}

?>

<?php

$fp = fopen('php://stdin', 'r');
$lines = [];

if ($fp) {
    while (($line = fgets($fp)) !== false) {

        $lines[] = trim($line);
    }

    fclose($fp);
}

$n =  $lines[0];

for ($i = 1; $i <= $n; $i++) {
    $result = workFunction($lines[$i]);
    fwrite(STDOUT, $result);
    fwrite(STDOUT, "\n");
}

function workFunction($competitors): int
{
    $competitors = explode(' ', $competitors);

    $teamMin = min($competitors);

    $possibleValue = (int)(array_sum($competitors) / 4);

    return min($teamMin, $possibleValue);
}

<?php
//摆烂，摆大烂
//123
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $tmp = explode(' ', trim($datum));
    $a = max((int)$tmp[0], (int)$tmp[1]);
    $b = min((int)$tmp[0], (int)$tmp[1]);

    if ($b === 0) {
        $result[] = 0;
        continue;
    }
    $n = $a - $b;
    $i = 0;
    if($n > 2) {
        $m=(int)($n/2);
        if ($m >= $b) {
            $result[]=$b;
            continue;
        }
        $i+=$m;
        $b-=$m;
    }
    $i += (int)($b / 2);
    $result[] = $i;
}
echo implode("\n", $result);

<?php
//摆烂，摆大烂
//123
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $tmp = explode(' ', trim($datum));
    $a = max((int)$tmp[0], (int)$tmp[1]);
    $b = min((int)$tmp[0], (int)$tmp[1]);

    if ($b === 0) {
        $result[] = 0;
        continue;
    }
    $n = $a - $b;
    $i = 0;
    if($n > 2) {
        $m=(int)(($n-2)/2);
        if ($m >= $b) {
            $result[]=$b;
            continue;
        }
        $i+=$m;
        $b-=$m;
    }
    $i += (int)($b / 2);
    $result[] = $i;
}
echo implode("\n", $result);

<?php
//摆烂，摆大烂
//123
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $tmp = explode(' ', trim($datum));
    $a = max((int)$tmp[0], (int)$tmp[1]);
    $b = min((int)$tmp[0], (int)$tmp[1]);

    if ($b === 0) {
        $result[] = 0;
        continue;
    }
    $n = $a - $b;
    $i = 0;
    if($n > 2) {
        $m=(int)(($n-2)/2);
        if ($m >= $b) {
            $result[]=$b;
            continue;
        }
        $i+=$m;
        $a-=3*$m;
    }
    $i += (int)($a / 2);
    $result[] = $i;
}
echo implode("\n", $result);

<?php
//摆烂，摆大烂
$input = trim(file_get_contents('php://stdin'));
$data = explode("
", $input);
unset($data[0]);
$result = [];
foreach ($data as $datum) {
    $datum=trim($datum);
    $tmp=explode(' ',$datum);
    $a=(int)$tmp[0];
    $b=(int)$tmp[1];
    $i=0;
    while($a>1000 && $b>1000) {
        $a-=1000;
        $b-=1000;
        $i+=500;
    }
    while ($a + $b >= 4 && min($a,$b)>0) {
        if ($a > $b) {
            $a-=3;
            --$b;
        }elseif ($b > $a) {
            $b-=3;
            --$a;
        } else {
            $b-=2;
            $a-=2;
        }
        if (max($a,$b)<0) {
            break;
        }
        ++$i;
    }
    $result[]=$i;
}
echo implode("\n", $result);


Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n vertices and 0 edges. During Bubble Sort execution, edges appear as described in the following algorithm (pseudocode). procedure bubbleSortGraph()    build a graph G with n vertices and 0 edges    repeat        swapped = false        for i = 1 to n - 1 inclusive do:            if a[i] > a[i + 1] then                add an undirected edge in G between a[i] and a[i + 1]                swap( a[i], a[i + 1] )                swapped = true            end if        end for    until not swapped     /* repeat the algorithm as long as swapped value is true. */ end procedureFor a graph, an independent set is a set of vertices in a graph, no two of which are adjacent (so there are no edges between vertices of an independent set). A maximum independent set is an independent set which has maximum cardinality. Given the permutation, find the size of the maximum independent set of graph G, if we use such permutation as the premutation a in procedure bubbleSortGraph.

The first line of the input contains an integer n (2 ≤ n ≤ 105). The next line contains n distinct integers a1, a2, ..., an (1 ≤ ai ≤ n).

Output a single integer — the answer to the problem.

NoteConsider the first example. Bubble sort swaps elements 3 and 1. We add edge (1, 3). Permutation is now [1, 3, 2]. Then bubble sort swaps elements 3 and 2. We add edge (2, 3). Permutation is now sorted. We have a graph with 3 vertices and 2 edges (1, 3) and (2, 3). Its maximal independent set is [1, 2].

<?php

    class Fenwick {
        private $n;
        private $count;

        public function __construct($n) {
            $this -> n = $n + 10;
            $this -> count = array_fill(1, $this -> n , 0);
        }

        public function update($i, $val) {
            for (; $i <= $this -> n; $i += $i & -$i) $this -> count[$i] = max($this -> count[$i], $val);
        }

        public function get($i) {
            $max = 0;
            for (; $i > 0; $i -= $i & -$i) $max = max($max, $this -> count[$i]);
            return $max;
        }
    }

    $n = fgets(STDIN);
    $a = explode(" ", trim(fgets(STDIN)));
    $fw = new Fenwick($n);
    $ans = 0;
    for ($i = 0; $i < $n; $i++) {
        $cur = $fw -> get($a[$i]) + 1;
        $fw -> update($a[$i], $cur);
        $ans = max($ans, $cur);
    }

    echo $ans;

<?php

    function lowerBound($dp, $l, $r, $k) {
        $ans = $r; $m = 0;
        while ($l < $r) {
            $m = $l + $r >> 1;
            if ($dp[$m] >= $k) $ans = $r = $m; else $l = $m + 1;
        }
        return $ans;
    }

    $n = fgets(STDIN);
    $a = explode(" ", trim(fgets(STDIN)));
    $dp = array_fill(0, $n, 0);
    $dp[0] = $a[0];
    $ans = 1;
    for ($i = 1; $i < $n; $i++) {
        if ($a[$i] > $dp[$ans - 1]) $dp[$ans++] = $a[$i];
        elseif ($a[$i] < $dp[0]) $dp[0] = $a[$i];
        else $dp[lowerBound($dp, 0, $ans, $a[$i])] = $a[$i];
    }

    echo $ans;

<?php

    class Fenwick {
        private $n;
        private $count;

        public function __construct($n) {
            $this -> n = $n + 10;
            $this -> count = array_fill(1, $GLOBALS['n'] , 0);
        }

        public function update($i, $val) {
            for (; $i <= $GLOBALS['n']; $i += $i & -$i) $GLOBALS['count'][$i] = max($GLOBALS['count'][$i], $val);
        }

        public function get($i) {
            $max = 0;
            for (; $i > 0; $i -= $i & -$i) $max = max($max, $GLOBALS['count'][$i]);
            return $max;
        }
    }

    $n = fgets(STDIN);
    $a = explode(" ", trim(fgets(STDIN)));
    $fw = new Fenwick($n);
    $ans = 0;
    for ($i = 0; $i < $n; $i++) {
        $cur = $fw -> get($a[$i]) + 1;
        $fw -> update($a[$i], $cur);
        $ans = max($ans, $cur);
    }

    echo $ans;

<?php

    class Fenwick {
        private $n;
        private $count;

        public function __construct($n) {
            $this -> n = $n;
            $this -> count = array_fill(1, $n, 0);
        }

        public function update($i, $val) {
            for (; $i <= $this -> n; $i += $i & -$i) $this -> count[$i] = max($this -> count[$i], $val);
        }

        public function get($i) {
            $max = 0;
            for (; $i > 0; $i -= $i & -$i) $max = max($max, $this -> count[$i]);
            return $max;
        }
    }

    $n = fgets(STDIN);
    $a = explode(" ", trim(fgets(STDIN)));
    $fw = new Fenwick($n);
    $ans = 0;
    for ($i = 0; $i < $n; $i++) {
        $cur = $fw -> get($a[$i]) + 1;
        $fw -> update($a[$i], $cur);
        $ans = max($ans, $cur);
    }

    echo $ans;

<?php

    function lowerBound($dp, $l, $r, $k) {
        $ans = $r; $m = 0;
        while ($l < $r) {
            $m = $l + $r >> 1;
            if ($dp[$m] >= $k) $ans = $r = $m; else $l = $m + 1;
        }
        return $ans;
    }

    $n = fgets(STDIN);
    $a = array_reverse(explode(" ", trim(fgets(STDIN))));
    $dp = array_fill(0, $n, 0);
    $dp[0] = $a[0];
    $ans = 1;
    for ($i = 1; $i < $n; $i++) {
        if ($a[$i] > $dp[$ans - 1]) $dp[$ans++] = $a[$i];
        elseif ($a[$i] < $dp[0]) $dp[0] = $a[$i];
        else $dp[lowerBound($dp, 0, $ans, $a[$i])] = $a[$i];
    }

    echo $ans;


The elections in which three candidates participated have recently ended. The first candidate received $$$a$$$ votes, the second one received $$$b$$$ votes, the third one received $$$c$$$ votes. For each candidate, solve the following problem: how many votes should be added to this candidate so that he wins the election (i.e. the number of votes for this candidate was strictly greater than the number of votes for any other candidate)?Please note that for each candidate it is necessary to solve this problem independently, i.e. the added votes for any candidate do not affect the calculations when getting the answer for the other two candidates.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of one line containing three integers $$$a$$$, $$$b$$$, and $$$c$$$ ($$$0 \le a,b,c \le 10^9$$$).

For each test case, output in a separate line three integers $$$A$$$, $$$B$$$, and $$$C$$$ ($$$A, B, C \ge 0$$$) separated by spaces — the answers to the problem for the first, second, and third candidate, respectively.

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

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

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();
$res = array();
while ($t--) {
    list($a,$b,$c) = IO::arr();
    $votes = array();
    if ($a == $b && $a == $c) {
        $votes[] = 1;
        $votes[] = 1;
        $votes[] = 1;
        $res[] = $votes;
        continue;
    }

    $max = max($a, $b);
    $max = max($c, $max);

    $fa = false;
    $fb = false;
    $fc = false;
    if ($a == $b || $a == $c) {
        $fa = true;
    }

    if ($b == $a || $b == $c) {
        $fb = true;
    }

    if ($c == $a || $c == $b) {
        $fc = true;
    }
    $win = $max + 1;

    if ($a == $max) {
        if ($fa) {
            $a = 1;
        } else {
            $a = 0;
        }
    } else {
        $a = $win - $a;
    }

    if ($b == $max) {
        if ($fb) {
            $b = 1;
        } else {
            $b = 0;
        }
    } else {
        $b = $win - $b;
    }

    if ($c == $max) {
        if ($fc) {
            $c = 1;
        } else {
            $c = 0;
        }
    } else {
        $c = $win - $c;
    }

    $votes = [$a, $b, $c];

    $res[] = $votes;
}

function setValue($a, $b, $c, $max) {
    if ($max == 0);
}

foreach ($res as $r) {
    foreach ($r as $f) {
        echo $f . ' ';
    }
    echo PHP_EOL;
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
    $aArray = [$a,$b,$c];
    $aAnswer = [];
    $k = max($aArray);
    $iCount = 0;
    foreach ($aArray as $sK => $sV) {
        if ($k == $sV) {
            $iCount++;
        }
    }
    foreach ($aArray as $sK => $sV) {
        if ($k == $sV) {
            if ($k == 0) {
                $aAnswer[] = 1;
            } else {
                if ($iCount > 1) {
                    $aAnswer[] = 1;
                } else {
                    $aAnswer[] = 0;
                }
            }
        } else {
            $aAnswer[] = ($k - $sV) + 1;
        }
    }
    echo implode(" ", $aAnswer). "\n";
}

<?php
$stdin=fopen('php://stdin', 'r');
$caseCount = fgets($stdin);
$cases=[];
for ($i=1;$i<=$caseCount;$i++){
    fscanf($stdin, "\n%d %d %d", $str1,$str2,$str3);
    $cases[]=[$str1,$str2,$str3];
}
//print_r($cases);
$results=[];
foreach ($cases as $caseNo =>$c) {
    //Each test case
        $result_1=[];
        for ($j = 0; $j < 3; $j++) {
            $ct=$c;unset($ct[$j]);shuffle($ct);
//            die(json_encode($c));
            $c1=$ct[0];$c2=$ct[1];$c0=$c[$j];
            //Retrieved $c1,$c2 and $c0 as now value
            $diff1=($c0>$c1)?0:($c1-$c0+1);
            $diff2=($c0>$c2)?0:($c2-$c0+1);
            $result_1[]=max($diff1,$diff2);
        }
        $results[]=$result_1;
}
//print_r($results);
foreach ($results as $caseNo =>$r) {
    printf("%d %d %d",$r[0],$r[1],$r[2]);
    if($caseNo !=($caseCount-1)){print("\n");}
}

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

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

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();
$res = array();
while ($t--) {
    list($a,$b,$c) = IO::arr();
    $votes = array();
    if ($a == $b && $a == $c) {
        $votes[] = $a+1;
        $votes[] = $a+1;
        $votes[] = $a+1;
        $res[] = $votes;
        continue;
    }

    $max = max($a, $b);
    $max = max($c, $max);

    $fa = false;
    $fb = false;
    $fc = false;
    if ($a == $b || $a == $c) {
        $fa = true;
    }

    if ($b == $a || $b == $c) {
        $fb = true;
    }

    if ($c == $a || $c == $b) {
        $fc = true;
    }
    $win = $max + 1;

    if ($a == $max) {
        if ($fa) {
            $a = 1;
        } else {
            $a = 0;
        }
    } else {
        $a = $win - $a;
    }

    if ($b == $max) {
        if ($fb) {
            $b = 1;
        } else {
            $b = 0;
        }
    } else {
        $b = $win - $b;
    }

    if ($c == $max) {
        if ($fc) {
            $c = 1;
        } else {
            $c = 0;
        }
    } else {
        $c = $win - $c;
    }

    $votes = [$a, $b, $c];

    $res[] = $votes;
}

function setValue($a, $b, $c, $max) {
    if ($max == 0);
}

foreach ($res as $r) {
    foreach ($r as $f) {
        echo $f . ' ';
    }
    echo PHP_EOL;
}

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

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

    public static function dd($val){
        echo $val; exit;
    }
}

$t = IO::str();
$res = array();
while ($t--) {
    list($a,$b,$c) = IO::arr();
    $votes = array();
    if ($a == $b && $a == $c) {
        $votes[] = $a+1;
        $votes[] = $a+1;
        $votes[] = $a+1;
        $res[] = $votes;
        continue;
    }

    $max = max($a, $b);
    $max = max($c, $max);

    if ($a - $max == 0) {
        $votes[] = 0;
        $votes[] = $max - $b + 1;
        $votes[] = $max - $c + 1;
    } else if ($b - $max == 0) {
        $votes[] = $max - $a + 1;
        $votes[] = 0;
        $votes[] = $max - $c + 1;
    } else if ($c - $max == 0) {
        $votes[] = $max - $a + 1;
        $votes[] = $max - $b + 1;
        $votes[] = 0;
    }

    $res[] = $votes;
}

foreach ($res as $r) {
    foreach ($r as $f) {
        echo $f . ' ';
    }
    echo PHP_EOL;
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
    $aArray = [$a,$b,$c];
    $aAnswer = [];
    $k = max($aArray);
    foreach ($aArray as $sK => $sV) {
        if ($k == $sV) {
            if ($k == 0) {
                $aAnswer[] = 1;
            } else {
                $aAnswer[] = 0;
            }
        } else {
            $aAnswer[] = ($k - $sV) + 1;
        }
    }
    echo implode(" ", $aAnswer). "\n";
}

<?php
list($n) = explode(' ', trim(fgets(STDIN)));
for ($j = 0; $j < $n; $j++) {
    list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
    if ($a == $b && $b == $c) {
        echo 1 . " " . 1 . " " . 1 . "\n";;
    } else {
        $aArray = [$a,$b,$c];
        $aAnswer = [];
        $k = max($aArray);
        foreach ($aArray as $sK => $sV) {
            if ($k == $sV) {
                $aAnswer[] = 0;
            } else {
                $aAnswer[] = $k - $sV + 1;
            }
        }
        echo implode(" ", $aAnswer). "\n";
    }
}

<?php
$stdin=fopen('php://stdin', 'r');
$caseCount = fgets($stdin);
$cases=[];
for ($i=1;$i<=$caseCount;$i++){
    fscanf($stdin, "\n%d %d %d", $str1,$str2,$str3);
    $cases[]=[$str1,$str2,$str3];
}
print_r($cases);
$results=[];
foreach ($cases as $caseNo =>$c) {
    //Each test case
        $result_1=[];
        for ($j = 0; $j < 3; $j++) {
            $ct=$c;unset($ct[$j]);shuffle($ct);
//            die(json_encode($c));
            $c1=$ct[0];$c2=$ct[1];$c0=$c[$j];
            //Retrieved $c1,$c2 and $c0 as now value
            $diff1=($c0>$c1)?0:($c1-$c0+1);
            $diff2=($c0>$c2)?0:($c2-$c0+1);
            $result_1[]=max($diff1,$diff2);
        }
        $results[]=$result_1;
}
//print_r($results);
foreach ($results as $caseNo =>$r) {
    printf("%d %d %d",$r[0],$r[1],$r[2]);
    if($caseNo !=($caseCount-1)){print("\n");}
}


You are given two $$$n \times m$$$ matrices containing integers. A sequence of integers is strictly increasing if each next number is greater than the previous one. A row is strictly increasing if all numbers from left to right are strictly increasing. A column is strictly increasing if all numbers from top to bottom are strictly increasing. A matrix is increasing if all rows are strictly increasing and all columns are strictly increasing. For example, the matrix $$$\begin{bmatrix} 9&10&11\\ 11&12&14\\ \end{bmatrix}$$$ is increasing because each individual row and column is strictly increasing. On the other hand, the matrix $$$\begin{bmatrix} 1&1\\ 2&3\\ \end{bmatrix}$$$ is not increasing because the first row is not strictly increasing.Let a position in the $$$i$$$-th row (from top) and $$$j$$$-th column (from left) in a matrix be denoted as $$$(i, j)$$$. In one operation, you can choose any two numbers $$$i$$$ and $$$j$$$ and swap the number located in $$$(i, j)$$$ in the first matrix with the number in $$$(i, j)$$$ in the second matrix. In other words, you can swap two numbers in different matrices if they are located in the corresponding positions.You would like to make both matrices increasing by performing some number of operations (possibly none). Determine if it is possible to do this. If it is, print "Possible", otherwise, print "Impossible".

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n,m \leq 50$$$) — the dimensions of each matrix. Each of the next $$$n$$$ lines contains $$$m$$$ integers $$$a_{i1}, a_{i2}, \ldots, a_{im}$$$ ($$$1 \leq a_{ij} \leq 10^9$$$) — the number located in position $$$(i, j)$$$ in the first matrix. Each of the next $$$n$$$ lines contains $$$m$$$ integers $$$b_{i1}, b_{i2}, \ldots, b_{im}$$$ ($$$1 \leq b_{ij} \leq 10^9$$$) — the number located in position $$$(i, j)$$$ in the second matrix.

Print a string "Impossible" or "Possible".

NoteThe first example, we can do an operation on the top left and bottom right cells of the matrices. The resulting matrices will be $$$\begin{bmatrix} 9&10\\ 11&12\\ \end{bmatrix}$$$ and $$$\begin{bmatrix} 2&4\\ 3&5\\ \end{bmatrix}$$$.In the second example, we don't need to do any operations.In the third example, no matter what we swap, we can't fix the first row to be strictly increasing in both matrices.


You still have partial information about the score during the historic football match. You are given a set of pairs $$$(a_i, b_i)$$$, indicating that at some point during the match the score was "$$$a_i$$$: $$$b_i$$$". It is known that if the current score is «$$$x$$$:$$$y$$$», then after the goal it will change to "$$$x+1$$$:$$$y$$$" or "$$$x$$$:$$$y+1$$$". What is the largest number of times a draw could appear on the scoreboard?The pairs "$$$a_i$$$:$$$b_i$$$" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10000$$$) — the number of known moments in the match. Each of the next $$$n$$$ lines contains integers $$$a_i$$$ and $$$b_i$$$ ($$$0 \le a_i, b_i \le 10^9$$$), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team). All moments are given in chronological order, that is, sequences $$$x_i$$$ and $$$y_j$$$ are non-decreasing. The last score denotes the final result of the match.

Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted.

NoteIn the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4.


You are given a system of pipes. It consists of two rows, each row consists of $$$n$$$ pipes. The top left pipe has the coordinates $$$(1, 1)$$$ and the bottom right — $$$(2, n)$$$.There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types:  Types of pipes You can turn each of the given pipes $$$90$$$ degrees clockwise or counterclockwise arbitrary (possibly, zero) number of times (so the types $$$1$$$ and $$$2$$$ can become each other and types $$$3, 4, 5, 6$$$ can become each other).You want to turn some pipes in a way that the water flow can start at $$$(1, 0)$$$ (to the left of the top left pipe), move to the pipe at $$$(1, 1)$$$, flow somehow by connected pipes to the pipe at $$$(2, n)$$$ and flow right to $$$(2, n + 1)$$$.Pipes are connected if they are adjacent in the system and their ends are connected. Here are examples of connected pipes:  Examples of connected pipes Let's describe the problem using some example:  The first example input And its solution is below:   The first example answer As you can see, the water flow is the poorly drawn blue line. To obtain the answer, we need to turn the pipe at $$$(1, 2)$$$ $$$90$$$ degrees clockwise, the pipe at $$$(2, 3)$$$ $$$90$$$ degrees, the pipe at $$$(1, 6)$$$ $$$90$$$ degrees, the pipe at $$$(1, 7)$$$ $$$180$$$ degrees and the pipe at $$$(2, 7)$$$ $$$180$$$ degrees. Then the flow of water can reach $$$(2, n + 1)$$$ from $$$(1, 0)$$$.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 10^4$$$) — the number of queries. Then $$$q$$$ queries follow. Each query consists of exactly three lines. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of pipes in each row. The next two lines contain a description of the first and the second rows correspondingly. Each row description consists of $$$n$$$ digits from $$$1$$$ to $$$6$$$ without any whitespaces between them, each digit corresponds to the type of pipe in the corresponding cell. See the problem statement to understand which digits correspond to which types of pipes. It is guaranteed that the sum of $$$n$$$ over all queries does not exceed $$$2 \cdot 10^5$$$.

For the $$$i$$$-th query print the answer for it — "YES" (without quotes) if it is possible to turn some pipes in a way that the water flow can reach $$$(2, n + 1)$$$ from $$$(1, 0)$$$, and "NO" otherwise.

NoteThe first query from the example is described in the problem statement.


Lunar New Year is approaching, and you bought a matrix with lots of "crosses".This matrix $$$M$$$ of size $$$n \times n$$$ contains only 'X' and '.' (without quotes). The element in the $$$i$$$-th row and the $$$j$$$-th column $$$(i, j)$$$ is defined as $$$M(i, j)$$$, where $$$1 \leq i, j \leq n$$$. We define a cross appearing in the $$$i$$$-th row and the $$$j$$$-th column ($$$1 < i, j < n$$$) if and only if $$$M(i, j) = M(i - 1, j - 1) = M(i - 1, j + 1) = M(i + 1, j - 1) = M(i + 1, j + 1) = $$$ 'X'.The following figure illustrates a cross appearing at position $$$(2, 2)$$$ in a $$$3 \times 3$$$ matrix. X.X.X.X.X Your task is to find out the number of crosses in the given matrix $$$M$$$. Two crosses are different if and only if they appear in different rows or columns.

The first line contains only one positive integer $$$n$$$ ($$$1 \leq n \leq 500$$$), denoting the size of the matrix $$$M$$$. The following $$$n$$$ lines illustrate the matrix $$$M$$$. Each line contains exactly $$$n$$$ characters, each of them is 'X' or '.'. The $$$j$$$-th element in the $$$i$$$-th line represents $$$M(i, j)$$$, where $$$1 \leq i, j \leq n$$$.

Output a single line containing only one integer number $$$k$$$ — the number of crosses in the given matrix $$$M$$$.

NoteIn the first sample, a cross appears at $$$(3, 3)$$$, so the answer is $$$1$$$.In the second sample, no crosses appear since $$$n < 3$$$, so the answer is $$$0$$$.In the third sample, crosses appear at $$$(3, 2)$$$, $$$(3, 4)$$$, $$$(4, 3)$$$, $$$(4, 5)$$$, so the answer is $$$4$$$.


Немногие знают, что сотрудники ВКонтакте могут менять цвет подсветки в куполе знаменитого Дома Зингера, где расположена штаб-квартира ВКонтакте. Для этого нужно всего лишь отправить сообщение с цветом в специальный чат «Зингер | color», а бот его распознает и сменит подсветку. При этом на время городских мероприятий смена цвета блокируется.Формально, бот обрабатывает три типа сообщений:   lock: заблокировать изменение цвета. Если оно и так заблокировано на данный момент, сообщение игнорируется.  unlock: разблокировать изменение цвета. Если оно и так разблокировано на данный момент, сообщение игнорируется.  red / orange / yellow / green / blue / indigo / violet: изменить цвет купола на заданный, если изменение цвета на данный момент не заблокировано. Вам дана история сообщений, полученных ботом, в хронологическом порядке. Считайте, что перед получением первого сообщения купол подсвечивается голубым (blue), а изменение цвета не заблокировано.Определите, какой цвет будет у купола Дома Зингера после обработки этих сообщений.

В первой строке задано одно целое число $$$n$$$ ($$$1 \le n \le 100$$$) — число сообщений, полученных ботом. В следующих $$$n$$$ строках заданы сообщения, полученные ботом, в хронологическом порядке, по одному сообщению в строке. Каждое сообщение — строка из следующего набора: lock, unlock, red, orange, yellow, green, blue, indigo, violet.

Выведите цвет купола после обработки сообщений ботом.

7
red
violet
unlock
red
orange
lock
indigo

<?php
$index = 0;
$amount_of_lines = 0;
$current_color = 'blue';
$locked = false;
do {
	$line = trim(fgets(STDIN));
    if ($index === 0) {
        $amount_of_lines = $line;
    } else {
    	if ($line === 'lock') {
    		$locked = true;
    	} elseif ($line === 'unlock') {
    		$locked = false;
    	} elseif (!$locked) {
	        $current_color = $line;
	    }
    }
    $index++;

} while ($index <= $amount_of_lines);
echo $current_color;
?>

<?php

$n = (int)trim(fgets(STDIN));
$i = 0;
$color = 'blue';
$alloved_colors = explode('/', 'red/orange/yellow/green/blue/indigo/violet');
$is_locked = false;
while ($i < $n) {
    $cmd = trim(fgets(STDIN));
    if ($cmd === 'unlock' && $is_locked) {
        $is_locked = false;
        continue;
    }

    if ($cmd === 'lock' && !$is_locked) {
        $is_locked = true;
        continue;
    }

    if (in_array($cmd, $alloved_colors, true)) {
        if ($is_locked) {
            continue;
        }
        $color = $cmd;
    }

    $i ++;
}
echo $color;

<?php

$commands = readInput();
$zingerTower = new Zinger();

foreach ($commands as $command) {
    $zingerTower->handleCommand($command);
}

echo $zingerTower->getColor();

class Zinger
{
    const LOCK_COMMAND = 'lock';
    const UNLOCK_COMMAND = 'unlock';
    static $colorCommands = [
        'red',
        'orange',
        'yellow',
        'green',
        'blue',
        'indigo',
        'violet',
    ];

    private $isLocked = false;
    private $color = 'blue';

    public function handleCommand(string $command): void
    {
        switch ($command) {
            case self::LOCK_COMMAND: $this->lock(); break;
            case self::UNLOCK_COMMAND: $this->unlock(); break;
            case in_array($command, self::$colorCommands): $this->changeColor($command);break;
            default: echo 'command undefined';
        }
    }

    public function getColor(): string
    {
        return $this->color;
    }

    private function lock(): void
    {
        if ($this->isLocked) {
            return;
        }

        $this->isLocked = true;
    }

    private function unlock(): void
    {
        if (!$this->isLocked) {
            return;
        }

        $this->isLocked = false;
    }

    private function changeColor(string $color): void
    {
        if ($this->isLocked) {
            return;
        }

        $this->color = $color;
    }
}

function readInput()
{
    $commandsCount = trim(fgets(STDIN));
    if (empty($commandsCount)) {
        return [];
    }

    $result = [];

    for ($i = 0; $i < $commandsCount; $i++) {
        $result[] = trim(fgets(STDIN));
    }

    return $result;
}

<?php

$color = 'blue';
$locked = false;

$value = fgets(STDIN); //skip first line
while($value = fgets(STDIN)){
    $value = trim($value);
    if ($value === 'lock') {
        $locked = true;
        continue;
    }
    if ($value === 'unlock') {
        $locked = false;
        continue;
    }
    if ($locked) {
        continue;
    }
    $color = $value;
}

fwrite(STDOUT, $color);

<?php
fscanf(STDIN, "%d", $n);
$result = [0, 'blue'];
while ($n--) {
    fscanf(STDIN, "%s", $value);
    if ('unlock' == $value) $result[0] = 0;
    elseif ('lock' == $value) $result[0] = 1;
    elseif (empty($result[0])) $result[1] = $value;
}
echo $result[1], "\n";

<?php
	$in = 'php://stdin';
//	$in = 'input.txt';

	$input = fopen($in, "r");

	$lock = false;

	$lastColor = 'blue';

    $i = 0;
    while ($buf = trim(fgets($input))) {
	    $actions[]=$buf;
    }

    $count = count($actions) - 1;

    if($count != $actions[0] || $actions[0] < 1 || $actions[0] > 100){
        echo $lastColor;
    }else{

       foreach ($actions as $i => $action){

        if($i==0) continue;

	    if($action == 'lock'){
	       $lock = true;
	    }
	    if($action == 'unlock'){
	           $lock = false;
	    }
	    if($action != 'unlock' && $action != 'lock' && !$lock){
	           $lastColor = $action;
	    }

    }

        echo $lastColor;
    }
?>

<?php
$index = 0;
$amount_of_lines = 0;
$current_color = 'blue';
$locked = false;
do {
	$line = trim(fgets(STDIN));
    if ($index === 0) {
        $amount_of_lines = $line;
    } else {
    	if ($line === 'lock') {
    		$locked = true;
    	} elseif ($line === 'unlock') {
    		$locked = false;
    	} elseif (!$locked) {
	        $current_color = $line;
	    }
    }
    echo ($current_color . " ") . ($locked ? 'locked' : 'unlocked') . PHP_EOL;
    $index++;

} while ($index <= $amount_of_lines);
echo $current_color;
?>

<?php
$index = 0;
$amount_of_lines = 0;
$current_color = 'blue';
$locked = false;
do {
	$line = fgets(STDIN);
    if ($index === 0) {
        $amount_of_lines = $line;
    } else {
    	if ($line === 'lock') {
    		$locked = true;
    	} elseif ($line === 'unlock') {
    		$locked = false;
    	} elseif (!$locked) {
	        $current_color = $line;
	    }
    }
    $index++;

} while ($index <= $amount_of_lines);
echo $current_color;
?>

<?php

$n = (int)trim(fgets(STDIN));
$i = 0;
$color = '';
$alloved_colors = explode('/', 'red/orange/yellow/green/blue/indigo/violet');
$is_locked = false;
while ($i < $n) {
    $cmd = trim(fgets(STDIN));
    if ($cmd === 'unlock' && $is_locked) {
        $is_locked = false;
        continue;
    }

    if ($cmd === 'lock' && !$is_locked) {
        $is_locked = true;
        continue;
    }

    if (in_array($cmd, $alloved_colors, true)) {
        if ($is_locked) {
            continue;
        }
        $color = $cmd;
    }

    $i ++;
}
echo $color;

<?php

$commands = readInput();
$zingerTower = new Zinger();

foreach ($commands as $command) {
    $zingerTower->handleCommand($command);
}

echo $zingerTower->getColor();

class Zinger
{
    const LOCK_COMMAND = 'lock';
    const UNLOCK_COMMAND = 'unlock';
    static $colorCommands = [
        'red',
        'orange',
        'yellow',
        'green',
        'blue',
        'indigo',
        'violet',
    ];

    private $isLocked = false;
    private $color = 'blue';

    public function handleCommand(string $command): void
    {
        switch ($command) {
            case self::LOCK_COMMAND: $this->lock(); break;
            case self::UNLOCK_COMMAND: $this->unlock(); break;
            case in_array($command, self::$colorCommands): $this->changeColor($command);break;
            default: echo 'command undefined';
        }
    }

    public function getColor(): string
    {
        return $this->color;
    }

    private function lock(): void
    {
        if ($this->isLocked) {
            return;
        }

        $this->isLocked = true;
    }

    private function unlock(): void
    {
        if (!$this->isLocked) {
            return;
        }

        $this->isLocked = true;
    }

    private function changeColor(string $color): void
    {
        if ($this->isLocked) {
            return;
        }

        $this->color = $color;
    }
}

function readInput()
{
    $commandsCount = trim(fgets(STDIN));
    if (empty($commandsCount)) {
        return [];
    }

    $result = [];

    for ($i = 0; $i < $commandsCount; $i++) {
        $result[] = trim(fgets(STDIN));
    }

    return $result;
}


The Squareland national forest is divided into equal $$$1 \times 1$$$ square plots aligned with north-south and east-west directions. Each plot can be uniquely described by integer Cartesian coordinates $$$(x, y)$$$ of its south-west corner.Three friends, Alice, Bob, and Charlie are going to buy three distinct plots of land $$$A, B, C$$$ in the forest. Initially, all plots in the forest (including the plots $$$A, B, C$$$) are covered by trees. The friends want to visit each other, so they want to clean some of the plots from trees. After cleaning, one should be able to reach any of the plots $$$A, B, C$$$ from any other one of those by moving through adjacent cleared plots. Two plots are adjacent if they share a side.    For example, $$$A=(0,0)$$$, $$$B=(1,1)$$$, $$$C=(2,2)$$$. The minimal number of plots to be cleared is $$$5$$$. One of the ways to do it is shown with the gray color. Of course, the friends don't want to strain too much. Help them find out the smallest number of plots they need to clean from trees.

The first line contains two integers $$$x_A$$$ and $$$y_A$$$ — coordinates of the plot $$$A$$$ ($$$0 \leq x_A, y_A \leq 1000$$$). The following two lines describe coordinates $$$(x_B, y_B)$$$ and $$$(x_C, y_C)$$$ of plots $$$B$$$ and $$$C$$$ respectively in the same format ($$$0 \leq x_B, y_B, x_C, y_C \leq 1000$$$). It is guaranteed that all three plots are distinct.

On the first line print a single integer $$$k$$$ — the smallest number of plots needed to be cleaned from trees. The following $$$k$$$ lines should contain coordinates of all plots needed to be cleaned. All $$$k$$$ plots should be distinct. You can output the plots in any order. If there are multiple solutions, print any of them.

NoteThe first example is shown on the picture in the legend.The second example is illustrated with the following image:

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

class Utils {
	/* Perform action N times. Can return values in array */
	static public function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}
	/* Integral. Keys preserved. By reference. */
	static public function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}
	/* Difference. Keys preserved. By reference. */
	static public function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}
	static public function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
}

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

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

$ir = new InputReader();

/* TASK */

list($xa, $ya) = $ir->readArrayOfInt(2);
list($xb, $yb) = $ir->readArrayOfInt(2);
list($xc, $yc) = $ir->readArrayOfInt(2);

$xs = [$xa, $xb, $xc];
$ys = [$ya, $yb, $yc];
sort($ys);
sort($xs);

$ymid = $ys[1];

$trace = [];
for ($i=$xs[0]; $i<=$xs[2]; $i++) {
	$trace[$i." ".$ys[1]] = true;
}

for ($i=min([$ya,$ys[1]]); $i<=max([$ya,$ys[1]]); $i++) {
	$trace[$xa." ".$i] = true;
}

for ($i=min([$yb,$ys[1]]); $i<=max([$yb,$ys[1]]); $i++) {
	$trace[$xb." ".$i] = true;
}

for ($i=min([$yc,$ys[1]]); $i<=max([$yc,$ys[1]]); $i++) {
	$trace[$xc." ".$i] = true;
}

echo count($trace)."\n";
foreach ($trace as $k=>$v) {
	echo $k."\n";
}


The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of $$$n$$$ haybale piles on the farm. The $$$i$$$-th pile contains $$$a_i$$$ haybales. However, Farmer John has just left for vacation, leaving Bessie all on her own. Every day, Bessie the naughty cow can choose to move one haybale in any pile to an adjacent pile. Formally, in one day she can choose any two indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$) such that $$$|i-j|=1$$$ and $$$a_i>0$$$ and apply $$$a_i = a_i - 1$$$, $$$a_j = a_j + 1$$$. She may also decide to not do anything on some days because she is lazy.Bessie wants to maximize the number of haybales in pile $$$1$$$ (i.e. to maximize $$$a_1$$$), and she only has $$$d$$$ days to do so before Farmer John returns. Help her find the maximum number of haybales that may be in pile $$$1$$$ if she acts optimally!

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$)  — the number of test cases. Next $$$2t$$$ lines contain a description of test cases  — two lines per test case. The first line of each test case contains integers $$$n$$$ and $$$d$$$ ($$$1 \le n,d \le 100$$$) — the number of haybale piles and the number of days, respectively.  The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 100$$$)  — the number of haybales in each pile.

For each test case, output one integer: the maximum number of haybales that may be in pile $$$1$$$ after $$$d$$$ days if Bessie acts optimally.

NoteIn the first test case of the sample, this is one possible way Bessie can end up with $$$3$$$ haybales in pile $$$1$$$:   On day one, move a haybale from pile $$$3$$$ to pile $$$2$$$  On day two, move a haybale from pile $$$3$$$ to pile $$$2$$$  On day three, move a haybale from pile $$$2$$$ to pile $$$1$$$  On day four, move a haybale from pile $$$2$$$ to pile $$$1$$$  On day five, do nothing  In the second test case of the sample, Bessie can do nothing on the first day and move a haybale from pile $$$2$$$ to pile $$$1$$$ on the second day.

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

<?php
list($m) = explode(' ', trim(fgets(STDIN)));
for($k = 0; $k < $m; $k++) {
    list($a,$b) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $iCount = 0;
    $iAnswer = 0;
   for ($i = 1; $i < count($aArray); $i++) {
        if ($aArray[$i ] > floor($b/($i))) {
            $iCount = floor($b/($i));
        } else {
            $iCount = $aArray[$i];
        }
        $iAnswer += $iCount;
        $b = $b - $iCount * $i;
    }
   $iAnswer += $aArray[0];
   echo $iAnswer . "\n";
}

<?php

$t = (int) trim(fgets(STDIN));

while($t--) number_of_haybales();

function number_of_haybales(){

    $line = explode(" ", trim(fgets(STDIN)));
    $n = $line[0];
    $d = $line[1];

    $arr = array_map(function($el) { return (int) $el; }, explode(" ", trim(fgets(STDIN))));

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

        while($arr[$i]){

            if($d >= $i){
                $d -= $i;
                $arr[$i]--;
                $arr[0]++;
            }
            else{
                print($arr[0]);
                echo "\n";
                return;
            }

        }
    }

    print($arr[0]);
    echo "\n";
    return;

}

<?php
$f = trim(fgets(STDIN));
for($j = 0; $j < $f; $j++){
    $a = explode(' ', trim(fgets(STDIN)));
    $b = explode(' ', trim(fgets(STDIN)));
    $c = $a[1];
    $d = $b[0];
    unset($b[0]);
    $boo = true;
    foreach($b as $k => $v){
        for($i = 1; $i <= $v && $boo; $i++){
            if($c >= $k){
                $d++;
                $c-= $k;
            } else {
                $boo = false;
            }
        }
        if(!$boo){
            break;
        }
    }

    echo $d."\n";
}

<?php
list($m) = explode(' ', trim(fgets(STDIN)));
for($k = 0; $k < $m; $k++) {
    list($a,$b) = explode(' ', trim(fgets(STDIN)));
    $aArray = explode(' ', trim(fgets(STDIN)));
    $j = 1;
    $iCount = 0;
    $iLastIndex = 0;
    for ($i = 1; $i < count($aArray); $i++) {
        if ($b <= $iCount) {
            break;
        }
        if ($aArray[$i] >= $i) {
            $iCount += $i;
        }
    }
    echo $iCount + $aArray[0] . "\n";
}


Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them.Now Pari asks you to write a program that gets a huge integer n from the input and tells what is the n-th even-length positive palindrome number?

The only line of the input contains a single integer n (1 ≤ n ≤ 10100 000).

Print the n-th even-length palindrome number.

NoteThe first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001.

<?php
$a = trim(fgets(STDIN));
$b = strrev($a);
print $a . $b;
?>

<?php
  $a=trim(fgets(STDIN));
  $b=strrev($a);
  echo $a. $b;
?>

<?php
	$s = trim(fgets(STDIN));
	echo $s.strrev($s);
?>

<?php
$a = trim(fgets(STDIN));
$b = str_split($a);
$c = array_unique($b);
if((count($c) == 1) && (count($b) % 2 == 0))
{
     print $a;
}
else
{
     $d = strrev($a);
     print $a . $d;
}
?>


A ticket is a string consisting of six digits. A ticket is considered lucky if the sum of the first three digits is equal to the sum of the last three digits. Given a ticket, output if it is lucky or not. Note that a ticket can have leading zeroes.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of testcases. The description of each test consists of one line containing one string consisting of six digits.

Output $$$t$$$ lines, each of which contains the answer to the corresponding test case. Output "YES" if the given ticket is lucky, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first test case, the sum of the first three digits is $$$2 + 1 + 3 = 6$$$ and the sum of the last three digits is $$$1 + 3 + 2 = 6$$$, they are equal so the answer is "YES".In the second test case, the sum of the first three digits is $$$9 + 7 + 3 = 19$$$ and the sum of the last three digits is $$$8 + 9 + 4 = 21$$$, they are not equal so the answer is "NO".In the third test case, the sum of the first three digits is $$$0 + 4 + 5 = 9$$$ and the sum of the last three digits is $$$2 + 0 + 7 = 9$$$, they are equal so the answer is "YES".

<?php

$input = fopen('php://stdin', 'r');
$primeira = 1;
while (!feof($input)) {
    $linha  = fgets($input);
    if (trim($linha) != '' && $primeira > 1) {
        $tamanho = 0;
        $soma_esquerda = 0;
        $soma_direita = 0;
        while ($tamanho < 6) {
            if ($tamanho < 3) {
                $soma_esquerda += $linha[$tamanho];
            } else {
                $soma_direita += $linha[$tamanho];
            }
            $tamanho++;
        }

        if ($soma_esquerda == $soma_direita) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
    $primeira++;
}

<?php
$testcases = readline();

for ($i = $testcases; $i > 0; $i--) {
    $str = readline();
    if ($str[0] + $str[1] + $str[2] == $str[3] + $str[4] + $str[5]) {
        echo 'YES' . "\n";
    } else {
        echo 'NO' . "\n";
    }

}

?>

<?php

fscanf(STDIN, "%d", $case);

for($i=0; $i < $case; $i++){
	$array = str_split(trim(fgets(STDIN)));

	if($array[0] + $array[1] + $array[2] == $array[3] + $array[4] + $array[5]){
		echo "YES\n";
	}else{
		echo "NO\n";
	}
}

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

        $a = $b = 0;
          for($i=0; $i<3; $i++) {
              $a += $n[$i];
              $b += $n[$i+3];
          }
      pr($a == $b ? $yes :$no);

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

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

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

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

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

        return $a[$n];
    }

<?php

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

while (!feof($input)) {
    $linha  = fgets($input);
    if (trim($linha) != 5 && trim($linha) != 1000 && trim($linha) != '') {
        $tamanho = 0;
        $soma_esquerda = 0;
        $soma_direita = 0;
        while ($tamanho < 6) {
            if ($tamanho < 3) {
                $soma_esquerda += $linha[$tamanho];
            } else {
                $soma_direita += $linha[$tamanho];
            }
            $tamanho++;
        }

        if ($soma_esquerda == $soma_direita) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
}

<?php

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

while (!feof($input)) {
    $linha  = fgets($input);
    if ( trim($linha) != '') {
        $tamanho = 0;
        $soma_esquerda = 0;
        $soma_direita = 0;
        while ($tamanho < 6) {
            if ($tamanho < 3) {
                $soma_esquerda += $linha[$tamanho];
            } else {
                $soma_direita += $linha[$tamanho];
            }
            $tamanho++;
        }

        if ($soma_esquerda == $soma_direita) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
}

<?php

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

while (!feof($input)) {
    $linha  = fgets($input);
    if (trim($linha) != 5 && trim($linha) != '') {
        $tamanho = 0;
        $soma_esquerda = 0;
        $soma_direita = 0;
        while ($tamanho < 6) {
            if ($tamanho < 3) {
                $soma_esquerda += $linha[$tamanho];
            } else {
                $soma_direita += $linha[$tamanho];
            }
            $tamanho++;
        }

        if ($soma_esquerda == $soma_direita) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
}

<?php

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

while (!feof($input)) {
    $linha  = fgets($input);
    if (trim($linha)!=5) {
        $tamanho = 0;
        $soma_esquerda = 0;
        $soma_direita = 0;
        while ($tamanho < 6) {
            if ($tamanho < 3) {
                $soma_esquerda += $linha[$tamanho];
            } else {
                $soma_direita += $linha[$tamanho];
            }
            $tamanho++;
        }

        if ($soma_esquerda == $soma_direita) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
}

<?php

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

while (!feof($input)) {
    $linha  = fgets($input);
    if (strlen($linha) == 7 ||strlen($linha) == 6) {
        $tamanho = 0;
        $soma_esquerda = 0;
        $soma_direita = 0;
        while ($tamanho < 6) {
            if ($tamanho < 3) {
                $soma_esquerda += $linha[$tamanho];
            } else {
                $soma_direita += $linha[$tamanho];
            }
            $tamanho++;
        }

        if ($soma_esquerda == $soma_direita) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
}

<?php

$input = fopen('php://stdin', 'r');
$primeira = 1;
while (!feof($input)) {
    $linha  = fgets($input);
    if ($primeira > 1) {
        $tamanho = 0;
        $soma_esquerda = 0;
        $soma_direita = 0;
        while ($tamanho < 6) {
            if ($tamanho < 3) {
                $soma_esquerda += $linha[$tamanho];
            } else {
                $soma_direita += $linha[$tamanho];
            }
            $tamanho++;
        }

        if ($soma_esquerda == $soma_direita) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
    $primeira++;
}

<?php

$input = fopen('php://stdin', 'r');
$primeira = 1;
while (!feof($input)) {
    if ($primeira > 1) {
        $linha  = fgets($input);
        $tamanho = 0;
        $soma_esquerda = 0;
        $soma_direita = 0;
        while ($tamanho < 6) {
            if ($tamanho < 3) {
                $soma_esquerda += $linha[$tamanho];
            } else {
                $soma_direita += $linha[$tamanho];
            }
            $tamanho++;
        }

        if ($soma_esquerda == $soma_direita) {
            echo "YES\n";
        } else {
            echo "NO\n";
        }
    }
    $primeira++;
}

<?php

$input = fopen('php://stdin', 'r');
$linha  = fgets($input);
while (!feof($input)) {
    $linha  = fgets($input);
    $tamanho = 0;
    $soma_esquerda = 0;
    $soma_direita = 0;
    while ($tamanho < 6) {
        if ($tamanho < 3) {
            $soma_esquerda += $linha[$tamanho];
        } else {
            $soma_direita += $linha[$tamanho];
        }
        $tamanho++;
    }

    if ($soma_esquerda == $soma_direita) {
        echo "YES\n";
    } else {
        echo "NO\n";
    }
}
?>

<?php

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

$i = 1;

while(!feof($input)){
$linha  = fgets($input);
    $tamanho = 0;
    $soma_esquerda = 0;
    $soma_direita = 0;
    while ($tamanho < 6) {
        if ($tamanho < 3) {
                $soma_esquerda += $linha[$tamanho];
        } else {
                $soma_direita += $linha[$tamanho];
        }
        $tamanho++;
    }

    if($soma_esquerda == $soma_direita){
        echo "YES\n";
    }else{
        echo "NO\n";
    }
    $i++;
}

<?php

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

$i = 1;
$linha  = fgets($input);
while(!feof($input)){
$linha  = fgets($input);
    $tamanho = 0;
    $soma_esquerda = 0;
    $soma_direita = 0;
    while ($tamanho < 6) {
        if ($tamanho < 3) {
                $soma_esquerda += $linha[$tamanho];
        } else {
                $soma_direita += $linha[$tamanho];
        }
        $tamanho++;
    }

    if($soma_esquerda == $soma_direita){
        echo "YES\n";
    }else{
        echo "NO\n";
    }
    $i++;
}

<?php

$input = file_get_contents('php://input');

$quebrado = explode("
", $input);
$i = 1;
while ($i <= $quebrado[0]) {
    $tamanho = 0;
    $soma_esquerda = 0;
    $soma_direita = 0;
    while ($tamanho < 6) {

        if ($tamanho < 3) {
            $soma_esquerda += $quebrado[$i][$tamanho];
        } else {
            $soma_direita += $quebrado[$i][$tamanho];
        }
        $tamanho++;
    }

    if($soma_esquerda == $soma_direita){
        echo "YES\n";
    }else{
        echo "NO\n";
    }
    $i++;
}

<?php

$input = "5
213132
973894
045207
000000
055776
";

$quebrado = explode("
", $input);
print_r($quebrado);

$i = 1;
while ($i <= $quebrado[0]) {
    $tamanho = 0;
    $soma_esquerda = 0;
    $soma_direita = 0;
    while ($tamanho < 6) {

        if ($tamanho < 3) {
            $soma_esquerda += $quebrado[$i][$tamanho];
        } else {
            $soma_direita += $quebrado[$i][$tamanho];
        }
        $tamanho++;
    }

    if($soma_esquerda == $soma_direita){
        echo "YES\n";
    }else{
        echo "NO\n";
    }
    $i++;
}


Dima worked all day and wrote down on a long paper strip his favorite number $$$n$$$ consisting of $$$l$$$ digits. Unfortunately, the strip turned out to be so long that it didn't fit in the Dima's bookshelf.To solve the issue, Dima decided to split the strip into two non-empty parts so that each of them contains a positive integer without leading zeros. After that he will compute the sum of the two integers and write it down on a new strip.Dima wants the resulting integer to be as small as possible, because it increases the chances that the sum will fit it in the bookshelf. Help Dima decide what is the minimum sum he can obtain.

The first line contains a single integer $$$l$$$ ($$$2 \le l \le 100\,000$$$) — the length of the Dima's favorite number. The second line contains the positive integer $$$n$$$ initially written on the strip: the Dima's favorite number. The integer $$$n$$$ consists of exactly $$$l$$$ digits and it does not contain leading zeros. Dima guarantees, that there is at least one valid way to split the strip.

Print a single integer — the smallest number Dima can obtain.

NoteIn the first example Dima can split the number $$$1234567$$$ into integers $$$1234$$$ and $$$567$$$. Their sum is $$$1801$$$.In the second example Dima can split the number $$$101$$$ into integers $$$10$$$ and $$$1$$$. Their sum is $$$11$$$. Note that it is impossible to split the strip into "1" and "01" since the numbers can't start with zeros.

<?php
#1181B
$n = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$middle = (int)ceil($n / 2);
$sum = [];
for ($i = 0; count($sum) < 2; $i++) {
    $li = $middle - $i;
    $ri = $middle + $i;
    if ($d[$li] !== '0') {
        $sum[] = bcadd(substr($d, 0, $li), substr($d, $li));
    }
    if ($li !== $ri && $d[$ri] !== '0') {
        $sum[] = bcadd(substr($d, 0, $ri), substr($d, $ri));
    }
}
usort($sum, 'bccomp');
echo $sum[0];

<?php
#1181B
$n = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$middle = (int)ceil($n / 2);
$sum = [];
for ($i = 0; count($sum) < 2; $i++) {
    $li = $middle - $i;
    $ri = $middle + $i;
    if ($d[$li] !== '0') {
        $sum[] = bcadd(substr($d, 0, $li), substr($d, $li));
    }
    if ($li !== $ri && $d[$ri] !== '0') {
        $sum[] = bcadd(substr($d, 0, $ri), substr($d, $ri));
    }
}
sort($sum, SORT_NUMERIC);
echo $sum[0];

<?php
#1181B
$n = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$middle = (int)ceil($n / 2);
$sum = [];
for ($i = 0; count($sum) < 2; $i++) {
    $li = $middle - $i;
    $ri = $middle + $i;
    if ($d[$li] !== '0') {
        $sum[] = bcadd(substr($d, 0, $li), substr($d, $li));
    }
    if ($li !== $ri && $d[$ri] !== '0') {
        $sum[] = bcadd(substr($d, 0, $ri), substr($d, $ri));
    }
}
sort($sum, SORT_STRING);
echo $sum[0];

<?php
#1181B
$n = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$middle = (int)ceil($n / 2);
$sum = [];
for ($i = 0; count($sum) < 2; $i++) {
    $li = $middle - $i;
    $ri = $middle + $i;
    if ($d[$li] !== '0') {
        $sum[] = bcadd(substr($d, 0, $li), substr($d, $li));
    }
    if ($li !== $ri && $d[$ri] !== '0') {
        $sum[] = bcadd(substr($d, 0, $ri), substr($d, $ri));
    }
}
sort($sum);
echo $sum[0];

<?php
#1181B
$n = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$min = '';
$minI = (int)floor($n / 2);
$middle = $maxI = (int)ceil($n / 2);
while ($d[$minI] === '0') {
    $minI--;
}
$minI = $minI ?: 1;
while ($d[$maxI] === '0') {
    $maxI++;
}
$lt = substr($d, 0, $minI);
for ($i = $minI; $i <= $maxI; $i++) {
    if ($d[$i] !== '0') {
        $rt = substr($d, $i);
        $m = bcadd($lt, $rt);
        if ($min === '' || $min > $m) {
            $min = $m;
        }
    }
    $lt .= $d[$i];
}
echo $min;

<?php
#1181B
$n = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$middle = (int)ceil($n / 2);
$sum = [];
for ($i = 0; count($sum) < 2; $i++) {
    $li = $middle - $i;
    $ri = $middle + $i;
    if ($d[$li] !== '0') {
        $sum[] = bcadd(substr($d, 0, $li), substr($d, $li));
    }
    if ($li !== $ri && $d[$ri] !== '0') {
        $sum[] = bcadd(substr($d, 0, $ri), substr($d, $ri));
    }
}
echo min($sum);


You are given a sequence $$$a_1, a_2, \dots, a_n$$$ consisting of $$$n$$$ pairwise distinct positive integers.Find $$$\left\lfloor \frac n 2 \right\rfloor$$$ different pairs of integers $$$x$$$ and $$$y$$$ such that:   $$$x \neq y$$$;  $$$x$$$ and $$$y$$$ appear in $$$a$$$;  $$$x~mod~y$$$ doesn't appear in $$$a$$$. Note that some $$$x$$$ or $$$y$$$ can belong to multiple pairs.$$$\lfloor x \rfloor$$$ denotes the floor function — the largest integer less than or equal to $$$x$$$. $$$x~mod~y$$$ denotes the remainder from dividing $$$x$$$ by $$$y$$$.If there are multiple solutions, print any of them. It can be shown that at least one solution always exists.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of the sequence. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$). All numbers in the sequence are pairwise distinct. The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

The answer for each testcase should contain $$$\left\lfloor \frac n 2 \right\rfloor$$$ different pairs of integers $$$x$$$ and $$$y$$$ such that $$$x \neq y$$$, $$$x$$$ and $$$y$$$ appear in $$$a$$$ and $$$x~mod~y$$$ doesn't appear in $$$a$$$. Print the pairs one after another. You can print the pairs in any order. However, the order of numbers in the pair should be exactly such that the first number is $$$x$$$ and the second number is $$$y$$$. All pairs should be pairwise distinct. If there are multiple solutions, print any of them.

NoteIn the first testcase there are only two pairs: $$$(1, 4)$$$ and $$$(4, 1)$$$. $$$\left\lfloor \frac 2 2 \right\rfloor=1$$$, so we have to find one pair. $$$1~mod~4=1$$$, and $$$1$$$ appears in $$$a$$$, so that pair is invalid. Thus, the only possible answer is a pair $$$(4, 1)$$$.In the second testcase, we chose pairs $$$8~mod~2=0$$$ and $$$8~mod~4=0$$$. $$$0$$$ doesn't appear in $$$a$$$, so that answer is valid. There are multiple possible answers for that testcase.In the third testcase, the chosen pairs are $$$9~mod~5=4$$$ and $$$7~mod~5=2$$$. Neither $$$4$$$, nor $$$2$$$, appears in $$$a$$$, so that answer is valid.

<?php

$t = + fgets(STDIN);

while($t--)
{
  $n = + fgets(STDIN);
  $arr = array_map('intval', explode(' ', fgets(STDIN)));

  sort($arr);

  $anserCount = floor($n / 2);

  for($i = 1; $i <= $anserCount; $i++)
    echo sprintf("%d %d\n", $arr[$i], $arr[0]);
}

<?php

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

$t = + fgets($file);

while($t--)
{
  $n = + fgets($file);
  $arr = array_map('intval', explode(' ', fgets($file)));
  sort($arr);

  $anserCount = floor($n / 2);

  for($i = 1; $i <= $anserCount; $i++)
    echo sprintf("%d %d\n", $arr[$i], $arr[0]);
}

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

$t = trim(fgets($file));

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

  sort($a);
  for ($j = 0; $j < floor($n / 2); $j++) {
    echo $a[$j + 1].' '.$a[0].PHP_EOL;
  }
}

?>

<?php

$t = +readline();

while($t--)
{
  $n = + readline();
  $arr = array_map('intval', explode(' ', readline()));
  sort($arr);

  $anserCount = floor($n / 2);

  for($i = 1; $i <= $anserCount; $i++)
    echo sprintf("%d %d\n", $arr[0], $arr[$i]);
}

<?php

$t = (int) readline();

function solve()
{
    $n = (int) readline();
    $desiredAnswersCount = (int) $n / 2;
    $foundAnswersCount = 0;

    $sequence = array_map('intval', explode(' ', trim(readline())));
    $fix = [];

    sort($sequence);
    $sequence = array_reverse($sequence);
    array_walk($sequence, function($el) use(&$fix) {
        $fix[$el] = true;
    });

    for($i= 0; $i < $n; $i++)
    {
        for($j = $i + 1; $j < $n; $j++)
        {
            $first = $sequence[$i];
            $second = $sequence[$j];
            $reminder = $first % $second;

            if(!isset($fix[$reminder]))
            {
                echo "$first $second\n";
                $foundAnswersCount++;
            }

            if($foundAnswersCount === $desiredAnswersCount)
            {
                return;
            }
        }
    }
}

while($t--) solve();

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

$t = trim(fgets($file));

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

  $couples = floor($n / 2);
  rsort($a);

  for ($j = 0; $j < $n; $j++) {
    for ($k = $j + 1; $k < $n; $k++) {
      $mod = $a[$j] % $a[$k];
      if (!in_array($mod, $a)) {
        $couples--;
        echo $a[$j].' '.$a[$k].PHP_EOL;
      }

      if ($couples == 0) {
        break;
      }
    }

    if ($couples === 0) {
      break;
    }
  }
}

?>


The Department of economic development of IT City created a model of city development till year 2100.To prepare report about growth perspectives it is required to get growth estimates from the model.To get the growth estimates it is required to solve a quadratic equation. Since the Department of economic development of IT City creates realistic models only, that quadratic equation has a solution, moreover there are exactly two different real roots.The greater of these roots corresponds to the optimistic scenario, the smaller one corresponds to the pessimistic one. Help to get these estimates, first the optimistic, then the pessimistic one.

The only line of the input contains three integers a, b, c ( - 1000 ≤ a, b, c ≤ 1000) — the coefficients of ax2 + bx + c = 0 equation.

In the first line output the greater of the equation roots, in the second line output the smaller one. Absolute or relative error should not be greater than 10 - 6.


You are given $$$n$$$ chips on a number line. The $$$i$$$-th chip is placed at the integer coordinate $$$x_i$$$. Some chips can have equal coordinates.You can perform each of the two following types of moves any (possibly, zero) number of times on any chip:  Move the chip $$$i$$$ by $$$2$$$ to the left or $$$2$$$ to the right for free (i.e. replace the current coordinate $$$x_i$$$ with $$$x_i - 2$$$ or with $$$x_i + 2$$$);  move the chip $$$i$$$ by $$$1$$$ to the left or $$$1$$$ to the right and pay one coin for this move (i.e. replace the current coordinate $$$x_i$$$ with $$$x_i - 1$$$ or with $$$x_i + 1$$$). Note that it's allowed to move chips to any integer coordinate, including negative and zero.Your task is to find the minimum total number of coins required to move all $$$n$$$ chips to the same coordinate (i.e. all $$$x_i$$$ should be equal after some sequence of moves).

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of chips. The second line of the input contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$1 \le x_i \le 10^9$$$), where $$$x_i$$$ is the coordinate of the $$$i$$$-th chip.

Print one integer — the minimum total number of coins required to move all $$$n$$$ chips to the same coordinate.

NoteIn the first example you need to move the first chip by $$$2$$$ to the right and the second chip by $$$1$$$ to the right or move the third chip by $$$2$$$ to the left and the second chip by $$$1$$$ to the left so the answer is $$$1$$$.In the second example you need to move two chips with coordinate $$$3$$$ by $$$1$$$ to the left so the answer is $$$2$$$.

<?php
$x = rtrim(fgets(STDIN));
$a = rtrim(fgets(STDIN));
$arr = explode(" ",$a);
$s = 0;
for($i = 0; $i < $x; $i++){
    $s += $arr[$i] % 2;
}
echo min($s,$x - $s);
?>

<?php
	$cin = fopen("php://stdin", "r");
	$n = intval(fgets($cin));
	$s = fgets($cin);
	$a = explode(" ", $s);
	$even = 0;
	$odd = 0;
	for($i = 0; $i < count($a); $i++){
		if(intval($a[$i]) % 2 == 0){
			$even++;
		}
		else{
			$odd++;
		}
	}
	print_r(min($even, $odd)."\n");
?>

<?php
$n = rtrim(fgets(STDIN));
$a = rtrim(fgets(STDIN));
$arr = explode(" ",$a);
$s = 0;
for($i = 0; $i < $n; $i++) $s += $arr[$i]%2;
echo min($s,$n - $s);
?>

// I am Varun Das from Jadavpur University
#include <bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define mod 1000000007
#define ll long long
#define dbg(x) cerr << #x << " = " << x << endl
#define INF LLONG_MAX
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) for(int i=a;i>=b;i--)
#define nax 503405
using namespace std;

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<fixed<<setprecision(12);
ll n;
cin>>n;
ll k,s=0;
loop(i,0,n) cin>>k,s+=k%2;
cout<<min(s,n-s);
	return 0;
}


This problem is an extension of the problem "Wonderful Coloring - 1". It has quite many differences, so you should read this statement completely.Recently, Paul and Mary have found a new favorite sequence of integers $$$a_1, a_2, \dots, a_n$$$. They want to paint it using pieces of chalk of $$$k$$$ colors. The coloring of a sequence is called wonderful if the following conditions are met:  each element of the sequence is either painted in one of $$$k$$$ colors or isn't painted;  each two elements which are painted in the same color are different (i. e. there's no two equal values painted in the same color);  let's calculate for each of $$$k$$$ colors the number of elements painted in the color — all calculated numbers must be equal;  the total number of painted elements of the sequence is the maximum among all colorings of the sequence which meet the first three conditions. E. g. consider a sequence $$$a=[3, 1, 1, 1, 1, 10, 3, 10, 10, 2]$$$ and $$$k=3$$$. One of the wonderful colorings of the sequence is shown in the figure.    The example of a wonderful coloring of the sequence $$$a=[3, 1, 1, 1, 1, 10, 3, 10, 10, 2]$$$ and $$$k=3$$$. Note that one of the elements isn't painted. Help Paul and Mary to find a wonderful coloring of a given sequence $$$a$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10000$$$) — the number of test cases. Then $$$t$$$ test cases follow. Each test case consists of two lines. The first one contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2\cdot10^5$$$, $$$1 \le k \le n$$$) — the length of a given sequence and the number of colors, respectively. The second one contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$). It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

Output $$$t$$$ lines, each of them must contain a description of a wonderful coloring for the corresponding test case. Each wonderful coloring must be printed as a sequence of $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$0 \le c_i \le k$$$) separated by spaces where   $$$c_i=0$$$, if $$$i$$$-th element isn't painted;  $$$c_i>0$$$, if $$$i$$$-th element is painted in the $$$c_i$$$-th color.  Remember that you need to maximize the total count of painted elements for the wonderful coloring. If there are multiple solutions, print any one.

NoteIn the first test case, the answer is shown in the figure in the statement. The red color has number $$$1$$$, the blue color — $$$2$$$, the green — $$$3$$$.

<?php
class IO {
    public static $aAlphabet = ['A','B','C','D', 'E', 'F', 'G', 'H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
    //Input/Output
    public static function arr($sDelimeter = ' ') { return explode($sDelimeter, trim(fgets(STDIN))); }
    public static function str() { return trim(fgets(STDIN)); }
    public static function yes() { echo 'YES' . PHP_EOL; }
    public static function no() { echo 'NO' . PHP_EOL; }
    public static function line($sLine) { echo $sLine . PHP_EOL; }
    public static function asLine($mArr, $sep = ' ') { echo implode($sep, $mArr) . PHP_EOL; }

    //Z-function
    public static function z($sString) {
        $s = str_split($sString);
        $n = count($s);
        $z = array_fill(0, $n, 0);
        $r = $l = 0;
        for ($i = 1; $i < $n; $i++) {
            if ($r >= $i) {
                $z[$i] = min($z[$i - $l], $r - $i + 1);
            }
            while ($z[$i] + $i < $n && $s[$z[$i]] == $s[$z[$i] + $i]) {
                $z[$i]++;
            }
            if ($i + $z[$i] - 1 > $r) {
                $l = $i;
                $r = $i + $z[$i] - 1;
            }
        }
        return $z;
    }
    public static function getCountOfDiffSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $n = count($s);
        $count = 0;
        $t = '';
        for ($i = $n - 1; $i >= 0; $i--) {
            $t = $s[$i] . $t;
            $count += $i + 1 - max(self::z($t));
        }
        return $count;
    }
    public static function getMinPeriodOfSubstrWithZ($sString)
    {
        $s = str_split($sString);
        $res = count($s);
        $z = self::z($sString);
        foreach ($z as $iI => $sV) {
            if ((int) $iI + $z[$iI] == $res && $res % (int) $iI == 0) {
                $res = $iI;
                break;
            }
        }
        return $res;
    }

    //Other functions
    public static function gcd($a, $b) {
        return ($a % $b) ? self::gcd($b,$a % $b) : $b;
    }
    public static function lcm($x, $y) {
        $p = $x;
        $q = $y;
        while ($x != $y)
        {
            if ($x > $y)
                $x = $x - $y;
            else
                $y = $y - $x;
        }
        return ($p*$q)/$x;
    }

}

//$iQueryCount = 1;
$iQueryCount = IO::str();
while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    list($n , $k) = IO::arr();
    $a = IO::arr();
    $b = [];
    $c = [];
    $res = [];
    $tp = 0;
    foreach ($a as $ind => $v) {
        if (isset($b[$v])) {
            $b[$v] += 1;
            $c[$v][] = $ind;
        } else {
            $b[$v] = 1;
            $c[$v] = [$ind];
        }
        if ($b[$v] == $k) {
            $tp += $k;
        }
        if ($b[$v] > $k) {
            $tp++;
        }
        $res[] = 0;
    }
    $x = floor(($n - $tp) / $k);
    $count = 1;
    $cycle = 0;
    foreach ($c as $v => $aV) {
        if ($b[$v] >= $k) {
            for ($i = 1; $i <= $k; $i++) {
               $res[$aV[$i - 1]] = $i;
            }
        } else {
            foreach ($aV as $item) {
                if ($cycle < $x) {
                    $res[$item] = $count;
                    $count++;
                }
                if ($count > $k) {
                    $count = 1;
                    $cycle++;
                }
                if ($cycle >= $x) {
                    break;
                }
            }
        }
    }

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

?>


Lunar New Year is approaching, and Bob is planning to go for a famous restaurant — "Alice's".The restaurant "Alice's" serves $$$n$$$ kinds of food. The cost for the $$$i$$$-th kind is always $$$c_i$$$. Initially, the restaurant has enough ingredients for serving exactly $$$a_i$$$ dishes of the $$$i$$$-th kind. In the New Year's Eve, $$$m$$$ customers will visit Alice's one after another and the $$$j$$$-th customer will order $$$d_j$$$ dishes of the $$$t_j$$$-th kind of food. The $$$(i + 1)$$$-st customer will only come after the $$$i$$$-th customer is completely served.Suppose there are $$$r_i$$$ dishes of the $$$i$$$-th kind remaining (initially $$$r_i = a_i$$$). When a customer orders $$$1$$$ dish of the $$$i$$$-th kind, the following principles will be processed. If $$$r_i > 0$$$, the customer will be served exactly $$$1$$$ dish of the $$$i$$$-th kind. The cost for the dish is $$$c_i$$$. Meanwhile, $$$r_i$$$ will be reduced by $$$1$$$. Otherwise, the customer will be served $$$1$$$ dish of the cheapest available kind of food if there are any. If there are multiple cheapest kinds of food, the one with the smallest index among the cheapest will be served. The cost will be the cost for the dish served and the remain for the corresponding dish will be reduced by $$$1$$$. If there are no more dishes at all, the customer will leave angrily. Therefore, no matter how many dishes are served previously, the cost for the customer is $$$0$$$.If the customer doesn't leave after the $$$d_j$$$ dishes are served, the cost for the customer will be the sum of the cost for these $$$d_j$$$ dishes.Please determine the total cost for each of the $$$m$$$ customers.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 10^5$$$), representing the number of different kinds of food and the number of customers, respectively. The second line contains $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^7$$$), where $$$a_i$$$ denotes the initial remain of the $$$i$$$-th kind of dishes. The third line contains $$$n$$$ positive integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \leq c_i \leq 10^6$$$), where $$$c_i$$$ denotes the cost of one dish of the $$$i$$$-th kind. The following $$$m$$$ lines describe the orders of the $$$m$$$ customers respectively. The $$$j$$$-th line contains two positive integers $$$t_j$$$ and $$$d_j$$$ ($$$1 \leq t_j \leq n$$$, $$$1 \leq d_j \leq 10^7$$$), representing the kind of food and the number of dishes the $$$j$$$-th customer orders, respectively.

Print $$$m$$$ lines. In the $$$j$$$-th line print the cost for the $$$j$$$-th customer.

NoteIn the first sample, $$$5$$$ customers will be served as follows. Customer $$$1$$$ will be served $$$6$$$ dishes of the $$$2$$$-nd kind, $$$1$$$ dish of the $$$4$$$-th kind, and $$$1$$$ dish of the $$$6$$$-th kind. The cost is $$$6 \cdot 3 + 1 \cdot 2 + 1 \cdot 2 = 22$$$. The remain of the $$$8$$$ kinds of food will be $$$\{8, 0, 2, 0, 4, 4, 7, 5\}$$$. Customer $$$2$$$ will be served $$$4$$$ dishes of the $$$1$$$-st kind. The cost is $$$4 \cdot 6 = 24$$$. The remain will be $$$\{4, 0, 2, 0, 4, 4, 7, 5\}$$$. Customer $$$3$$$ will be served $$$4$$$ dishes of the $$$6$$$-th kind, $$$3$$$ dishes of the $$$8$$$-th kind. The cost is $$$4 \cdot 2 + 3 \cdot 2 = 14$$$. The remain will be $$$\{4, 0, 2, 0, 4, 0, 7, 2\}$$$. Customer $$$4$$$ will be served $$$2$$$ dishes of the $$$3$$$-rd kind, $$$2$$$ dishes of the $$$8$$$-th kind. The cost is $$$2 \cdot 3 + 2 \cdot 2 = 10$$$. The remain will be $$$\{4, 0, 0, 0, 4, 0, 7, 0\}$$$. Customer $$$5$$$ will be served $$$7$$$ dishes of the $$$7$$$-th kind, $$$3$$$ dishes of the $$$1$$$-st kind. The cost is $$$7 \cdot 3 + 3 \cdot 6 = 39$$$. The remain will be $$$\{1, 0, 0, 0, 4, 0, 0, 0\}$$$.In the second sample, each customer is served what they order except the last one, who leaves angrily without paying. For example, the second customer is served $$$6$$$ dishes of the second kind, so the cost is $$$66 \cdot 6 = 396$$$.In the third sample, some customers may not be served what they order. For example, the second customer is served $$$6$$$ dishes of the second kind, $$$6$$$ of the third and $$$1$$$ of the fourth, so the cost is $$$66 \cdot 6 + 666 \cdot 6 + 6666 \cdot 1 = 11058$$$.


Alice guesses the strings that Bob made for her.At first, Bob came up with the secret string $$$a$$$ consisting of lowercase English letters. The string $$$a$$$ has a length of $$$2$$$ or more characters. Then, from string $$$a$$$ he builds a new string $$$b$$$ and offers Alice the string $$$b$$$ so that she can guess the string $$$a$$$.Bob builds $$$b$$$ from $$$a$$$ as follows: he writes all the substrings of length $$$2$$$ of the string $$$a$$$ in the order from left to right, and then joins them in the same order into the string $$$b$$$.For example, if Bob came up with the string $$$a$$$="abac", then all the substrings of length $$$2$$$ of the string $$$a$$$ are: "ab", "ba", "ac". Therefore, the string $$$b$$$="abbaac".You are given the string $$$b$$$. Help Alice to guess the string $$$a$$$ that Bob came up with. It is guaranteed that $$$b$$$ was built according to the algorithm given above. It can be proved that the answer to the problem is unique.

The first line contains a single positive integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases in the test. Then $$$t$$$ test cases follow. Each test case consists of one line in which the string $$$b$$$ is written, consisting of lowercase English letters ($$$2 \le |b| \le 100$$$) — the string Bob came up with, where $$$|b|$$$ is the length of the string $$$b$$$. It is guaranteed that $$$b$$$ was built according to the algorithm given above.

Output $$$t$$$ answers to test cases. Each answer is the secret string $$$a$$$, consisting of lowercase English letters, that Bob came up with.

NoteThe first test case is explained in the statement.In the second test case, Bob came up with the string $$$a$$$="ac", the string $$$a$$$ has a length $$$2$$$, so the string $$$b$$$ is equal to the string $$$a$$$.In the third test case, Bob came up with the string $$$a$$$="bcdaf", substrings of length $$$2$$$ of string $$$a$$$ are: "bc", "cd", "da", "af", so the string $$$b$$$="bccddaaf".

<?php
fscanf(STDIN,"%d",$tc);
while ($tc--) {
	# code...

$str=trim(fgets(STDIN));
$str1="";
$length=strlen($str);
for($i=1;$i<=$length-2;$i+=2)
{
	$str1.=$str[$i];

}
echo $str[0]."$str1".$str[$length-1]."\n";

}

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

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

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

        $len = strlen($in_str) ;
        $ans = "" ;

        $ans .= $in_str[0] ;
        for($i = 1; $i < $len - 1; $i += 2)
        {
            $ans .= $in_str[$i] ;
            if($in_str[$i] != $in_str[$i + 1]) $ans .= $in_str[$i + 1] ;
        }
        $ans .= $in_str[$len - 1] ;
        echo $ans . "\n" ;
    }
?>

<?php
  $t = intval(readline());
  while ($t--) {
    $b = readline();
    $l = strlen($b);
    echo $b[0];
    for ($i = 1; $i < $l - 1; $i += 2) {
      echo $b[$i];
    }
    echo $b[$l - 1];
    echo "\n";
  }
?>


You have a sequence $$$a$$$ with $$$n$$$ elements $$$1, 2, 3, \dots, k - 1, k, k - 1, k - 2, \dots, k - (n - k)$$$ ($$$k \le n < 2k$$$).Let's call as inversion in $$$a$$$ a pair of indices $$$i < j$$$ such that $$$a[i] > a[j]$$$.Suppose, you have some permutation $$$p$$$ of size $$$k$$$ and you build a sequence $$$b$$$ of size $$$n$$$ in the following manner: $$$b[i] = p[a[i]]$$$.Your goal is to find such permutation $$$p$$$ that the total number of inversions in $$$b$$$ doesn't exceed the total number of inversions in $$$a$$$, and $$$b$$$ is lexicographically maximum.Small reminder: the sequence of $$$k$$$ integers is called a permutation if it contains all integers from $$$1$$$ to $$$k$$$ exactly once.Another small reminder: a sequence $$$s$$$ is lexicographically smaller than another sequence $$$t$$$, if either $$$s$$$ is a prefix of $$$t$$$, or for the first $$$i$$$ such that $$$s_i \ne t_i$$$, $$$s_i < t_i$$$ holds (in the first position that these sequences are different, $$$s$$$ has smaller number than $$$t$$$).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$k \le n < 2k$$$; $$$1 \le k \le 10^5$$$) — the length of the sequence $$$a$$$ and its maximum. It's guaranteed that the total sum of $$$k$$$ over test cases doesn't exceed $$$10^5$$$.

For each test case, print $$$k$$$ integers — the permutation $$$p$$$ which maximizes $$$b$$$ lexicographically without increasing the total number of inversions. It can be proven that $$$p$$$ exists and is unique.

NoteIn the first test case, the sequence $$$a = [1]$$$, there is only one permutation $$$p = [1]$$$.In the second test case, the sequence $$$a = [1, 2]$$$. There is no inversion in $$$a$$$, so there is only one permutation $$$p = [1, 2]$$$ which doesn't increase the number of inversions.In the third test case, $$$a = [1, 2, 1]$$$ and has $$$1$$$ inversion. If we use $$$p = [2, 1]$$$, then $$$b = [p[a[1]], p[a[2]], p[a[3]]] = [2, 1, 2]$$$ and also has $$$1$$$ inversion.In the fourth test case, $$$a = [1, 2, 3, 2]$$$, and since $$$p = [1, 3, 2]$$$ then $$$b = [1, 3, 2, 3]$$$. Both $$$a$$$ and $$$b$$$ have $$$1$$$ inversion and $$$b$$$ is the lexicographically maximum.


There are three sticks with integer lengths $$$l_1, l_2$$$ and $$$l_3$$$.You are asked to break exactly one of them into two pieces in such a way that:   both pieces have positive (strictly greater than $$$0$$$) integer length;  the total length of the pieces is equal to the original length of the stick;  it's possible to construct a rectangle from the resulting four sticks such that each stick is used as exactly one of its sides. A square is also considered a rectangle.Determine if it's possible to do that.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The only line of each testcase contains three integers $$$l_1, l_2, l_3$$$ ($$$1 \le l_i \le 10^8$$$) — the lengths of the sticks.

For each testcase, print "YES" if it's possible to break one of the sticks into two pieces with positive integer length in such a way that it's possible to construct a rectangle from the resulting four sticks. Otherwise, print "NO". You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES are all recognized as a positive answer).

NoteIn the first testcase, the first stick can be broken into parts of length $$$1$$$ and $$$5$$$. We can construct a rectangle with opposite sides of length $$$1$$$ and $$$5$$$.In the second testcase, breaking the stick of length $$$2$$$ can only result in sticks of lengths $$$1, 1, 2, 5$$$, which can't be made into a rectangle. Breaking the stick of length $$$5$$$ can produce results $$$2, 3$$$ or $$$1, 4$$$ but neither of them can't be put into a rectangle.In the third testcase, the second stick can be broken into parts of length $$$2$$$ and $$$2$$$. The resulting rectangle has opposite sides $$$2$$$ and $$$2$$$ (which is a square).In the fourth testcase, the third stick can be broken into parts of length $$$2$$$ and $$$2$$$. The resulting rectangle has opposite sides $$$2$$$ and $$$5$$$.

<?php

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

function solve()
{
    global $file;

    list($a, $b, $c) = array_map('intval', explode(' ', trim(fgets($file))));

    if(abs($a - $b) === $c)
    {
        echo "YES";
        return;
    }

    if(abs($a - $c) === $b)
    {
        echo "YES";
        return;
    }

    if(abs($c - $b) === $a)
    {
        echo "YES";
        return;
    }

    if($a === $b && $c % 2 == 0)
    {
        echo "YES";
        return;
    }

    if($a === $c && $b % 2 == 0)
    {
        echo "YES";
        return;
    }

    if($b === $c && $a % 2 == 0)
    {
        echo "YES";
        return;
    }

    echo "NO";
}

$t = +fgets($file);

while($t--) {
    solve();
    echo PHP_EOL;
}


You are given a forest — an undirected graph with $$$n$$$ vertices such that each its connected component is a tree.The diameter (aka "longest shortest path") of a connected undirected graph is the maximum number of edges in the shortest path between any pair of its vertices.You task is to add some edges (possibly zero) to the graph so that it becomes a tree and the diameter of the tree is minimal possible.If there are multiple correct answers, print any of them.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 1000$$$, $$$0 \le m \le n - 1$$$) — the number of vertices of the graph and the number of edges, respectively. Each of the next $$$m$$$ lines contains two integers $$$v$$$ and $$$u$$$ ($$$1 \le v, u \le n$$$, $$$v \ne u$$$) — the descriptions of the edges. It is guaranteed that the given graph is a forest.

In the first line print the diameter of the resulting tree. Each of the next $$$(n - 1) - m$$$ lines should contain two integers $$$v$$$ and $$$u$$$ ($$$1 \le v, u \le n$$$, $$$v \ne u$$$) — the descriptions of the added edges. The resulting graph should be a tree and its diameter should be minimal possible. For $$$m = n - 1$$$ no edges are added, thus the output consists of a single integer — diameter of the given tree. If there are multiple correct answers, print any of them.

NoteIn the first example adding edges (1, 4) or (3, 4) will lead to a total diameter of 3. Adding edge (2, 4), however, will make it 2.Edge (1, 2) is the only option you have for the second example. The diameter is 1.You can't add any edges in the third example. The diameter is already 2.