Published using Google Docs
Polygon advices
Updated automatically every 5 minutes

IF YOU ARE TO PREPARE A ROUND ON CODEFORCES, THESE ARE RULES.
FOLLOW THEM AS CLOSE AS YOU CAN.

* are for Codeforces only.

Tutorial/walkthrough


Checker, validator, and interactor

Checker:

Tests and generators

D2A

D2B

D2C

D2D

Pretests

4

10

20

30

Tests

10

15

40

70

Statements

English

Russian

The first line contains a single integer $n$ ($1 \le n \le 10^5$).

Первая строка содержит одно целое число $n$ ($1 \le n \le 10^5$).

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$).

Вторая строка содержит $n$ целых чисел $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$).

Each of the next $m$ lines contains two integers $x$ and $y$ ($1 \le x, y \le n$), or The $i$-th of the next $m$ lines contains two integers $x_i$ and $y_i$  ($1 \le x_i, y_i \le n$).

Каждая из следующих $m$ строк содержит два целых числа $x$ и $y$ ($1 \le x, y \le n$), или $i$-я из следующих $m$ строк содержит два целых числа $x_i$ и $y_i$  ($1 \le x_i, y_i \le n$).

You can output the answer in any case (upper or lower). For example, the strings ``\t{yEs}'', ``\t{yes}'', ``\t{Yes}'', and ``\t{YES}'' will be recognized as positive responses.

Вы можете выводить каждую букву в любом регистре (строчную или заглавную). Например, строки <<\t{yEs}>>, <<\t{yes}>>, <<\t{Yes}>> и <<\t{YES}>> будут приняты как положительный ответ.

If there are multiple solutions, print any of them.

Если существует несколько решений, выведите любое из них.

If there is no solution, print a single integer $-1$.

Если решения не существует, выведите одно целое число $-1$.

Output <...> modulo $998\,244\,353$.

Formally, let $M = 998\,244\,353$. It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$, where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$. Output the integer equal to $p \cdot q^{-1} \bmod M$. In other words, output such an integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$.

Выведите <...> по модулю $998\,244\,353$.

Формально, пусть $M = 998\,244\,353$. Можно показать, что ответ может быть представлен в виде несократимой дроби $\frac{p}{q}$, где $p$ и $q$ "--- целые числа, и $q \not \equiv 0 \pmod{M}$. Выведите целое число, равное $p \cdot q^{-1} \bmod M$. Другими словами, выведите такое целое число $x$, что $0 \le x < M$ и $x \cdot q \equiv p \pmod{M}$.

We can show that an answer always exists.

This phrase should be put in legend/output and means that for every possible input an answer exists. No additional constraints are added here.

Можно показать, что ответ всегда существует.

Используйте это предложение в легенде или в формате вывода. Она означает, что для всех возможных тестов ответ существует и не накладывает дополнительных ограничений на тест.

It is guaranteed that...
It means that the input is specially prepared so that the condition holds. This should be put in the legend and input section. Example: It is guaranteed that the given edges form a tree.

Гарантируется, что...
Эта фраза означает, что тесты специально подобраны таким образом, чтобы условие выполнялось. Используйте ее в легенде и формате ввода. Например: Гарантируется, что заданные ребра образуют дерево.

Your answer is considered correct if its absolute or relative error does not exceed $10^{-9}$.

Formally, let your answer be $a$, and the jury's answer be $b$. Your answer is accepted if and only if $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-9}$.
Don’t forget to change the precision!

Ваш ответ будет считаться правильным, если его абсолютная или относительная ошибка не превосходит $10^{-9}$.

Формально, пусть ваш ответ равен $a$, а ответ жюри равен $b$. Ваш ответ будет зачтен, если и только если $\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-9}$.
Не забудьте поменять точность!

