#K52332. Longest Continuous Upward Sequence

    ID: 29286 Type: Default 1000ms 256MiB

Longest Continuous Upward Sequence

Longest Continuous Upward Sequence

You are given a sequence of moves represented by the characters 'U', 'D', 'L', and 'R'. Each move is provided on a separate line. Your task is to find the length of the longest continuous subsequence of moves that are 'U'.

This problem can be expressed mathematically as follows:

Let the sequence of moves be \(S = s_1, s_2, \dots, s_n\). Define \(L(i)\) as the length of the consecutive 'U's starting at position \(i\). Then the answer is:

[ \max_{1 \le i \le n} L(i) ]

If there is no 'U' in the sequence, the answer is 0.

inputFormat

The input is given via standard input (stdin). The first line contains an integer (n) which represents the number of moves. The following (n) lines each contain a single character which is one of 'U', 'D', 'L', or 'R'.

outputFormat

Output a single integer to standard output (stdout) which is the length of the longest continuous sequence of 'U'.## sample

8
U
U
D
U
U
U
D
U
3