Four paths
Limits: 2 sec., 512 MiB
This statement was translated automatically from Ukrainian.
There is a rectangular table with \(n\) rows and \(m\) columns.
Initially, a token is placed in the top-left cell of the table. In one move, the token can be moved one cell to the right, if the token is not in the last column, or one cell down, if it is not in the last row. The token ends its path in the bottom-right cell of the table.
The path of the token can be represented as a string of letters
R and D, where R denotes a move
to the right, and D — down.
You are given four strings of length \(k\) that specify the paths of the token from the top-left to the bottom-right cell of the table.
Find the dimensions of the table \(n\) and \(m\).
Input
The first line contains an integer \(k\) — the length of the strings.
The next four lines contain \(s_i\) — the paths of the token.
Output
In a single line, print any pair of integers \(n\) and \(m\) that could be equal to the number of rows and columns of the table, such that all token paths start at the top-left cell of the table and end at the bottom-right cell of the table.
Constraints
\(1 \le k \le 1000\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 7 DRRDRRR DRRRRRD RDRRRDR RRDDRRR | 3 6 |
Notes
There is always at least one pair \(n\) and \(m\) that satisfies the condition.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|