You are given a $$$n \times m$$$ board with white or black cells. Each second the board is going to change. For each $$$2 \times 2$$$ square on the previous board, if it doesn't contain two adjacent cells of the same color, all four cells will have their color flipped on the next board. If a cell didn't belong to any of such $$$2 \times 2$$$ squares, its color stays the same. The initial board is in time $$$0$$$. Your task is to answer $$$q$$$ queries. Each query contains one number $$$t$$$ — calculate the number of black cells after $$$t$$$ seconds.
The first line of input contains three integers $$$n$$$, $$$m$$$ and $$$q$$$ ($$$1 \leq n, m \leq 2\,000$$$, $$$1 \leq q \leq 200\,000$$$). The next $$$n$$$ lines contain a description of the board. The $$$i$$$-th of these lines contains a string of length $$$m$$$ representing the $$$i$$$-th row. If $$$j$$$-th letter of the string is '#', then cell (i, j) is black. If it's '.' then it's white. The next $$$q$$$ lines contain descriptions of the following queries. In each line there is one integer $$$t$$$ ($$$1 \leq t \leq 10^9$$$) described above.
Output $$$q$$$ lines. In $$$i$$$-th of these lines print the answer to the $$$i$$$-th query from input.
3 4 2 #.#. ##.# .#.# 1 10
7 6
For a given tree $$$t$$$ of size $$$n$$$, a permutation of length $$$n$$$ is called $$$t$$$-good when there is an edge between nodes $$$i$$$ and $$$j$$$ if and only if there is an edge between nodes $$$p[i]$$$ and $$$p[j]$$$. For a given $$$k$$$, find a tree $$$t$$$ such that there are exactly $$$k$$$ $$$t$$$-good permutations.
The first line of the input contains a single integer $$$k$$$ ($$$2 \leq k \leq 10^{18}$$$).
The first line of the output should contain an integer $$$n$$$ ($$$1 \leq n \leq 400$$$) — size of a tree or $$$-1$$$ if it does not exist.
If the tree exists, the following $$$n - 1$$$ lines each should contain two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$) — the $$$i$$$-th edge of the tree.
2
6 2 1 3 1 4 1 5 4 6 5
You are given a tree with $$$n$$$ vertices. Vertex $$$i$$$ is controlled by mafia $$$m_i$$$. Vertex $$$v$$$ is inside the control area of the $$$i$$$-th mafia iff $$$v$$$ is on the shortest path between any two vertices $$$a$$$ and $$$b$$$ (possibly $$$a = b$$$) controlled by this mafia. Your task is to process $$$q$$$ events of the following two types:
The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 200\,000$$$). The next line contains $$$n$$$ integers $$$m_i$$$ ($$$1 \leq m_i \leq n$$$). The next $$$n - 1$$$ lines describe the edges of the tree. Each of these lines contains two integers $$$v$$$ and $$$u$$$ ($$$1 \leq v, u \leq n$$$) representing an edge between vertices $$$v$$$ and $$$u$$$. The next $$$q$$$ lines describe the events. Each line starts with one integer $$$t$$$ ($$$1 \leq t \leq 2$$$) representing the type of the event. If:
Output one line for each event of type $$$2$$$. The $$$i$$$-th of these lines should contain the answer for the $$$i$$$-th such event from the input.
5 4 1 2 3 1 2 1 2 1 3 3 4 1 5 2 2 5 2 1 4 1 1 2 2 2 3
2 3 2
Let's define a sequence of Gray Codes $$$G_n$$$ as follows:
| 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
The table $$$T_3$$$
Two cells in the table are adjacent if they share a side. The distance between cells $$$(a, b)$$$ and $$$(c, d)$$$, satisfying $$$T_n(a, b) = T_n(c, d) = 1$$$, is defined as the minimal number of moves needed to get from one cell to the other moving only on cells that are $$$1$$$'s. Given $$$n$$$, your task is to calculate the sum of distances between every ordered pair of cells modulo 998 244 353.
The first line of input contains one integer $$$n$$$ ($$$1 \leq n \leq 200\,000$$$).
Print one line containing the answer.
2
20
You are given a sequence $$$a$$$ of length $$$n$$$. Your task is to process $$$q$$$ events of the following $$$4$$$ types:
The first line of input contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n, q \leq 200\,000$$$). The next line contains $$$n$$$ integers — $$$i$$$-th of them represents $$$a_i$$$ ($$$1 \leq a_i \leq 10^9$$$). The next $$$q$$$ lines contain descriptions of events. Each line starts with one number $$$t$$$ ($$$1 \leq t \leq 4$$$) representing the type of the event. If:
Output one line for each query of type $$$3$$$ or $$$4$$$. The $$$i$$$-th of them should contain the answer for the $$$i$$$-th such query from the input.
5 8 1 2 3 2 1 4 5 1 1 1 4 4 3 2 1 2 1 4 4 2 2 3 7 4 1 3 4
3 2 2 4 2
Fibonacci sequence $$$f_i$$$ is defined in the following way: $$$f_0 = f_1 = 1$$$ and for $$$i \gt 1$$$, $$$f_i = f_{i - 1} + f_{i-2}$$$. Given the number $$$k$$$ check if it belongs to the Fibonacci sequence.
The first line of input contains integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — length of the number $$$k$$$. The second line of input contains integer $$$k$$$ of length $$$n$$$.
Print 'YES' (without quotes) if $$$k$$$ belongs to the Fibonacci sequence, and 'NO' (without quotes) otherwise.
3 610
YES
1 7
NO
Initially there are two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$ filled with zeros. You need to process $$$q$$$ updates and queries of the following types:
1. For each $$$i$$$ such, that $$$l \leq i \leq r$$$ set $$$a[i] := a[i] + c$$$ and then set $$$b[i] := \max(b[i], a[i])$$$
2. For each $$$i$$$ such, that $$$l \leq i \leq r$$$ set $$$a[i] := \max(a[i], d)$$$ and then set $$$b[i] := \max(b[i], a[i])$$$
3. Print $$$\max(b[l], b[l + 1], ..., b[r])$$$
The first line of the input contains a integers $$$n, q$$$ ($$$1 \leq n,q \leq 5 \cdot 10^5$$$).
The following $$$q$$$ lines of the input start with $$$1 \leq t_i \leq 3$$$ indicating query / update type.
If $$$t_i = 1$$$ the line contains integers $$$l_i, r_i, c_i$$$, ($$$1 \leq l_i \leq r_i \leq n, |c_i| \leq 10^6$$$).
If $$$t_i = 2$$$ the line contains integers $$$l_i, r_i, d_i$$$, ($$$1 \leq l_i \leq r_i \leq n, |d_i| \leq 10^{12}$$$).
If $$$t_i = 3$$$ the line contains integers $$$l_i, r_i$$$, ($$$1 \leq l_i \leq r_i \leq n$$$).
The $$$i$$$-th line of the output should contain the answer to the $$$i$$$-th type 3 query.
10 8 1 1 10 1 1 1 2 2 3 1 7 1 1 5 -100 3 1 3 2 1 6 100 3 7 8 3 6 9
3 3 1 100
Let's define a sequence of Gray Codes $$$G_n$$$ as follows:
| 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 |
| 0 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
The table $$$T_3$$$
The first line of input contains one integer $$$q$$$ ($$$1 \leq q \leq 10\,000$$$). The next $$$q$$$ lines each contain one number $$$n$$$ ($$$1 \leq n \leq 10^{18}$$$) described above.
Output $$$q$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th query in the input.
3 1 2 3
1 7 32
You are given a graph $$$G$$$ of $$$n$$$ vertices and $$$m$$$ edges. Find any vertex cover (set of vertices such, that no two non-selected vertices are connected by an edge) $$$C$$$ of this graph such that if $$$a \neq b$$$ and $$$a,b \in C$$$ then $$$\gcd(a, b) = 1$$$.
The first line of the input contains two space-separated integers $$$n, m$$$ ($$$1 \leq n,m \leq 5 \cdot 10^5$$$).
The following $$$m$$$ lines each contain two integers $$$u_i, v_i$$$ ($$$1 \leq u_i \lt v_i \leq n$$$) — there is an edge between vertex $$$u_i$$$ and vertex $$$v_i$$$.
It is guaranteed that there exists at least one such cover $$$C$$$.
The first line of the output should contain $$$|C|$$$.
The second line of the output should contain $$$|C|$$$ space separated integers — elements of $$$C$$$.
If there are multiple solutions, print any of them.
5 4 1 2 2 3 3 4 4 5
3 2 3 5
Given two arrays $$$a$$$ and $$$b$$$ of length n consisting of values $$$0, 1, 2, 3$$$ and $$$4$$$ you can do the following operation at most $$$8 \cdot n$$$ times:
Choose an index $$$i$$$ and let $$$a[i] := (a[i - 1] + a[i] + a[i + 1]) \mod 5$$$.
All the operations on indices are modulo $$$n$$$.
Check if it is possible to make both arrays equal.
The first line of the input contains single number $$$n$$$ ($$$5 \leq n \leq 10^5$$$) — the length of both arrays.
The second line contains $$$n$$$ numbers $$$a_0, a_1 ... a_{n - 1}$$$ ($$$0 \leq a_i \leq 4$$$) — elements of an array.
The third line contains analogous description of array $$$b$$$.
If it is not possible to make both arrays equal output $$$-1$$$.
If it is possible to make both arrays equal the first line should contain $$$0 \leq k \leq 8 \cdot n$$$ — the number of operations.
The following $$$k$$$ lines each should contain a single number $$$0 \leq t_i \leq n - 1$$$ — the index chosen in the $$$i$$$-th operation.
5 1 0 0 1 0 1 0 0 1 1
3 4 4 4