Kuro is living in a country called Uberland, consisting of $$$n$$$ towns, numbered from $$$1$$$ to $$$n$$$, and $$$n - 1$$$ bidirectional roads connecting these towns. It is possible to reach each town from any other. Each road connects two towns $$$a$$$ and $$$b$$$. Kuro loves walking and he is planning to take a walking marathon, in which he will choose a pair of towns $$$(u, v)$$$ ($$$u \neq v$$$) and walk from $$$u$$$ using the shortest path to $$$v$$$ (note that $$$(u, v)$$$ is considered to be different from $$$(v, u)$$$).Oddly, there are 2 special towns in Uberland named Flowrisa (denoted with the index $$$x$$$) and Beetopia (denoted with the index $$$y$$$). Flowrisa is a town where there are many strong-scent flowers, and Beetopia is another town where many bees live. In particular, Kuro will avoid any pair of towns $$$(u, v)$$$ if on the path from $$$u$$$ to $$$v$$$, he reaches Beetopia after he reached Flowrisa, since the bees will be attracted with the flower smell on Kuro’s body and sting him.Kuro wants to know how many pair of city $$$(u, v)$$$ he can take as his route. Since he’s not really bright, he asked you to help him with this problem.

The first line contains three integers $$$n$$$, $$$x$$$ and $$$y$$$ ($$$1 \leq n \leq 3 \cdot 10^5$$$, $$$1 \leq x, y \leq n$$$, $$$x \ne y$$$) - the number of towns, index of the town Flowrisa and index of the town Beetopia, respectively. $$$n - 1$$$ lines follow, each line contains two integers $$$a$$$ and $$$b$$$ ($$$1 \leq a, b \leq n$$$, $$$a \ne b$$$), describes a road connecting two towns $$$a$$$ and $$$b$$$. It is guaranteed that from each town, we can reach every other town in the city using the given roads. That is, the given map of towns and roads is a tree.

A single integer resembles the number of pair of towns $$$(u, v)$$$ that Kuro can use as his walking route.

NoteOn the first example, Kuro can choose these pairs:   $$$(1, 2)$$$: his route would be $$$1 \rightarrow 2$$$,  $$$(2, 3)$$$: his route would be $$$2 \rightarrow 3$$$,  $$$(3, 2)$$$: his route would be $$$3 \rightarrow 2$$$,  $$$(2, 1)$$$: his route would be $$$2 \rightarrow 1$$$,  $$$(3, 1)$$$: his route would be $$$3 \rightarrow 2 \rightarrow 1$$$. Kuro can't choose pair $$$(1, 3)$$$ since his walking route would be $$$1 \rightarrow 2 \rightarrow 3$$$, in which Kuro visits town $$$1$$$ (Flowrisa) and then visits town $$$3$$$ (Beetopia), which is not allowed (note that pair $$$(3, 1)$$$ is still allowed because although Kuro visited Flowrisa and Beetopia, he did not visit them in that order).On the second example, Kuro can choose the following pairs:   $$$(1, 2)$$$: his route would be $$$1 \rightarrow 2$$$,  $$$(2, 1)$$$: his route would be $$$2 \rightarrow 1$$$,  $$$(3, 2)$$$: his route would be $$$3 \rightarrow 1 \rightarrow 2$$$,  $$$(3, 1)$$$: his route would be $$$3 \rightarrow 1$$$.


You are given an array $$$d_1, d_2, \dots, d_n$$$ consisting of $$$n$$$ integer numbers.Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array. Let the sum of elements of the first part be $$$sum_1$$$, the sum of elements of the second part be $$$sum_2$$$ and the sum of elements of the third part be $$$sum_3$$$. Among all possible ways to split the array you have to choose a way such that $$$sum_1 = sum_3$$$ and $$$sum_1$$$ is maximum possible.More formally, if the first part of the array contains $$$a$$$ elements, the second part of the array contains $$$b$$$ elements and the third part contains $$$c$$$ elements, then:$$$$$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$$$$$ $$$$$$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$$$$$ $$$$$$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$$$$$The sum of an empty array is $$$0$$$.Your task is to find a way to split the array such that $$$sum_1 = sum_3$$$ and $$$sum_1$$$ is maximum possible.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in the array $$$d$$$. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$) — the elements of the array $$$d$$$.

Print a single integer — the maximum possible value of $$$sum_1$$$, considering that the condition $$$sum_1 = sum_3$$$ must be met. Obviously, at least one valid way to split the array exists (use $$$a=c=0$$$ and $$$b=n$$$).

NoteIn the first example there is only one possible splitting which maximizes $$$sum_1$$$: $$$[1, 3, 1], [~], [1, 4]$$$.In the second example the only way to have $$$sum_1=4$$$ is: $$$[1, 3], [2, 1], [4]$$$.In the third example there is only one way to split the array: $$$[~], [4, 1, 2], [~]$$$.

<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d", $n);
$a = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($a);
$upper = $sum / 2;

$array1 = array();
$array2 = array();

$sum1 = $sum2 = 0;
for ($i = 0; $i < $n; $i++) {
	$sum1 += $a[$i];
	if ($upper >= $sum1) {
		$array1[$sum1] = 1;
	}
	$sum2 += $a[$n - $i - 1];
	if ($upper >= $sum2) {
		$array2[$sum2] = 1;
	}
}

/*
echo "1: ";
foreach ($array1 as $key => $dummy) {
echo $key . " ";
}
echo PHP_EOL;
echo "2: ";
foreach ($array2 as $key => $dummy) {
echo $key . " ";
}
echo PHP_EOL;
 */

krsort($array1);

foreach ($array1 as $key => $dummy) {
	if (isset($array2[$key])) {
		echo $key . PHP_EOL;
		exit;
	}
}
echo "0";

<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d", $n);
$a = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($a);
$upper = $sum / 2;

$array1 = array();
$array2 = array();

$sum1 = $sum2 = 0;
for ($i = 0; $i < $n; $i++) {
	$sum1 += $a[$i];
	if ($upper >= $sum1) {
		$array1[$sum1] = 1;
	}
	$sum2 += $a[$n - $i - 1];
	if ($upper >= $sum2) {
		$array2[$sum2] = 1;
	}
}

/*
echo "1: ";
foreach ($array1 as $key => $dummy) {
echo $key . " ";
}
echo PHP_EOL;
echo "2: ";
foreach ($array2 as $key => $dummy) {
echo $key . " ";
}
echo PHP_EOL;
 */

krsort($array1);
krsort($array2);

foreach ($array1 as $key => $dummy) {
	if (isset($array2[$key])) {
		echo $key . PHP_EOL;
		exit;
	}
}
echo "0";

<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d", $n);
$a = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($a);
$upper = $sum / 2;

$array1 = array();
$array2 = array();

$sum1 = $sum2 = 0;
for ($i = 0; $i < $n; $i++) {
	$sum1 += $a[$i];
	$sum1 = intval($sum1);
	if ($upper >= $sum1) {
		$array1[$sum1] = 1;
	}
	$sum2 += $a[$n - $i - 1];
	$sum2 = intval($sum2);
	if ($upper >= $sum2) {
		$array2[$sum2] = 1;
	}
}

/*
echo "1: ";
foreach ($array1 as $key => $dummy) {
echo $key . " ";
}
echo PHP_EOL;
echo "2: ";
foreach ($array2 as $key => $dummy) {
echo $key . " ";
}
echo PHP_EOL;
 */

krsort($array1);
krsort($array2);

foreach ($array1 as $key => $dummy) {
	if (isset($array2[$key])) {
		echo $key . PHP_EOL;
		exit;
	}
}
echo "0";

<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE);

fscanf(STDIN, "%d", $n);
$a = explode(" ", trim(fgets(STDIN)));
$sum = array_sum($a);
$upper = $sum / 2;

$array1 = array();
$array2 = array();

$sum1 = $sum2 = 0;
for ($i = 0; $i < $n; $i++) {
	$sum1 += $a[$i];
	$sum1 = floor($sum1);
	if ($upper >= $sum1) {
		$array1[$sum1] = 1;
	}
	$sum2 += $a[$n - $i - 1];
	$sum2 = floor($sum2);
	if ($upper >= $sum2) {
		$array2[$sum2] = 1;
	}
}

/*
echo "1: ";
foreach ($array1 as $key => $dummy) {
echo $key . " ";
}
echo PHP_EOL;
echo "2: ";
foreach ($array2 as $key => $dummy) {
echo $key . " ";
}
echo PHP_EOL;
 */

krsort($array1);
krsort($array2);

foreach ($array1 as $key => $dummy) {
	if (isset($array2[$key])) {
		echo $key . PHP_EOL;
		exit;
	}
}
echo "0";


The Human-Cow Confederation (HC2), led by Heidi, has built a base where people and cows can hide, guarded from zombie attacks. The entrance to the base is protected by an automated gate which performs a kind of a Turing test: it shows the entering creature a photograph and asks them whether the top and bottom halves of this photograph have been swapped or not. A person (or even a cow) will have no problem answering such questions; on the other hand, a zombie would just randomly smash one of the two buttons.The creature is asked a series of such questions. If at least 75% of them are answered correctly, the gate is unlocked; otherwise, a side door opens, beneath which a huge fan is spinning...Heidi is now building a robot army to fight the zombies, and she wants the robots to also be able to enter the base. You are tasked with programming them to distinguish the images. The first two images from the test set. The first picture has been rearranged, but not the second.

The first line of the input contains the number q of questions (1 ≤ q ≤ 220). After that, q questions follow, each of which in the format described below. The first line of every question contains two space-separated integers h and w (1 ≤ h, w ≤ 600) – the height (number of rows) and width (number of columns) of the photograph. (Most photographs are roughly 200 × 300.) After this, h lines follow, each describing a single row of the picture. The picture is monochrome (in shades of grey). Its i-th row is described by w space-separated integers aij (j = 1, ..., w), where aij is the brightness of the corresponding pixel (0 ≤ aij < 256, where 0 is black and 255 is white). Each picture will be either a real-life photograph, or a real-life photograph which has been broken up into two pieces and rearranged. More precisely, in the latter case, the topmost  rows have been moved to the bottom of the picture. It is guaranteed that h is even. There is only a single input file to be processed, called all.in, and it is downloadable from the online judge. You are also a given another input file, called sample.in, which contains the first 20 pictures from all.in; you are provided the correct answers for sample.in in sample.out. You are also given a directory easy_bmp, which contains the first 50 input photographs in the form of .bmp image files, as well as a directory easy_sample_original_bmp, which contains the first 20 images before rearrangement. Check the notes for the download links.

