Bessie is playing a Geometry Dash level that takes place on an infinite 2D grid. The level contains $$$n$$$ objects, with no two at the same position. Bessie starts and ends the level at the first object, which is always a green orb.
Bessie always faces one of the four cardinal directions: up, down, left or right. At the end of every second, she moves exactly one unit in her current direction.
There are three types of objects. When Bessie enters a cell containing an object, her direction may change based on the object type:
If Bessie enters a cell without an object, she continues moving in her current direction. Bessie can visit a cell any number of times.
Help Bessie determine the maximum number of distinct cells she can visit such that she starts and ends at the first object, or output $$$0$$$ if she can never return to the first object.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. For each test case:
The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$), the number of objects.
Each of the next $$$n$$$ lines describes an object:
The characters U, L, D, and R represent the directions up, left, down, and right respectively.
For each test case, it is guaranteed that all $$$(x, y)$$$ are distinct and $$$|x|, |y| \le 10^9$$$. The first object is always a green orb.
The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
—–
Tests in subtasks are numbered from $$$1−20$$$ with samples skipped. Each test is worth $$$\frac{100}{20}=5$$$ points.
Tests $$$1-4$$$ have an answer that is at most $$$25$$$.
Tests $$$5-20$$$ satisfy no additional constraints.
Output a single integer — the maximum number of distinct cells Bessie can visit and return to the starting cell, or $$$0$$$ is she cannot return.
291 0 01 -1 -11 -1 11 1 -12 -1 03 0 -1 R3 1 0 L3 0 1 L3 1 1 D11 1 1
50
—
Problem Idea: AksLolCoding
Problem Preparation: AksLolCoding
Occurrences: Novice I, Advanced E