..., where $\oplus$ denotes the \href{https://en.wikipedia.org/wiki/Bitwise_operation#XOR}{bitwise XOR operation}.

..., где $\oplus$ обозначает операцию \href{https://ru.wikipedia.org/wiki/Битовая_операция#Побитовое_исключающее_ИЛИ}{побитового исключающего ИЛИ}.

..., where $\&$ denotes the \href{https://en.wikipedia.org/wiki/Bitwise_operation#AND}{bitwise AND operation}.

..., где $\&$ обозначает операцию \href{https://ru.wikipedia.org/wiki/Битовая_операция#Побитовое_И}{побитового И}.
К сожалению CF пока не научился протаскивать ссылки со скобками, поэтому так.

..., where $|$ denotes the \href{https://en.wikipedia.org/wiki/Bitwise_operation#OR}{bitwise OR operation}.

..., где $|$ обозначает операцию \href{https://ru.wikipedia.org/wiki/Битовая_операция#Побитовое_ИЛИ}{побитового ИЛИ}.

..., where $\gcd(x, y)$ denotes the \href{https://en.wikipedia.org/wiki/Greatest_common_divisor}{greatest common divisor (GCD)} of integers $x$ and $y$.
Replace $x$ and $y$ if you use them in some other place of the statement!

..., где $\gcd(x, y)$ обозначает \href{https://ru.wikipedia.org/wiki/Наибольший_общий_делитель}{наибольший общий делитель (НОД)} чисел $x$ и $y$.
Замените $x$ и $y$, если они используются в другом месте в условии!

..., where $\operatorname{MEX}$ of a collection of integers $c_1, c_2, \ldots, c_k$ is defined as the smallest non-negative integer $x$ which does not occur in the collection $c$.

..., где $\operatorname{MEX}$ набора чисел $c_1,c_2,\ldots,c_k$ определяется как наименьшее неотрицательное целое число $x$, которое не встречается в наборе чисел $c$.

Here $x \bmod y$ denotes the remainder from dividing $x$ by $y$.

Replace $x$ and $y$ if you use them in some other place of the statement!

Здесь $x \bmod y$ обозначает остаток от деления $x$ на $y$.

Замените $x$ и $y$, если они используются в другом месте в условии!

A string $a$ is lexicographically smaller than a string $b$ if and only if one of the following holds:

\begin{itemize}

\item $a$ is a prefix of $b$, but $a \ne b$;

\item in the first position where $a$ and $b$ differ, the string $a$ has a letter that appears earlier in the alphabet than the corresponding letter in $b$.

\end{itemize}

Replace $a$ and $b$ if you use them in some other place of the statement!

Строка $a$ лексикографически меньше строки $b$, если и только если выполняется один из следующих пунктов:

\begin{itemize}

\item $a$ “--- префикс $b$, но $a \ne b$;

\item в первой позиции, где $a$ и $b$ различны, в строке $a$ находится буква, которая встречается в алфавите раньше, чем соответствующая буква в $b$.

\end{itemize}

Замените $a$ и $b$, если они используются в другом месте в условии!

A sequence $a$ is lexicographically smaller than a sequence $b$ if and only if one of the following holds:

\begin{itemize}

\item $a$ is a prefix of $b$, but $a \ne b$;

\item in the first position where $a$ and $b$ differ, the sequence $a$ has a smaller element than the corresponding element in $b$.

\end{itemize}

Replace $a$ and $b$ if you use them in some other place of the statement!

Последовательность $a$ лексикографически меньше последовательности $b$, если и только если выполняется один из следующих пунктов:

\begin{itemize}

\item $a$ “--- префикс $b$, но $a \ne b$;

\item в первой позиции, где $a$ и $b$ различны, в последовательности $a$ элемент меньше, чем соответствующий элемент в $b$.

\end{itemize}

Замените $a$ и $b$, если они используются в другом месте в условии!

A sequence $a$ is a subsequence of a sequence $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) elements.

Replace $a$ and $b$ if you use them in some other place of the statement!

Последовательность $a$ является подпоследовательностью $b$, если $a$ может быть получена из $b$ удалением нескольких (возможно, ни одного или всех) элементов.

Замените $a$ и $b$, если они используются в другом месте в условии!

A sequence $a$ is a subsegment of a sequence $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end.

Replace $a$ and $b$ if you use them in some other place of the statement!

Последовательность $a$ является подотрезком $b$, если $a$ может быть получена из $b$ удалением нескольких (возможно, ни одного или всех) элементов из начала и нескольких (возможно, ни одного или всех) элементов из конца.

Замените $a$ и $b$, если они используются в другом месте в условии!

A string $a$ is a substring of a string $b$ if $a$ can be obtained from $b$ by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.

Replace $a$ and $b$ if you use them in some other place of the statement!

Строка $a$ является подстрокой $b$, если $a$ может быть получена из $b$ удалением нескольких (возможно, ни одного или всех) символов из начала и нескольких (возможно, ни одного или всех) символов из конца.

Замените $a$ и $b$, если они используются в другом месте в условии!

A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

Перестановкой длины $n$ является массив, состоящий из $n$ различных целых чисел от $1$ до $n$ в произвольном порядке. Например, $[2,3,1,5,4]$ “--- перестановка, но $[1,2,2]$ не перестановка ($2$ встречается в массиве дважды) и $[1,3,4]$ тоже не перестановка ($n=3$, но в массиве встречается $4$).

After printing a query do not forget to output the end of line and flush the output. Otherwise, you will get \t{Idleness limit exceeded}. To do this, use:

\begin{itemize}

\item \t{fflush(stdout)} or \t{cout.flush()} in C++;

\item \t{System.out.flush()} in Java;

\item \t{flush(output)} in Pascal;

\item \t{stdout.flush()} in Python;

\item see the documentation for other languages.

\end{itemize}

Answer ``\t{***}'' instead of ``\t{***}'' or ``\t{***}'' means that you made an invalid query. Exit immediately after receiving ``\t{***}'' and you will see \t{Wrong answer} verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

Replace the interaction samples in the last paragraph!

После вывода запроса не забудьте вывести перевод строки и сбросить буфер вывода. В противном случае вы получите вердикт \t{Решение <<зависло>>}. Для сброса буфера используйте:

\begin{itemize}

\item \t{fflush(stdout)} или \t{cout.flush()} в C++;

\item \t{System.out.flush()} в Java;

\item \t{flush(output)} в Pascal;

\item \t{stdout.flush()} в Python;

\item смотрите документацию для других языков.

\end{itemize}

Ответ <<\t{***}>> вместо <<\t{***}>> или <<\t{***}>> означает, что ваша программа сделала некорректный запрос. Ваша программа должна немедленно завершиться после прочтения ответа <<\t{***}>>, вы получите вердикт \t{Неправильный ответ}. В противном случае вы можете получить любой вердикт, так как программа продолжит чтение из закрытого потока.

Замените примеры ответов в части про принудительное завершение!

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 100$). The description of the test cases follows.

The first line of each test case contains...

It is guaranteed that the sum of $n$ over all test cases does not exceed...

Каждый тест состоит из нескольких наборов входных данных. В первой строке находится одно целое число $t$ ($1 \le t \le 100$) “--- количество наборов входных данных. Далее следует описание наборов входных данных.

Первая строка каждого набора входных данных содержит…

Гарантируется, что сумма значений $n$ по всем наборам входных данных не превосходит...

example

пример

Smth is as follows. Always singular!

Solutions

General