Your program should print q lines. The i-th line should contain your answer for the i-th question: YES if the photograph has been rearranged and NO otherwise. Your answers will be accepted if they all conform to this format and if at least 75% of them are correct. Because the input is rather huge, feel free to process it locally and submit just your precomputed answers (i.e., a program which just prints your output for the input file all.in).

NoteThe link to download all necessary files is http://assets.codeforces.com/files/690/easy_contestant_package.zip

YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
NO
YES
NO
NO
YES
NO
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
NO
NO
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
NO
NO
YES
NO
NO
NO
NO
YES
NO
YES
NO
NO
YES
NO
YES
YES
YES
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES

YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
YES
YES
NO
YES
NO
NO
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
NO
NO
NO
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
NO
NO

YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
NO
YES
NO
NO
YES
NO
NO
YES
YES
NO
YES
NO
NO
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
NO
NO
YES
NO
YES
YES
NO
YES
NO
YES
NO
NO
NO
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
YES
NO
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
NO
NO
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
YES
YES
YES
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES

YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
NO
NO
YES
NO
YES
YES
NO
NO
NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES

YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
NO
NO
NO
YES
NO
YES
YES
YES
NO
NO
YES
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
NO
NO
YES
NO
NO
YES
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO


You are given an integer $$$n$$$ ($$$n > 1$$$).Your task is to find a sequence of integers $$$a_1, a_2, \ldots, a_k$$$ such that:  each $$$a_i$$$ is strictly greater than $$$1$$$;  $$$a_1 \cdot a_2 \cdot \ldots \cdot a_k = n$$$ (i. e. the product of this sequence is $$$n$$$);  $$$a_{i + 1}$$$ is divisible by $$$a_i$$$ for each $$$i$$$ from $$$1$$$ to $$$k-1$$$;  $$$k$$$ is the maximum possible (i. e. the length of this sequence is the maximum possible). If there are several such sequences, any of them is acceptable. It can be proven that at least one valid sequence always exists for any integer $$$n > 1$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Then $$$t$$$ test cases follow. The only line of the test case contains one integer $$$n$$$ ($$$2 \le n \le 10^{10}$$$). It is guaranteed that the sum of $$$n$$$ does not exceed $$$10^{10}$$$ ($$$\sum n \le 10^{10}$$$).

For each test case, print the answer: in the first line, print one positive integer $$$k$$$ — the maximum possible length of $$$a$$$. In the second line, print $$$k$$$ integers $$$a_1, a_2, \ldots, a_k$$$ — the sequence of length $$$k$$$ satisfying the conditions from the problem statement. If there are several answers, you can print any. It can be proven that at least one valid sequence always exists for any integer $$$n > 1$$$.

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%f", $n);
    $queue = new SplQueue();
    for ($i = 2, $l = floor(sqrt($n)); $i <= $l; $i++) {
        if (0 == fmod($n, $i)) {
            $new_value = $n/$i;
            (0 == fmod($new_value, $i)) and $queue->enqueue([$n/$i, [$i], $i]);
        }
    }
    $priority = new SplPriorityQueue();
    $cnt = 0;
    while ($queue->count()) {
        list($value, $path, $offset) = $queue->dequeue();
        $prev_value = end($path);
        for ($i = $offset; $i <= $value; $i += $offset) {
            $cnt++;
            if (0 != fmod($value, $i)) continue;
            $new_value = $value/$i;
            if (1 == $new_value) {
                $path[] = $i;
                $priority->insert($path, count($path));
            } elseif (0 != fmod($new_value, $i)) {
                if (count($path) > 1) {
                    $queue->enqueue([$prev_value*$value, array_slice($path, 0, -1), $prev_value+$prev_value]);
                }
                $path[] = $value;
                $priority->insert($path, count($path));
            } else {
                $path[] = $i;
                $queue->enqueue([$new_value, $path, $i]);
            }
            break;
        }
    }
    $value = $priority->count() ? $priority->extract() : [$n];
    printf("%s\n%s\n", count($value), implode(' ', $value));
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%f", $n);
    $queue = new SplQueue();
    for ($i = 2, $l = intval(sqrt($n)); $i <= $l; $i++) {
        if (0 === $n%$i) {
            $new_value = $n/$i;
            (0 === $new_value%$i) and $queue->enqueue([$n/$i, [$i], $i]);
        }
    }
    $priority = new SplPriorityQueue();
    while ($queue->count()) {
        list($value, $path, $offset) = $queue->dequeue();
        $prev_value = end($path);
        for ($i = $offset; $i <= $value; $i += $offset) {
            if (0 !== $value%$i) continue;
            $new_value = $value/$i;
            if (1 == $new_value) {
                $path[] = $i;
                $priority->insert($path, count($path));
            } elseif (0 !== $new_value%$prev_value) {
                count($path) > 1
                and $queue->enqueue([$prev_value*$value, array_slice($path, 0, -1), $prev_value+$prev_value]);
            } else {
                $path[] = $i;
                $queue->enqueue([$new_value, $path, $new_value]);
            }
            break;
        }
    }
    $value = $priority->count() ? $priority->extract() : [$n];
    printf("%s\n%s\n", count($value), implode(' ', $value));
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    $queue = new SplQueue();
    for ($i = 2, $l = intval(sqrt($n)); $i <= $l; $i++) {
        if (0 === $n%$i) {
            $new_value = $n/$i;
            (0 === $new_value%$i) and $queue->enqueue([$n/$i, [$i], $i]);
        }
    }
    $priority = new SplPriorityQueue();
    while ($queue->count()) {
        list($value, $path, $offset) = $queue->dequeue();
        $prev_value = end($path);
        for ($i = $offset; $i <= $value; $i += $offset) {
            if (0 !== $value%$i) continue;
            $new_value = $value/$i;
            if (1 == $new_value) {
                $path[] = $i;
                $priority->insert($path, count($path));
            } elseif (0 !== $new_value%$prev_value) {
                count($path) > 1
                and $queue->enqueue([$prev_value*$value, array_slice($path, 0, -1), $prev_value+$prev_value]);
            } else {
                $path[] = $i;
                $queue->enqueue([$new_value, $path, $new_value]);
            }
            break;
        }
    }
    printf("%s\n", $priority->count() ? implode(' ', $priority->extract()) : $n);
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%f", $n);
    $queue = new SplQueue();
    for ($i = 2, $l = intval(sqrt($n)); $i <= $l; $i++) {
        if (0 == fmod($n, $i)) {
            $new_value = $n/$i;
            (0 === $new_value%$i) and $queue->enqueue([$n/$i, [$i], $i]);
        }
    }
    $priority = new SplPriorityQueue();
    $cnt = 0;
    while ($queue->count()) {
        list($value, $path, $offset) = $queue->dequeue();
        $prev_value = end($path);
        for ($i = $offset; $i <= $value; $i += $offset) {
            $cnt++;
            if (0 != fmod($value, $i)) continue;
            $new_value = $value/$i;
            if (1 == $new_value) {
                $path[] = $i;
                $priority->insert($path, count($path));
            } elseif (0 != fmod($new_value, $i)) {
                if (count($path) > 1) {
                    $queue->enqueue([$prev_value*$value, array_slice($path, 0, -1), $prev_value+$prev_value]);
                    $path[] = $value;
                    $priority->insert($path, count($path));
                }
            } else {
                $path[] = $i;
                $queue->enqueue([$new_value, $path, $i]);
            }
            break;
        }
    }
    $value = $priority->count() ? $priority->extract() : [$n];
    printf("%s\n%s\n", count($value), implode(' ', $value));
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%d", $n);
    $queue = new SplQueue();
    for ($i = 2, $l = intval(sqrt($n)); $i <= $l; $i++) {
        if (0 === $n%$i) {
            $new_value = $n/$i;
            (0 === $new_value%$i) and $queue->enqueue([$n/$i, [$i], $i]);
        }
    }
    $priority = new SplPriorityQueue();
    while ($queue->count()) {
        list($value, $path, $offset) = $queue->dequeue();
        $prev_value = end($path);
        for ($i = $offset; $i <= $value; $i += $offset) {
            if (0 !== $value%$i) continue;
            $new_value = $value/$i;
            if (1 == $new_value) {
                $path[] = $i;
                $priority->insert($path, count($path));
            } elseif (0 !== $new_value%$prev_value) {
                count($path) > 1
                and $queue->enqueue([$prev_value*$value, array_slice($path, 0, -1), $prev_value+$prev_value]);
            } else {
                $path[] = $i;
                $queue->enqueue([$new_value, $path, $new_value]);
            }
            break;
        }
    }
    $value = $priority->count() ? $priority->extract() : [$n];
    printf("%s\n%s\n", count($value), implode(' ', $value));
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%f", $n);
    $queue = new SplQueue();
    for ($i = 2, $l = intval(sqrt($n)); $i <= $l; $i++) {
        if (0 == fmod($n, $i)) {
            $new_value = $n/$i;
            (0 === $new_value%$i) and $queue->enqueue([$n/$i, [$i], $i]);
        }
    }
    $priority = new SplPriorityQueue();
    $cnt = 0;
    while ($queue->count()) {
        list($value, $path, $offset) = $queue->dequeue();
        $prev_value = end($path);
        for ($i = $offset; $i <= $value; $i += $offset) {
            $cnt++;
            if (0 != fmod($value, $i)) continue;
            $new_value = $value/$i;
            if (1 == $new_value) {
                $path[] = $i;
                $priority->insert($path, count($path));
            } elseif (0 != fmod($new_value, $i)) {
                if (count($path) > 1) {
                    $queue->enqueue([$prev_value*$value, array_slice($path, 0, -1), $prev_value+$prev_value]);
                }
                $path[] = $value;
                $priority->insert($path, count($path));
            } else {
                $path[] = $i;
                $queue->enqueue([$new_value, $path, $i]);
            }
            break;
        }
    }
    $value = $priority->count() ? $priority->extract() : [$n];
    printf("%s\n%s\n", count($value), implode(' ', $value));
}

