Author: NemanjaSo2005

**Hint 1**

Assume that cells $$$i-1$$$, $$$i$$$ and $$$i+1$$$ are covered in water. What happens if you remove water from cell $$$i$$$?

**Hint 2**

The water at position $$$i$$$ is replaced as both cells $$$i-1$$$ and $$$i+1$$$ have water in them.

**Solution**

Read the hints.

If there are 3 consecutive empty cells $$$i-1$$$, $$$i$$$, $$$i+1$$$, we can place water in cells $$$i-1$$$ and $$$i+1$$$ and then move water from cell $$$i$$$ to all other cells. If there are no such cells, we have to place water on every empty cell.

So if we find substring ''...'' in the array, the answer is $$$2$$$, otherwise the answer is the number of empty cells.

Author: NemanjaSo2005

**Hint 1**

Check if only digits $$$1$$$ can remain. The situation is similar for checking if only digits $$$2$$$ or only digits $$$3$$$ can remain.

**Hint 2**

Try to find something that stays the same after each operation.

**Hint 3**

Look at the parity of the numbers.

**Hint 4**

The parity of each number changes after an operation. That means that if $$$2$$$ numbers have the same parity, they will always have the same parity. If they had different parity, their parities stay different.

**Solution**

Read the hints.

If the parity of $$$b$$$ and $$$c$$$ is not the same, then it is impossible for only digits $$$1$$$ to remain on the board, as it would require $$$b = c = 0$$$. Otherwise, the following construction will leave only digits $$$1$$$ on the board.

First remove digits $$$2$$$ and $$$3$$$ and write digit $$$1$$$ while $$$b>0$$$ and $$$c>0$$$. If $$$b=c$$$, then we are done. Otherwise, without loss of generality assume $$$b>c$$$. That means that after the operations $$$c=0$$$ and $$$b$$$ is even (Because $$$b$$$ and $$$c$$$ are the same parity). Now we perform the following $$$2$$$ operations $$$\frac{b}{2}$$$ times to get only digits $$$1$$$ left. Remove digits $$$1$$$ and $$$2$$$ and add digit $$$3$$$. After that remove digits $$$2$$$ and $$$3$$$ and add digit $$$1$$$. An effective change of these $$$2$$$ operations is the reduction of $$$b$$$ by $$$2$$$.

1900C - Аньи и двоичное дерево

**Hint 1**

Solve the problem if all of the characters on vertices are 'U'.

**Hint 2**

We can run DFS from the root. Using it we can calculate the number of vertices that we have to traverse to get to every edge. Just output the smallest value among all the leaves.

**Hint 3**

Modify the DFS such that it takes into account that traversing some edges does not require an operation.

**Hint 4**

Add weights to the edges.

**Solution**

Read the hints.

We will make edges from a vertex to its children. The weight of that edge will be $$$1$$$, unless one of the following holds:

The weight of an edge between a vertex and its left child will be $$$0$$$ if the letter written on that vertex is 'L'.

The weight of an edge between a vertex and its right child will be $$$0$$$ if the letter written on that vertex is 'R'.

Now we run a modified DFS to find the distance of each vertex from the root, but with weighted edges. We output the minimal value among all the leaves.