MediumLoopsNot started

Longest reading streak

A reading log uses R for a day with reading and - for a missed day. Read the log and print the longest consecutive run of R characters. An all-missed log has a longest run of zero.

Input

One line containing 1 to 200 characters, each either R or -.

Output

One integer: the longest consecutive reading streak.

Example 1

Input

RR-RRR--R

Output

3

The three R characters in the middle form the longest run.

Constraints

  • 1 <= log length <= 200
  • The log contains only R and -

Hints

Hint 1 of 3

Keep one counter for the current run and one for the best run.

Hint 2 of 3

A dash resets only the current run.

Hint 3 of 3

Update best immediately after increasing current.

Solution

Show a reference solution and explanation
 Python · reference solution
log = input().strip()
best = 0
current = 0
for mark in log:
    if mark == "R":
        current += 1
        best = max(best, current)
    else:
        current = 0
print(best)

Why it works

The current counter represents the run ending at the character being inspected. Each missed day breaks that run, while the best counter remembers the largest value seen anywhere in the log.

Lesson for this exercise: Loops in Python: for and while

Your program
log = input().strip()
best = 0
current = 0
# scan the log
print(best)

Tests: 4 cases including the examples. Passing every test marks the exercise solved in this browser.

Ready for a challenge?

How this page was checked. Every program on it was run with CPython 3.11 at build time; runs in your browser on CPython 3.14 (Pyodide) by the publishing checks, and the output shown is what it printed. The Run buttons execute the same code on your device; nothing you type is sent anywhere.