<?php
fscanf(STDIN, "%d", $t);
while ($t--) {
    fscanf(STDIN, "%f", $n);
    $queue = new SplQueue();
    for ($i = 2, $l = intval(sqrt($n)); $i <= $l; $i++) {
        if (0 == fmod($n, $i)) {
            $new_value = $n/$i;
            (0 === $new_value%$i) and $queue->enqueue([$n/$i, [$i], $i]);
        }
    }
    $priority = new SplPriorityQueue();
    $cnt = 0;
    while ($queue->count()) {
        list($value, $path, $offset) = $queue->dequeue();
        $prev_value = end($path);
        for ($i = $offset; $i <= $value; $i += $offset) {
            $cnt++;
            if (0 != fmod($value, $i)) continue;
            $new_value = $value/$i;
            if (1 == $new_value) {
                $path[] = $i;
                $priority->insert($path, count($path));
            } elseif (0 != fmod($new_value, $i)) {
                count($path) > 1
                and $queue->enqueue([$prev_value*$value, array_slice($path, 0, -1), $prev_value+$prev_value]);
            } else {
                $path[] = $i;
                $queue->enqueue([$new_value, $path, $i]);
            }
            break;
        }
    }
    $value = $priority->count() ? $priority->extract() : [$n];
    printf("%s\n%s\n", count($value), implode(' ', $value));
}


You are given an array $$$a$$$ of $$$n$$$ integers. Count the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_j - a_i = j - i$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$). Then $$$t$$$ test cases follow. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case output the number of pairs of indices $$$(i, j)$$$ such that $$$i < j$$$ and $$$a_j - a_i = j - i$$$.

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

$results = [];
for ($i = 0; $i < $t; $i++) {
    fscanf(STDIN, "%d\n", $n);
    $arr = fgets(STDIN);
    $arr = explode(' ', $arr);
    $res = [];
    foreach ($arr as $index => $item) {
        $diff = $item - $index;
        if (isset($res[$diff])) {
            $res[$diff]++;
        } else {
            $res[$diff] = 1;
        }
    }

    $result = 0;
    foreach ($res as $resItem) {
        if ($resItem > 1) {
            //$result = bcadd($result, bcdiv(fac($resItem), (bcmul(2, fac($resItem - 2)))));
            $result += ($resItem * ($resItem - 1)) / 2;
        }
    }

    $results[] = $result;
}

foreach ($results as $result) {
    echo $result . PHP_EOL;
}

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

$results = [];
for ($i = 0; $i < $t; $i++) {
    fscanf(STDIN, "%d\n", $n);
    $arr = fgets(STDIN);
    $arr = explode(' ', $arr);
    $res = [];
    foreach ($arr as $index => $item) {
        $diff = $item - $index;
        if (isset($res[$diff])) {
            $res[$diff]++;
        } else {
            $res[$diff] = 1;
        }
    }

    $result = 0;
    foreach ($res as $resItem) {
        if ($resItem > 1) {
            $result = ($resItem * ($resItem - 1)) / 2;
        }
    }

    $results[] = $result;
}

foreach ($results as $result) {
    echo $result . PHP_EOL;
}

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

$results = [];
for ($i = 0; $i < $t; $i++) {
    fscanf(STDIN, "%d\n", $n);
    $arr = fgets(STDIN);
    $arr = array_map('intval', explode(' ', $arr));
    $res = [];
    foreach ($arr as $index => $item) {
        $diff = $item - $index;
        if (isset($res[$diff])) {
            $res[$diff]++;
        } else {
            $res[$diff] = 1;
        }
    }

    $greaterOne = array_filter($res, function ($resItem) {
        return $resItem > 1;
    });

    $result = 0;
    foreach ($greaterOne as $greaterOneItem) {
        $result += fac($greaterOneItem) / (2 * fac($greaterOneItem - 2));
    }

    $results[] = is_nan($result) ? 0 : $result;
}

foreach ($results as $result) {
    echo $result . PHP_EOL;
}

function fac($n)
{
    $factorial = 1;
    for ($i = 1; $i <= $n; $i++){
        $factorial *= $i;
    }
    return $factorial;
}

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

$results = [];
for ($i = 0; $i < $t; $i++) {
    fscanf(STDIN, "%d\n", $n);
    $arr = fgets(STDIN);
    $arr = array_map('intval', explode(' ', $arr));
    $res = [];
    foreach ($arr as $index => $item) {
        $diff = $item - $index;
        if (isset($res[$diff])) {
            $res[$diff]++;
        } else {
            $res[$diff] = 1;
        }
    }

    $greaterOne = array_filter($res, function ($resItem) {
        return $resItem > 1;
    });

    $result = 0;
    foreach ($greaterOne as $greaterOneItem) {
        $result += fac($greaterOneItem) / (2 * fac($greaterOneItem - 2));
    }

    $results[] = $result;
}

foreach ($results as $result) {
    echo $result . PHP_EOL;
}

function fac($n)
{
    $factorial = 1;
    for ($i = 1; $i <= $n; $i++){
        $factorial *= $i;
    }
    return $factorial;
}

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

$results = [];
for ($i = 0; $i < $t; $i++) {
    fscanf(STDIN, "%d\n", $n);
    $arr = fgets(STDIN);
    $arr = array_map('intval', explode(' ', $arr));
    $res = [];
    foreach ($arr as $index => $item) {
        $diff = $item - $index;
        if (isset($res[$diff])) {
            $res[$diff]++;
        } else {
            $res[$diff] = 1;
        }
    }

    $greaterOne = array_sum(array_filter($res, function ($resItem) {
        return $resItem > 1;
    }));

    $results[] = fac($greaterOne) / (2 * fac($greaterOne - 2));
}

foreach ($results as $result) {
    echo $result . PHP_EOL;
}

function fac($n)
{
    $factorial = 1;
    for ($i = 1; $i <= $n; $i++){
        $factorial *= $i;
    }
    return $factorial;
}


Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all.Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived.According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left.

The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 1018,  b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium.

Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation.

NoteIn the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day. In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal.In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal.


Timur likes his name. As a spelling of his name, he allows any permutation of the letters of the name. For example, the following strings are valid spellings of his name: Timur, miurT, Trumi, mriTu. Note that the correct spelling must have uppercased T and lowercased other letters.Today he wrote string $$$s$$$ of length $$$n$$$ consisting only of uppercase or lowercase Latin letters. He asks you to check if $$$s$$$ is the correct spelling of his name.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ $$$(1 \leq n \leq 10)$$$ — the length of string $$$s$$$. The second line of each test case contains a string $$$s$$$ consisting of only uppercase or lowercase Latin characters.

For each test case, output "YES" (without quotes) if $$$s$$$ satisfies the condition, and "NO" (without quotes) otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

10

5

Timur

5

miurT

5

Trumi

5

mriTu

5

timur

4

Timr

6

Timuur

10

codeforces

10

TimurTimur

5

TIMUR

<?php

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

$cases =  trim(fgets( $f ));

for($i = 0; $i < $cases; $i++)
{
    $length = trim(fgets( $f ));
    $string = trim(fgets( $f ));

    $name = [
        "T" => false,
        "i" => false,
        "m" => false,
        "u" => false,
        "r" => false,
    ];

    if($length != 5)
    {
        echo "NO\n";
        continue;
    }

    foreach(str_split($string) as $c)
    {
        if(array_key_exists($c, $name))
        {
            if($name[$c] == false)
            {
                $name[$c] = true;
            }
            else
            {
                echo "NO\n";
                continue 2;
            }
        }
        else{
            echo "NO\n";
            continue 2;
        }
    }

    echo ((bool)array_product($name) ) ? "YES\n" : "NO\n";
}

?>

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
    $len = 5;
    $aInner = ['T' => 0, 'i' => 0, 'm' => 0, 'u' => 0, 'r' => 0];

   $n = IO::get();
   $s = IO::get();
   if($n != 5) {
        IO::pr('No');
   } else {
        $b = true;
     for ($i=0; $i<$n; $i++) {
        if(isset($aInner[$s[$i]])) {
          $aInner[$s[$i]] = 1;
        } else {
           $b = false;
           break;
        }
     }
     foreach ($aInner as $k=>$v) {
        if($v === 0) {
           $b = false;
        }
     }
     IO::pr($b ? 'Yes' : 'No');
   }

}

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

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

<?php

$testsNumber = (int)readline();

for ($i = 0; $i < $testsNumber; $i ++){
    $nameLen = (int)readline();
    $nameStr = readline();

    if ($nameLen != 5){
        print "NO\n";
        continue;
    }

    $nameStr = str_split($nameStr);
    sort($nameStr);
    $nameStr = implode($nameStr);

    if ($nameStr != 'Timru')
        print "NO\n";
    else
        print "YES\n";
}

<?php

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

$cases =  trim(fgets( $f ));

for($i = 0; $i < $cases; $i++)
{
    $length = trim(fgets( $f ));
    $string = trim(fgets( $f ));

    $name = [
        "T" => false,
        "i" => false,
        "m" => false,
        "u" => false,
        "r" => false,
    ];

    if($length != 5)
    {
        echo "NO\n";
    }

    foreach(str_split($string) as $c)
    {
        if(array_key_exists($c, $name))
        {
            if($name[$c] == false)
            {
                $name[$c] = true;
            }
            else
            {
                echo "NO\n";
                continue 2;
            }
        }
        else{
            echo "NO\n";
            continue 2;
        }
    }

    echo ((bool)array_product($name) ) ? "YES\n" : "NO\n";
}

?>


You are given a string $$$s$$$ consisting of lowercase letters of the English alphabet. You must perform the following algorithm on $$$s$$$:  Let $$$x$$$ be the length of the longest prefix of $$$s$$$ which occurs somewhere else in $$$s$$$ as a contiguous substring (the other occurrence may also intersect the prefix). If $$$x = 0$$$, break. Otherwise, remove the first $$$x$$$ characters of $$$s$$$, and repeat. A prefix is a string consisting of several first letters of a given string, without any reorders. An empty prefix is also a valid prefix. For example, the string "abcd" has 5 prefixes: empty string, "a", "ab", "abc" and "abcd".For instance, if we perform the algorithm on $$$s =$$$ "abcabdc",   Initially, "ab" is the longest prefix that also appears somewhere else as a substring in $$$s$$$, so $$$s =$$$ "cabdc" after $$$1$$$ operation.  Then, "c" is the longest prefix that also appears somewhere else as a substring in $$$s$$$, so $$$s =$$$ "abdc" after $$$2$$$ operations.  Now $$$x=0$$$ (because there are no non-empty prefixes of "abdc" that also appear somewhere else as a substring in $$$s$$$), so the algorithm terminates. Find the final state of the string after performing the algorithm.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. This is followed by $$$t$$$ lines, each containing a description of one test case. Each line contains a string $$$s$$$. The given strings consist only of lowercase letters of the English alphabet and have lengths between $$$1$$$ and $$$2 \cdot 10^5$$$ inclusive. It is guaranteed that the sum of the lengths of $$$s$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print a single line containing the string $$$s$$$ after executing the algorithm. It can be shown that such string is non-empty.

6
abcabdc
a
bbbbbbbbbb
codeforces
cffcfccffccfcffcfccfcffccffcfccf
zyzyzwxxyyxxyyzzyzzxxwzxwywxwzxxyzzw

NoteThe first test case is explained in the statement.In the second test case, no operations can be performed on $$$s$$$.In the third test case,   Initially, $$$s =$$$ "bbbbbbbbbb".  After $$$1$$$ operation, $$$s =$$$ "b". In the fourth test case,   Initially, $$$s =$$$ "codeforces".  After $$$1$$$ operation, $$$s =$$$ "odeforces".  After $$$2$$$ operations, $$$s =$$$ "deforces".

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

  for($q=0; $q <$t; $q++) {
      $a = trim(fgets(STDIN));

   $break = false;
    $sP = 0;
    for($i=0; $i< strlen($a); $i++) {
        for($j=$i+1; $j< strlen($a); $j++) {
            if($a[$i] == $a[$j]) {
                $sP = $i+1;
                break;
            }
            if($j ==strlen($a) - 1  &&  $a[$i] != $a[$j]) {
                $break = true;
            }
        }
        if($break) {
            break;
        }
      }

      echo substr($a, $sP) . "\n";

  }


You are given three arrays $$$a$$$, $$$b$$$ and $$$c$$$. Initially, array $$$a$$$ consists of $$$n$$$ elements, arrays $$$b$$$ and $$$c$$$ are empty.You are performing the following algorithm that consists of two steps:   Step $$$1$$$: while $$$a$$$ is not empty, you take the last element from $$$a$$$ and move it in the middle of array $$$b$$$. If $$$b$$$ currently has odd length, you can choose: place the element from $$$a$$$ to the left or to the right of the middle element of $$$b$$$. As a result, $$$a$$$ becomes empty and $$$b$$$ consists of $$$n$$$ elements.  Step $$$2$$$: while $$$b$$$ is not empty, you take the middle element from $$$b$$$ and move it to the end of array $$$c$$$. If $$$b$$$ currently has even length, you can choose which of two middle elements to take. As a result, $$$b$$$ becomes empty and $$$c$$$ now consists of $$$n$$$ elements.  Refer to the Note section for examples.Can you make array $$$c$$$ sorted in non-decreasing order?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. Next $$$t$$$ cases follow. The first line of each test case contains the single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^6$$$) — the array $$$a$$$ itself. It's guaranteed that the sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test, print YES (case-insensitive), if you can make array $$$c$$$ sorted in non-decreasing order. Otherwise, print NO (case-insensitive).

<?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 = true;
      $n = getT();
      $a = getA();
      if ($n % 2 == 0) {
          for ($i=0; $i< $n; $i +=2) {
            if ($a[$i] > $a[$i + 1]) {
                $tmp = $a[$i];
                $a[$i] = $a[$i + 1];
                $a[$i + 1] = $tmp;
            }

          }

      } else {
          for ($i=1; $i< $n; $i +=2) {
            if ($a[$i] > $a[$i + 1]) {
                $tmp = $a[$i];
                $a[$i] = $a[$i + 1];
                $a[$i + 1] = $tmp;
            }

          }
      }

    for ($i=0; $i< $n-1; $i++) {
        if ($a[$i] > $a[$i + 1]) {
            $ans = false;
            break;
        }
    }

        echo $ans ? $yes : $no, $inter;

  }
// 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 ComandR($aCordinate) {
      return [$aCordinate[0] + 1, $aCordinate[1]];
  }
  function ComandL($aCordinate) {
      return [$aCordinate[0] - 1, $aCordinate[1]];
  }
  function ComandU($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] + 1];
  }
  function ComandD($aCordinate) {
      return [$aCordinate[0], $aCordinate[1] - 1];
  }

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

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

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

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

    function 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];
    }


A palindrome is a string that reads the same backward as forward. For example, the strings "z", "aaa", "aba", and "abccba" are palindromes, but "codeforces" and "ab" are not. You hate palindromes because they give you déjà vu.There is a string $$$s$$$. You must insert exactly one character 'a' somewhere in $$$s$$$. If it is possible to create a string that is not a palindrome, you should find one example. Otherwise, you should report that it is impossible.For example, suppose $$$s=$$$ "cbabc". By inserting an 'a', you can create "acbabc", "cababc", "cbaabc", "cbabac", or "cbabca". However "cbaabc" is a palindrome, so you must output one of the other options.

The first line contains a single integer $$$t$$$ ($$$1\le t\le 10^4$$$) — the number of test cases. The only line of each test case contains a string $$$s$$$ consisting of lowercase English letters. The total length of all strings does not exceed $$$3\cdot 10^5$$$.

For each test case, if there is no solution, output "NO". Otherwise, output "YES" followed by your constructed string of length $$$|s|+1$$$ on the next line. If there are multiple solutions, you may print any. You can print each letter of "YES" and "NO" in any case (upper or lower).

YES
cbabac
YES
aab
YES
zaza
YES
baa
NO
YES
nutforajarofatuna

NoteThe first test case is described in the statement.In the second test case, we can make either "aab" or "aba". But "aba" is a palindrome, so "aab" is the only correct answer.In the third test case, "zaza" and "zzaa" are correct answers, but not "azza".In the fourth test case, "baa" is the only correct answer.In the fifth test case, we can only make "aa", which is a palindrome. So the answer is "NO".In the sixth test case, "anutforajaroftuna" is a palindrome, but inserting 'a' elsewhere is valid.

<?php
	fscanf(STDIN, "%d", $t);
	while($t--) {
		fscanf(STDIN, "%s", $s);
		strlen($s)%2 == 0 ? $n=strlen($s)/2 : $n = floor(strlen($s)/2 + 1);
		$no = true;
		for ($i=strlen($s), $k=strlen($s)-1; $i>=$n; $i--, $k--) {
			if ($s[strlen($s)-$i] != 'a') {
				$no = false;
				echo "YES\n";
				for ($j=0; $j<$i; $j++) {
					echo $s[$j];
				}
				echo 'a';
				for ($j=$i; $j<strlen($s); $j++){
					echo $s[$j];
				}
				echo "\n";
				break;

			}
			else if ($s[$k] != 'a'){
				$no = false;
				echo "YES\n";
				$k2 = strlen($s)-$k-1;
				while($k2 > 0){
					$k2--;
					echo $s[$k2];
				}
				echo 'a';
				for ($i=strlen($s)-$k-1; $i<=strlen($s)-1; $i++){
					echo $s[$i];
				}
				echo "\n";
				break;
			}

		}
		if ($no) echo "NO\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;
    }
}

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $n = count($a);
    $s = $e = '';
    $bool = true;
    for ($i = 0; $i < $n; $i++) {
        $f = $a[$i];
        $l = $a[count($a) - $i - 1];
        if ('a' !== $l && $bool) {
            $s .= 'a';
            $bool = false;
        }
        $s .= $f;
    }

    if(!$bool) {
        IO::line('YES');
        IO::line($s);
    } else {
        IO::line('NO');
    }

}

?>

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

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

for ($i = 0; $i < $t; $i++) {
  $str = trim(fgets($file));
  $r = strrev($str);
  $j = 0; $k = 0;
  while ($r[$j] == 'a') { $j++; }
  while ($str[$k] == 'a') { $k++; }

  if ($j == strlen($str)) { echo 'NO'.PHP_EOL; }
  else {
    if ($j == 0 && $k == 0) { echo 'YES'.PHP_EOL; echo 'a'.$str.PHP_EOL; }
    else {
      if ($j >= $k) { echo 'YES'.PHP_EOL;  echo $str.'a'.PHP_EOL; }
      if ($j < $k) { echo 'YES'.PHP_EOL;  echo 'a'.$str.PHP_EOL; }
    }
  }
}
?>

<?php
	fscanf(STDIN, "%d", $t);
	while($t--) {
		fscanf(STDIN, "%s", $s);
		strlen($s)%2 == 0 ? $n=strlen($s)/2 : $n = floor(strlen($s)/2 + 1);
		$no = true;
		for ($i=strlen($s), $k=strlen($s)-1; $i>=$n; $i--, $k--) {
			if ($s[strlen($s)-$i] != 'a') {
				$no = false;
				echo "YES\n";
				for ($j=0; $j<$i; $j++) {
					echo $s[$j];
				}
				echo 'a';
				for ($j=$i; $j<strlen($s); $j++){
					echo $s[$j];
				}
				echo "\n";
				break;

			}
			else if ($s[$k] != 'a'){
				$no = false;
				echo "YES\n";
				$k2 = strlen($s)-$k-1;
				while($k2 > 0){
					$k2--;
					echo $s[$k2];
				}
				echo 'a';
				for ($i=strlen($s)-$k-1; $i<strlen($s)-1; $i++){
					echo $s[$i];
				}
				echo "\n";
				break;
			}

		}
		if ($no) echo "NO\n";

	}
?>

<?php
	fscanf(STDIN, "%d", $t);
	while($t--) {
		fscanf(STDIN, "%s", $s);
		strlen($s)%2 == 0 ? $n=strlen($s)/2 : $n = floor(strlen($s)/2 + 1);
		$no = true;
		for ($i=strlen($s); $i>=$n; $i--) {
			if ($s[strlen($s)-$i] != 'a') {
				$no = false;
				echo "YES\n";
				for ($j=0; $j<$i; $j++) {
					echo $s[$j];
				}
				echo 'a';
				for ($j=$i; $j<strlen($s); $j++){
					echo $s[$j];
				}
				echo "\n";
				break;
			}
		}
		if ($no) echo "NO\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;
    }
}

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $n = ceil(count($a) / 2);
    $s = $e = '';
    $bool = true;
    for ($i = 0; $i < $n; $i++) {
       $f = $a[$i];
       $l = $a[count($a) - $i - 1];
       if ('a' !== $l && $bool) {
           $s .= 'a';
           $bool = false;
       }
       $s .= $f;
       $sp = isset($a[count($a) - $i - 2]) ? $a[count($a) - $i - 2] : 'a';
       if ($sp !== 'a' && $bool) {
           $s .= 'a';
           $bool = false;
       }
       if (count($a) - $i - 1 !== $i) {
           $e = $l . $e;
       }
    }

    if(!$bool) {
        IO::line('YES');
        IO::line($s . $e);
    } else {
        IO::line('NO');
    }

}

?>

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

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

while($iQueryCount > 0) {
    $iQueryCount--;
    solve();
}
function solve() {
    $a = str_split(IO::str());
    $n = ceil(count($a) / 2);
    $s = $e = '';
    $bool = true;
    for ($i = 0; $i < $n; $i++) {
       $f = $a[$i];
       $l = $a[count($a) - $i - 1];
       if ('a' !== $l && $bool) {
           $s .= 'a';
           $bool = false;
       }
       $s .= $f;
       if (count($a) - $i - 1 !== $i) {
           $e = $l . $e;
       }
    }

    if(!$bool) {
        IO::line('YES');
        IO::line($s . $e);
    } else {
        IO::line('NO');
    }

}

?>


A championship is held in Berland, in which $$$n$$$ players participate. The player with the number $$$i$$$ has $$$a_i$$$ ($$$a_i \ge 1$$$) tokens.The championship consists of $$$n-1$$$ games, which are played according to the following rules:  in each game, two random players with non-zero tokens are selected;  the player with more tokens is considered the winner of the game (in case of a tie, the winner is chosen randomly);  the winning player takes all of the loser's tokens; The last player with non-zero tokens is the winner of the championship.All random decisions that are made during the championship are made equally probable and independently.For example, if $$$n=4$$$, $$$a = [1, 2, 4, 3]$$$, then one of the options for the game (there could be other options) is:   during the first game, the first and fourth players were selected. The fourth player has more tokens, so he takes the first player's tokens. Now $$$a = [0, 2, 4, 4]$$$;  during the second game, the fourth and third players were selected. They have the same number of tokens, but in a random way, the third player is the winner. Now $$$a = [0, 2, 8, 0]$$$;  during the third game, the second and third players were selected. The third player has more tokens, so he takes the second player's tokens. Now $$$a = [0, 0, 10, 0]$$$;  the third player is declared the winner of the championship. Championship winners will receive personalized prizes. Therefore, the judges want to know in advance which players have a chance of winning, i.e have a non-zero probability of winning the championship. You have been asked to find all such players.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case consists of one positive integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of players in the championship. The second line of each test case contains $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the number of tokens the players have. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print the number of players who have a nonzero probability of winning the championship. On the next line print the numbers of these players in increasing order. Players are numbered starting from one in the order in which they appear in the input.

<?php

$times = (int)trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    $ni[] = (int)trim(fgets(STDIN));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $a = &$ai[$idx];
    $b = $a;
    sort($b);
    $sm = [$b[0]];
    for ($i = 1; $i < $n; ++$i) {
        $sm[$i] = $sm[$i - 1] + $b[$i];
    }
    $mx = $b[$n - 1];
    for ($i = $n - 1; $i >= 0; --$i) {
        if ($sm[$i] >= $mx) {
            $mx = $b[$i];
        } else {
            break;
        }
    }
    $ans = [];
    for ($i = 0; $i < $n; ++$i) {
        $a[$i] >= $mx && $ans[] = $i + 1;
    }
    echo count($ans) , PHP_EOL;
    echo implode(' ', $ans) , PHP_EOL;
}

<?php

$times = (int)trim(fgets(STDIN));
for ($idx = 0; $idx < $times; ++$idx) {
    $ni[] = (int)trim(fgets(STDIN));
    $ai[] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}
for ($idx = 0; $idx < $times; ++$idx) {
    $n = &$ni[$idx];
    $a = &$ai[$idx];
    $b = $a;
    sort($b);
    $sm = [];
    $tmp = 0;
    for ($i = 0; $i < $n; ++$i) {
        $tmp += $b[$i];
        $sm[] = $tmp;
    }
    $mx = max($b);
    for ($i = $n - 1; $i >= 0; --$i) {
        if ($sm[$i] >= $mx) {
            $mx = $b[$i];
        } else {
            break;
        }
    }
    $ans = [];
    for ($i = 0; $i < $n; ++$i) {
        $a[$i] >= $mx && $ans[] = $i + 1;
    }
    echo count($ans) , PHP_EOL;
    echo implode(' ', $ans) , PHP_EOL;
}


Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to $$$1$$$ meter movement in the south, north, west or east direction respectively).It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is $$$5$$$ seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes $$$1$$$ second.Find the skier's time to roll all the path.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed $$$10^5$$$ characters. The sum of the lengths of $$$t$$$ given lines over all test cases in the input does not exceed $$$10^5$$$.

For each test case, print the desired path time in seconds.


Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i.Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1 × 1. Squares are numbered 1, 2, 3 and so on. Vika decided that she will start painting squares one by one from left to right, starting from the square number 1 and some arbitrary color. If the square was painted in color x, then the next square will be painted in color x + 1. In case of x = n, next square is painted in color 1. If there is no more paint of the color Vika wants to use now, then she stops.Square is always painted in only one color, and it takes exactly 1 liter of paint. Your task is to calculate the maximum number of squares that might be painted, if Vika chooses right color to paint the first square.

The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of jars with colors Vika has. The second line of the input contains a sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of liters of paint in the i-th jar, i.e. the number of liters of color i that Vika has.

The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above.

NoteIn the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.In the second sample Vika can start to paint using any color.In the third sample Vika should start painting using color number 5.


You are given $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$n$$$ is odd. You are allowed to flip the sign of some (possibly all or none) of them. You wish to perform these flips in such a way that the following conditions hold:  At least $$$\frac{n - 1}{2}$$$ of the adjacent differences $$$a_{i + 1} - a_i$$$ for $$$i = 1, 2, \dots, n - 1$$$ are greater than or equal to $$$0$$$.  At least $$$\frac{n - 1}{2}$$$ of the adjacent differences $$$a_{i + 1} - a_i$$$ for $$$i = 1, 2, \dots, n - 1$$$ are less than or equal to $$$0$$$. Find any valid way to flip the signs. It can be shown that under the given constraints, there always exists at least one choice of signs to flip that satisfies the required condition. If there are several solutions, you can find any of them.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \le t \le 500$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$3 \le n \le 99$$$, $$$n$$$ is odd)  — the number of integers given to you. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$)  — the numbers themselves. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10000$$$.

For each test case, print $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$, corresponding to the integers after flipping signs. $$$b_i$$$ has to be equal to either $$$a_i$$$ or $$$-a_i$$$, and of the adjacent differences $$$b_{i + 1} - b_i$$$ for $$$i = 1, \dots, n - 1$$$, at least $$$\frac{n - 1}{2}$$$ should be non-negative and at least $$$\frac{n - 1}{2}$$$ should be non-positive. It can be shown that under the given constraints, there always exists at least one choice of signs to flip that satisfies the required condition. If there are several solutions, you can find any of them.

NoteIn the first test case, the difference $$$(-4) - (-2) = -2$$$ is non-positive, while the difference $$$3 - (-4) = 7$$$ is non-negative.In the second test case, we don't have to flip any signs. All $$$4$$$ differences are equal to $$$0$$$, which is both non-positive and non-negative.In the third test case, $$$7 - (-4)$$$ and $$$4 - (-6)$$$ are non-negative, while $$$(-4) - (-2)$$$ and $$$(-6) - 7$$$ are non-positive.


Monocarp wrote down two numbers on a whiteboard. Both numbers follow a specific format: a positive integer $$$x$$$ with $$$p$$$ zeros appended to its end.Now Monocarp asks you to compare these two numbers. Can you help him?

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 two integers $$$x_1$$$ and $$$p_1$$$ ($$$1 \le x_1 \le 10^6; 0 \le p_1 \le 10^6$$$) — the description of the first number. The second line of each testcase contains two integers $$$x_2$$$ and $$$p_2$$$ ($$$1 \le x_2 \le 10^6; 0 \le p_2 \le 10^6$$$) — the description of the second number.

For each testcase print the result of the comparison of the given two numbers. If the first number is smaller than the second one, print '<'. If the first number is greater than the second one, print '>'. If they are equal, print '='.

<?php

# ...შენ რო გიყურებ ერთ ანიგდოტ მახსენდება ოღონდ სასაცილო არ არი.
# ბალღოო! ჭკვიანად იყავ თორე გიამბობ იცოდე. გიიგე?
#
# თუში მეცხვარე.
# გახსოვდეს ვისი გორისა ხარ

function readArray()
{
    return array_map('intval', explode(' ', trim(readline())));
}

function countLen($num, $additional)
{
    return strlen(strval($num)) + $additional;
}

$n = +readline();

while($n--)
{
    list($a, $aZeros) = readArray();
    list($b, $bZeros) = readArray();

    $aNumLen = countLen($a, $aZeros);
    $bNumLen = countLen($b, $bZeros);

    if($aNumLen > $bNumLen)
    {
        echo '>';
    }
    else if($aNumLen < $bNumLen)
    {
        echo '<';
    }
    else
    {
        while(strlen(strval($a)) !== strlen(strval($b)))
        {
            if(strlen(strval($a)) < strlen(strval($b)))
            {
                $a *= 10;
            }
            else
            {
                $b *= 10;
            }
        }

        if($a > $b)
        {
            echo '>';
        }
        else if($a < $b)
        {
            echo '<';
        }
        else
        {
            echo '=';
        }
    }

    echo "\n";
}

<?php
ini_set("display_errors","Off");
error_reporting(0);
$t1=microtime(1);
$stdin=fopen('php://stdin', 'r');
fscanf($stdin, "%d\n",$caseCount);
$arrayAs=[];
function proc($x,$p){
    if($x<10){return [$x,$p];}
    do{$p++;}while(($x/=10)>9);
    return [$x,$p];
}
for($j=0;$j<$caseCount;$j++) {
    fscanf($stdin, "%d %d\n", $x1,$p1);
    fscanf($stdin, "%d %d\n", $x2,$p2);
//    echo "[$x1,$p1]\n";
    list($x1,$p1)=proc($x1,$p1);
//    echo "[$x1,$p1]\n";
    list($x2,$p2)=proc($x2,$p2);
    if($p1>$p2){echo ">";}elseif($p1<$p2){echo "<";}elseif($x1<$x2){echo "<";}elseif($x1>$x2){echo ">";}else{echo "=";}
    echo "\n";
}

<?php
ini_set("display_errors","Off");
error_reporting(0);
$t1=microtime(1);
$stdin=fopen('php://stdin', 'r');
fscanf($stdin, "%d\n",$caseCount);
$arrayAs=[];
function proc($x,$p){
    if($x<10){return [$x,$p];}
    while(($x/=10)>9){$p++;}
    return [$x,$p];
}
for($j=0;$j<$caseCount;$j++) {
    fscanf($stdin, "%d %d\n", $x1,$p1);
    fscanf($stdin, "%d %d\n", $x2,$p2);
//    echo "[$x1,$p1]\n";
    list($x1,$p1)=proc($x1,$p1);
//    echo "[$x1,$p1]\n";
    list($x2,$p2)=proc($x2,$p2);
    if($p1>$p2){echo ">";}elseif($p1<$p2){echo "<";}elseif($x1<$x2){echo "<";}elseif($x1>$x2){echo ">";}else{echo "=";}
    echo "\n";
}


Alice and Bob have received three big piles of candies as a gift. Now they want to divide these candies as fair as possible. To do this, Alice takes one pile of candies, then Bob takes one of the other two piles. The last pile is split between Alice and Bob as they want: for example, it is possible that Alice takes the whole pile, and Bob gets nothing from it.After taking the candies from the piles, if Alice has more candies than Bob, she discards some candies so that the number of candies she has is equal to the number of candies Bob has. Of course, Bob does the same if he has more candies.Alice and Bob want to have as many candies as possible, and they plan the process of dividing candies accordingly. Please calculate the maximum number of candies Alice can have after this division process (of course, Bob will have the same number of candies).You have to answer $$$q$$$ independent queries.Let's see the following example: $$$[1, 3, 4]$$$. Then Alice can choose the third pile, Bob can take the second pile, and then the only candy from the first pile goes to Bob — then Alice has $$$4$$$ candies, and Bob has $$$4$$$ candies.Another example is $$$[1, 10, 100]$$$. Then Alice can choose the second pile, Bob can choose the first pile, and candies from the third pile can be divided in such a way that Bob takes $$$54$$$ candies, and Alice takes $$$46$$$ candies. Now Bob has $$$55$$$ candies, and Alice has $$$56$$$ candies, so she has to discard one candy — and after that, she has $$$55$$$ candies too.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 1000$$$) — the number of queries. Then $$$q$$$ queries follow. The only line of the query contains three integers $$$a, b$$$ and $$$c$$$ ($$$1 \le a, b, c \le 10^{16}$$$) — the number of candies in the first, second and third piles correspondingly.

Print $$$q$$$ lines. The $$$i$$$-th line should contain the answer for the $$$i$$$-th query — the maximum number of candies Alice can have after the division, if both Alice and Bob act optimally (of course, Bob will have the same number of candies).

<?php
list($c) = explode(' ', trim(fgets(STDIN)));
for($i = 0; $i < $c; $i++){
    list($a,$y,$z) = explode(' ', trim(fgets(STDIN)));
    $iTotal = bcadd(bcadd($a,$y),$z);
    $iAnswer = bcdiv($iTotal,2);
    echo $iAnswer."\n";
}

<?php
#1196A
$n = trim(fgets(STDIN));
while ($n--) {
    $result = 0;
    $arr = explode(' ', trim(fgets(STDIN)));
    foreach ($arr as $v) {
        $result = bcadd($result, $v);
    }
    echo bcdiv($result, 2) . PHP_EOL;
}

<?php

$t = trim(fgets(STDIN));

$ans = '';
for ($o = 0; $o < $t; $o++)
{
	$data = explode(" ", trim(fgets(STDIN)));
	$ans .= bcdiv(bcadd($data[0], bcadd($data[1], $data[2])), 2)."\n";
}
echo $ans;

?>


Shubham has a binary string $$$s$$$. A binary string is a string containing only characters "0" and "1".He can perform the following operation on the string any amount of times:   Select an index of the string, and flip the character at that index. This means, if the character was "0", it becomes "1", and vice versa. A string is called good if it does not contain "010" or "101" as a subsequence  — for instance, "1001" contains "101" as a subsequence, hence it is not a good string, while "1000" doesn't contain neither "010" nor "101" as subsequences, so it is a good string.What is the minimum number of operations he will have to perform, so that the string becomes good? It can be shown that with these operations we can make any string good.A string $$$a$$$ is a subsequence of a string $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) characters.

The first line of the input contains a single integer $$$t$$$ $$$(1\le t \le 100)$$$ — the number of test cases. Each of the next $$$t$$$ lines contains a binary string $$$s$$$ $$$(1 \le |s| \le 1000)$$$.

For every string, output the minimum number of operations required to make it good.

NoteIn test cases $$$1$$$, $$$2$$$, $$$5$$$, $$$6$$$ no operations are required since they are already good strings.For the $$$3$$$rd test case: "001" can be achieved by flipping the first character  — and is one of the possible ways to get a good string.For the $$$4$$$th test case: "000" can be achieved by flipping the second character  — and is one of the possible ways to get a good string.For the $$$7$$$th test case: "000000" can be achieved by flipping the third and fourth characters  — and is one of the possible ways to get a good string.

<?php
    define("MAXN", 1024) ;

    $T = intval(fgets(STDIN));
    while($T --)
    {
        $Hate = trim(fgets(STDIN)) ;

        $len = strlen($Hate) ;

        $prefix_sum = array(
            array_fill(0, $len, 0),
            array_fill(0, $len, 0)
        ) ;

        $suffix_sum = array(
            array_fill(0, $len + 1, 0),
            array_fill(0, $len + 1, 0)
        ) ;

        if($Hate[0] == '0') $prefix_sum[0][0] = 1 ;
        else $prefix_sum[1][0] = 1 ;

        for($i = 1; $i < $len; $i ++)
        {
            $prefix_sum[0][$i] = $prefix_sum[0][$i - 1] ;
            $prefix_sum[1][$i] = $prefix_sum[1][$i - 1] ;

            if($Hate[$i] == '0') $prefix_sum[0][$i] ++ ;
            if($Hate[$i] == '1') $prefix_sum[1][$i] ++ ;
        }

        for($i = $len - 1; $i >= 0; $i --)
        {
            $suffix_sum[0][$i] = $suffix_sum[0][$i + 1] ;
            $suffix_sum[1][$i] = $suffix_sum[1][$i + 1] ;

            if($Hate[$i] == '0') $suffix_sum[0][$i] ++ ;
            if($Hate[$i] == '1') $suffix_sum[1][$i] ++ ;
        }

        $ans = $len ;
        for($i = 0; $i < $len; $i ++)
        {
            $ans = min($ans, $prefix_sum[1][$i] + $suffix_sum[0][$i + 1]) ;
            $ans = min($ans, $prefix_sum[0][$i] + $suffix_sum[1][$i + 1]) ;
        }

        echo $ans . "\n" ;
    }
?>

<?php
    define("MAXN", 1024) ;

    $T = intval(fgets(STDIN));
    while($T --)
    {
        $Hate = trim(fgets(STDIN)) ;

        $len = strlen($Hate) ;

        $prefix_sum = array(
            array_fill(0, $len, 0),
            array_fill(0, $len, 0)
        ) ;

        $suffix_sum = array(
            array_fill(0, $len + 1, 0),
            array_fill(0, $len + 1, 0)
        ) ;

        if($Hate[0] == '0') $prefix_sum[0][0] = 1 ;
        else $prefix_sum[1][0] = 1 ;

        if($Hate[$len - 1] == '0') $suffix_sum[0][$len - 1] = 1 ;
        else $suffix_sum[1][$len - 1] = 1 ;

        for($i = 1; $i < $len; $i ++)
        {
            $prefix_sum[0][$i] = $prefix_sum[0][$i - 1] ;
            $prefix_sum[1][$i] = $prefix_sum[1][$i - 1] ;

            if($Hate[$i] == '0') $prefix_sum[0][$i] ++ ;
            if($Hate[$i] == '1') $prefix_sum[1][$i] ++ ;
        }

        for($i = $len - 2; $i >= 0; $i --)
        {
            $suffix_sum[0][$i] = $suffix_sum[0][$i + 1] ;
            $suffix_sum[1][$i] = $suffix_sum[1][$i + 1] ;

            if($Hate[$i] == '0') $suffix_sum[0][$i] ++ ;
            if($Hate[$i] == '1') $suffix_sum[1][$i] ++ ;
        }

        $ans = $len ;
        for($i = 0; $i < $len; $i ++)
        {
            $ans = min($ans, $prefix_sum[1][$i] + $suffix_sum[0][$i + 1]) ;
            $ans = min($ans, $prefix_sum[0][$i] + $suffix_sum[1][$i + 1]) ;
        }

        echo $ans . "\n" ;
    }
?>

<?php
    define("MAXN", 1024) ;

    $T = intval(fgets(STDIN));
    while($T --)
    {
        $Hate = trim(fgets(STDIN)) ;

        $len = strlen($Hate) ;

        $prefix_sum = array(
            array_fill(0, $len, 0),
            array_fill(0, $len, 0)
        ) ;

        $suffix_sum = array(
            array_fill(0, $len, 0),
            array_fill(0, $len, 0)
        ) ;

        if($Hate[0] == '0') $prefix_sum[0][0] = 1 ;
        else $prefix_sum[1][0] = 1 ;

        if($Hate[$len - 1] == '0') $suffix_sum[0][$len - 1] = 1 ;
        else $suffix_sum[1][$len - 1] = 1 ;

        for($i = 1; $i < $len; $i ++)
        {
            $prefix_sum[0][$i] = $prefix_sum[0][$i - 1] ;
            $prefix_sum[1][$i] = $prefix_sum[1][$i - 1] ;

            if($Hate[$i] == '0') $prefix_sum[0][$i] ++ ;
            if($Hate[$i] == '1') $prefix_sum[1][$i] ++ ;
        }

        for($i = $len - 2; $i >= 0; $i --)
        {
            $suffix_sum[0][$i] = $suffix_sum[0][$i + 1] ;
            $suffix_sum[1][$i] = $suffix_sum[1][$i + 1] ;

            if($Hate[$i] == '0') $suffix_sum[0][$i] ++ ;
            if($Hate[$i] == '1') $suffix_sum[1][$i] ++ ;
        }

        $ans = $len ;
        for($i = 0; $i + 1 < $len; $i ++)
        {
            $ans = min($ans, $prefix_sum[1][$i] + $suffix_sum[0][$i + 1]) ;
            $ans = min($ans, $prefix_sum[0][$i] + $suffix_sum[1][$i + 1]) ;
        }

        echo $ans . "\n" ;
    }
?>


When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members efficiently), so he decided to organize his own contests PFAST Inc. — Petr and Friends Are Solving Tasks Corporation. PFAST Inc. rules allow a team to have unlimited number of members.To make this format of contests popular he organised his own tournament. To create the team he will prepare for the contest organised by the PFAST Inc. rules, he chose several volunteers (up to 16 people) and decided to compile a team from them. Petya understands perfectly that if a team has two people that don't get on well, then the team will perform poorly. Put together a team with as many players as possible given that all players should get on well with each other.

The first line contains two integer numbers n (1 ≤ n ≤ 16) — the number of volunteers, and m () — the number of pairs that do not get on. Next n lines contain the volunteers' names (each name is a non-empty string consisting of no more than 10 uppercase and/or lowercase Latin letters). Next m lines contain two names — the names of the volunteers who do not get on. The names in pair are separated with a single space. Each pair of volunteers who do not get on occurs exactly once. The strings are case-sensitive. All n names are distinct.

The first output line should contain the single number k — the number of people in the sought team. Next k lines should contain the names of the sought team's participants in the lexicographical order. If there are several variants to solve the problem, print any of them. Petya might not be a member of the sought team.


One fine October day a mathematics teacher Vasily Petrov went to a class and saw there n pupils who sat at the  desks, two people at each desk. Vasily quickly realized that number n is even. Like all true mathematicians, Vasily has all students numbered from 1 to n.But Vasily Petrov did not like the way the children were seated at the desks. According to him, the students whose numbers differ by 1, can not sit together, as they talk to each other all the time, distract others and misbehave.On the other hand, if a righthanded student sits at the left end of the desk and a lefthanded student sits at the right end of the desk, they hit elbows all the time and distract each other. In other cases, the students who sit at the same desk, do not interfere with each other.Vasily knows very well which students are lefthanders and which ones are righthanders, and he asks you to come up with any order that meets these two uncomplicated conditions (students do not talk to each other and do not bump their elbows). It is guaranteed that the input is such that at least one way to seat the students always exists.

The first input line contains a single even integer n (4 ≤ n ≤ 100) — the number of students in the class. The second line contains exactly n capital English letters "L" and "R". If the i-th letter at the second line equals "L", then the student number i is a lefthander, otherwise he is a righthander.

Print  integer pairs, one pair per line. In the i-th line print the numbers of students that will sit at the i-th desk. The first number in the pair stands for the student who is sitting to the left, and the second number stands for the student who is sitting to the right. Separate the numbers in the pairs by spaces. If there are multiple solutions, print any of them.

<?php
$aClass = explode("\n", file_get_contents("input.txt"));
$len = $aClass[0];
$pupil = $aClass[1];
$result = "";

for ( $i = 0; $i < $len/2; $i++ ){

    if ( $pupil[$i] == "R") $result .= ($i+1+$len/2)." ".($i+1);

    else  $result .= ($i+1)." ".($i+1+$len/2);

    if($i < $len) $result .= "\n";

}

$handle = fopen("output.txt", "w");
fwrite($handle, $result);
fclose($handle);
?>

<?php
@error_reporting(0);
$stdin = fopen("input.txt", "r");
$stdout = fopen("output.txt", "w");

$n = intval(fgets($stdin));
$st = trim(fgets($stdin));
fclose($stdin);
for($i = 0; $i < $n / 2; ++ $i) {
	if($st[$i] == 'R' && $st[$i + $n / 2] == 'L'){
		fwrite($stdout, strval($i + $n / 2 + 1) . " " . strval($i + 1) . "\n");
	} else {
		fwrite($stdout, strval($i + 1) . " " . strval($i + 1 + $n / 2) . "\n");
	}
}
fclose($stdout);

<?php
$aClass = explode("\n", file_get_contents("input.txt"));
$len = $aClass[0];
$pupil = $aClass[1];
$result = "";

for($i = 0; $i < len/2; $i++){
if($pupil[$i] == "R")
$result .= ($i+$len/2+1)." ".($i+1);
else
$result .= ($i+1)." ".($i+$len/2+1);
if($i < $len) $result .= "\n";
}

$handle = fopen("output.txt", "w");
fwrite($handle, $result);
fclose($handle);
?>

<?php
$aClass = explode("\n", file_get_contents("input.txt"));
$len = $aClass[0];
$pupil = $aClass[1];
$result = "";

for($i = 0; $i < len/2; $i++){
if($pupil[$i] == 'R' && $pupil[$i+$len/2] == 'L')
$result .= ($i+$len/2+1).' '.($i+1);
else
$result .= ($i+1).' '.($i+$len/2+1);
if($i < len/2-1) $result .= '\n';
}

$handle = fopen("output.txt", "w");
fwrite($handle, $result);
fclose($handle);
?>

<?php
$aClass = explode("\n", file_get_contents("input.txt"));
$len = $aClass[0];
$pupil = $aClass[1];
$result = "";

for($i = 0; $i < len/2; $i++){
if($pupil[$i] == 'R' && $pupil[$i+$len/2] == 'L')
$result .= ($i+$len/2).' '.$i;
else
$result .= $i.' '.($i+$len/2);
$result .= '\n';
}

$handle = fopen("output.txt", "w");
fwrite($handle, $result);
fclose($handle);
?>

<?php
$aClass = explode("\n", file_get_contents("input.txt"));
$len = $aClass[0];
$pupil = $aClass[1];
$result = "";

for($i = 0; $i < len/2; $i++){
if($pupil[$i] == 'R')
$result .= ($i+$len/2+1)." ".($i+1);
else
$result .= ($i+1)." ".($i+$len/2+1);
if($i < $len) $result .= "\n";
}

$handle = fopen("output.txt", "w");
fwrite($handle, $result);
fclose($handle);
?>

<?php
@error_reporting(0);
$stdin = fopen("php://stdin", "r");
$stdout = fopen("php://stdout", "w");

$n = intval(fgets($stdin));
$st = trim(fgets($stdin));
fclose($stdin);
for($i = 0; $i < $n / 2; ++ $i) {
	if($st[$i] == 'R' && $st[$i + $n / 2] == 'L'){
		fwrite($stdout, strval($i + $n / 2 + 1) . " " . strval($i + 1) . "\n");
	} else {
		fwrite($stdout, strval($i + 1) . " " . strval($i + 1 + $n / 2) . "\n");
	}
}
fclose($stdout);

<?php
$aClass = explode("\n", stream_get_contents(fopen("php://stdin", 'r')));
$len = $aClass[0];
$pupil = explode('', $aClass[1]);
for ( $i = 1; $i <= $len/2; $i++ ){
    $a = $len / 2 + $i;
    if ( $pupil[$i] == "R" && $pupil[$a] == "L") echo $i." ".$a;
    else  echo $a." ".$i;
    if($i < $len) echo "\n";
}
?>

<?php
$aClass = explode("\n", file_get_contents("input.txt"));
$len = $aClass[0];
$pupil = $aClass[1];
$result = "";

for ( $i = 0; $i < $len/2; $i++ ){

    $a = $len / 2 + $i;

    if ( $pupil[$i] == "L" && $pupil[$a] == "R") echo ($i+1)." ".($a+1);

    else  echo ($a+1)." ".$i;

    if($i < $len) echo $result .= "\n";

}

$handle = fopen("output.txt", "w");
fwrite($handle, $result);
fclose($handle);
?>

<?php
$aClass = explode("\n", stream_get_contents(fopen("php://stdin", 'r')));
$len = $aClass[0];
$pupil = explode('', $aClass[1]);
var_dump($pupil);
for ( $i = 1; $i <= $len/2; $i++ ){
    $a = $len / 2 + $i;
    if ( $pupil[$i] == "R" && $pupil[$a] == "L") echo $i." ".$a;
    else  echo $a." ".$i;
    if($i < $len) echo "\n";
}
?>

<?php
$sNum = file_get_contents("input.txt");
$c = 0;
hexadecimal(1);
function hexadecimal($a){
    global $sNum, $c;
    if($a <= $sNum){
		$c++;
        hexadecimal($a*10);
        hexadecimal($a*10+1);
    }
    return true;
}
$handle = fopen("output.txt", "w");
fwrite($handle, $c);
fclose($handle);
?>

<?php
$aClass = explode("\n", file_get_contents("input.txt"));
$len = $aClass[0];
$pupil = explode('', $aClass[1]);
$result = "";

for ( $i = 1; $i <= $len/2; $i++ ){

    $a = $len / 2 + $i;

    if ( $pupil[$i] == "R" && $pupil[$a] == "L") $result .= $i." ".$a;

    else  echo $result .= $a." ".$i;

    if($i < $len) echo $result .= "\n";

}

$handle = fopen("output.txt", "w");
fwrite($handle, $result);
fclose($handle);
?>

<?php
$sNum = stream_get_contents(fopen("php://stdin", 'r'));
$c = 0;
hexadecimal(1);
function hexadecimal($a){
    global $sNum, $c;
    if($a <= $sNum){
		$c++;
        hexadecimal($a*10);
        hexadecimal($a*10+1);
    }
    return true;
}
echo $c;
?>

<?php
$aClass = explode("\n", file_get_contents("input.txt"));
$len = $aClass[0];
$pupil = $aClass[1];
$result = "";

for ( $i = 0; $i < $len/2; $i++ ){

    $a = $len / 2 + $i;

    if ( $pupil[$i] == "L" && $pupil[$a] == "R") $result .= ($i+1)." ".($a+1);

    else  $result .= ($a+1)." ".$i;

    if($i < $len) $result .= "\n";

}

$handle = fopen("output.txt", "w");
fwrite($handle, $result);
fclose($handle);
?>

<?php
$aClass = explode("\n", file_get_contents("input.txt"));
$len = $aClass[0];
$pupil = $aClass[1];
$result = "";

for ( $i = 0; $i < $len/2; $i++ ){

    $a = $len / 2 + $i;

    if ( $pupil[$i] == "R" && $pupil[$a] == "R") $result .= ($i+1+$len/2)." ".($i+1);

    else  $result .= ($i+1)." ".($i+1+$len/2);

    if($i < $len) $result .= "\n";

}

$handle = fopen("output.txt", "w");
fwrite($handle, $result);
fclose($handle);
?>


You work in the quality control department of technical support for a large company. Your job is to make sure all client issues have been resolved.Today you need to check a copy of a dialog between a client and a technical support manager. According to the rules of work, each message of the client must be followed by one or several messages, which are the answer of a support manager. However, sometimes clients ask questions so quickly that some of the manager's answers to old questions appear after the client has asked some new questions.Due to the privacy policy, the full text of messages is not available to you, only the order of messages is visible, as well as the type of each message: a customer question or a response from the technical support manager. It is guaranteed that the dialog begins with the question of the client.You have to determine, if this dialog may correspond to the rules of work described above, or the rules are certainly breached.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). Description of the test cases follows. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the total number of messages in the dialog. The second line of each test case consists of $$$n$$$ characters "Q" and "A", describing types of messages in the dialog in chronological order. Character "Q" denotes the message with client question, and character "A" — the message with technical support manager answer. It is guaranteed that the first character in the line equals to "Q".

For each test case print "Yes" (without quotes) if dialog may correspond to the rules of work, or "No" (without quotes) otherwise.

5

4

QQAA

4

QQAQ

3

QAA

1

Q

14

QAQQAQAAQQQAAA

NoteIn the first test case the two questions from the client are followed with two specialist's answers. So this dialog may correspond to the rules of work.In the second test case one of the first two questions was not answered.In the third test case the technical support manager sent two messaged as the answer to the only message of the client.

<?php

$tc = trim(fgets(STDIN));

while ($tc-- > 0) {
    $messages = trim(fgets(STDIN));
    $dialog = trim(fgets(STDIN));

    $questions = 0;

    for ($i = 0; $i < strlen($dialog); $i++) {
        if ($dialog[$i] === 'Q') {
            $questions++;
        } else if ($questions > 0) {
            $questions--;
        }
    }

    if ($questions === 0) {
        echo "Yes" . PHP_EOL;
    } else {
        echo "No" . PHP_EOL;
    }
}

?>

<?php

//[$a,$b] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$h = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$mod = 998244353;
//$mod = 1000000007;
//$alpha = "abcdefghijklmnopqrstuvwxyz";

[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));

for($i=0;$i<$t;$i++){
    [$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    [$s] = explode(' ', trim(fgets(STDIN)));
    $qcnt = 0;
    for($j=0;$j<$n;$j++){
        if($s[$j]=="Q") {
            $qcnt++;
        }
        else {
            $qcnt--;
            if($qcnt < 0) $qcnt = 0;
        }
    }
    if($qcnt > 0) $ans[] = "No";
    else $ans[] = "Yes";
}
echo implode(PHP_EOL,$ans);

<?php
$t = trim(fgets(STDIN));
for($i=0; $i < $t; $i++) {
    $n =  trim(fgets(STDIN));
	$a =  trim(fgets(STDIN));

    $counter = 0;
	for($j = 0; $j < $n; $j++){
		if ($a[$j] == "Q")
		{
			$counter++;
		} else if($a[$j] == "A"){
			if($counter>0)
			{
				$counter--;
			}
		}
    }
	if($counter<=0){
		echo "Yes";
	}
	else{
		echo "No";
	}
    echo "\n";
}

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

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $s = IO::get();
   $ans = 'NO';
   $q = 0;
   $a = 0;

   for ($i = 0; $i < $n; $i++) {
      if($s[$i] == 'Q') {
           $q++;
      } else {
           if($q > 0) {
             $q--;
           }
      }
   }

   $ans = $q == 0 ? 'YES' : 'NO';

    IO::pr($ans);
}

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

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

<?php

$tc = trim(fgets(STDIN));

while ($tc-- > 0) {
    $messages = trim(fgets(STDIN));
    $dialog = trim(fgets(STDIN));

    $questions = 0;
    $answers = 0;

    for ($i = 0; $i < strlen($dialog); $i++) {
        if ($dialog[$i] === 'Q') {
            $questions++;
        } else {
            $answers++;
        }
    }

    if ($answers >= $questions) {
        echo "Yes" . PHP_EOL;
    } else {
        echo "No" . PHP_EOL;
    }
}

?>

<?php

//[$a,$b] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$h = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$mod = 998244353;
//$mod = 1000000007;
//$alpha = "abcdefghijklmnopqrstuvwxyz";

[$t] = array_map('intval', explode(' ', trim(fgets(STDIN))));

for($i=0;$i<$t;$i++){
    [$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    [$s] = explode(' ', trim(fgets(STDIN)));
    $qcnt = 0;
    for($j=0;$j<$n;$j++){
        if($s[$j]=="Q") $qcnt++;
    }
    if($qcnt > ($n-$qcnt)) $ans[] = "No";
    else $ans[] = "Yes";
}
echo implode(PHP_EOL,$ans);


Alica and Bob are playing a game.Initially they have a binary string $$$s$$$ consisting of only characters 0 and 1.Alice and Bob make alternating moves: Alice makes the first move, Bob makes the second move, Alice makes the third one, and so on. During each move, the current player must choose two different adjacent characters of string $$$s$$$ and delete them. For example, if $$$s = 1011001$$$ then the following moves are possible:   delete $$$s_1$$$ and $$$s_2$$$: $$$\textbf{10}11001 \rightarrow 11001$$$;  delete $$$s_2$$$ and $$$s_3$$$: $$$1\textbf{01}1001 \rightarrow 11001$$$;  delete $$$s_4$$$ and $$$s_5$$$: $$$101\textbf{10}01 \rightarrow 10101$$$;  delete $$$s_6$$$ and $$$s_7$$$: $$$10110\textbf{01} \rightarrow 10110$$$. If a player can't make any move, they lose. Both players play optimally. You have to determine if Alice can win.

First line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Only line of each test case contains one string $$$s$$$ ($$$1 \le |s| \le 100$$$), consisting of only characters 0 and 1.

For each test case print answer in the single line. If Alice can win print DA (YES in Russian) in any register. Otherwise print NET (NO in Russian) in any register.

NoteIn the first test case after Alice's move string $$$s$$$ become empty and Bob can not make any move.In the second test case Alice can not make any move initially.In the third test case after Alice's move string $$$s$$$ turn into $$$01$$$. Then, after Bob's move string $$$s$$$ become empty and Alice can not make any move.

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

        $ans = min(substr_count($in_str, "0"), substr_count($in_str, "1")) ;

        echo $ans&1 ? "DA\n" : "NET\n" ;
    }
?>


You are given an array $$$a_1, a_2, \dots, a_n$$$ where all $$$a_i$$$ are integers and greater than $$$0$$$. In one operation, you can choose two different indices $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$). If $$$gcd(a_i, a_j)$$$ is equal to the minimum element of the whole array $$$a$$$, you can swap $$$a_i$$$ and $$$a_j$$$. $$$gcd(x, y)$$$ denotes the greatest common divisor (GCD) of integers $$$x$$$ and $$$y$$$. Now you'd like to make $$$a$$$ non-decreasing using the operation any number of times (possibly zero). Determine if you can do this. An array $$$a$$$ is non-decreasing if and only if $$$a_1 \le a_2 \le \ldots \le a_n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.  The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of array $$$a$$$.  The second line of each test case contains $$$n$$$ positive integers $$$a_1, a_2, \ldots a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the array itself.  It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$10^5$$$.

For each test case, output "YES" if it is possible to make the array $$$a$$$ non-decreasing using the described operation, or "NO" if it is impossible to do so.

Note In the first and third sample, the array is already non-decreasing. In the second sample, we can swap $$$a_1$$$ and $$$a_3$$$ first, and swap $$$a_1$$$ and $$$a_5$$$ second to make the array non-decreasing. In the forth sample, we cannot the array non-decreasing using the operation.

<?php
    $j = trim(fgets(STDIN));
    for($l = 0; $l < $j; $l++){
        $a = trim(fgets(STDIN));
        $b = $c = explode(" ", trim(fgets(STDIN)));
        sort($c);
        $min = $c[0];
        $bool = true;
        foreach($b as $sK => $bb){
            if($bb != $c[$sK]){
                if($c[$sK] % $min != 0){
                    echo "NO\n";
                    $bool = false;
                    break;
                }
            }
        }
        if($bool){
            echo "YES\n";
        }
    }

?>