Roy is going through the dark times of his life. Recently his girl friend broke up with him and to overcome the pain of acute misery he decided to restrict himself to Eat-Sleep-Code life cycle. For N days he did nothing but eat, sleep and code.
A close friend of Roy kept an eye on him for last N days. For every single minute of the day, he kept track of Roy's actions and prepared a log file.
The log file contains exactly N lines, each line contains a string of length 1440 ( i.e. number of minutes in 24 hours of the day).
The string is made of characters E, S, and C only; representing Eat, Sleep and Code respectively. i^th character of the string represents what Roy was doing during i^th minute of the day.
Roy's friend is now interested in finding out the maximum of longest coding streak of the day - X.
He also wants to find the longest coding streak of N days - Y.
Coding streak means number of C's without any E or S in between.
See sample test case for clarification.
Input:
First line of each file contains N - number of days.
Following N lines contains a string of exactly 1440 length representing his activity on that day.
Output:
Print X and Y separated by a space in a single line.
Constraints:
1 ≤ N ≤ 365
String consists of characters E, S, and C only.
String length is exactly 1440.
Note: The sample test case does not follow the given constraints on string length to avoid large data. It is meant only for explanation. We assure you that the hidden test files strictly follow the constraints.
Longest coding streak for each day is as follows:
Day 1: 4
Day 2: 5
Day 3: 7
Day 4: 6
Maximum of these is 7, hence X is 7.
Now in order to find longest coding streak of the all days, we should also check if Roy continued his coding from previous days.
As in the sample test case, Roy was coding for 4 minutes at the end of Day 1 and he continued to code till 5 more minutes on Day 2. Hence the longest coding streak is 4+5 equals 9. There is no any other coding streak larger than this. So the longest coding streak of all days is 9.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to read input: first line N, then N strings each of length 1440 (but sample uses shorter for explanation). For each day, we need to compute the longest consecutive run of 'C' within that day (call streak_day). Then X = max over days of streak_day.
Also we need Y = longest coding streak across all days, meaning we consider that coding can continue across days if it ends at the end of one day and starts at the beginning of the next day. Since days are consecutive, we need to compute the maximum total length of consecutive C's that spans across days. Specifically, if a day ends with a streak of C's (i.e., suffix of C's) and the next day starts with a streak of C's (i.e., prefix of C's), then these can be combined. So we need to compute the maximum total length of consecutive C's in the concatenated sequence of days, considering day boundaries.
We can treat it as a continuous timeline of minutes across days. Since each day has exactly 1440 minutes, we could combine all strings and compute longest run of C's. But careful: There might be no break across days? Actually, we treat minutes as contiguous: minute 1440 of day1 is followed by minute 1 of day2, etc. So if day1 ends with some C's and day2 starts with some C's, then those combine into a longer streak. So the longest coding streak overall Y is simply the longest run of consecutive 'C's across the entire concatenated string of all days, i.e., if we join all strings one after another. But we must be careful: Is there any gap between days? No, because it's just minutes of consecutive days. So yes, we can simply concatenate all strings (since each is exactly 1440 characters) and compute the longest run of C's. However, note the constraints: N up to 365, each string length 1440 => total length up to 525,600 (~0.5 million), which is fine.
But there's a nuance: The problem might ask for Y as the longest streak of consecutive minutes of coding across the entire period, potentially spanning multiple days. That is exactly the longest run in the concatenated string. However, we need to also compute X as maximum within any day, which we can get as we process each day.
Thus straightforward solution: read N, then for each day compute:
longest streak in that day: we can loop through characters, count consecutive C's, track max. Also track prefix length: the number of consecutive C's from start of the string; suffix length: the number of consecutive C's at the end. Why track prefix/suffix? Not needed for X but could be used for Y if we want to combine without full concatenation. But we can just concatenate and compute. However, concatenating all strings into one big string might be memory-intensive but okay: 525,600 chars is about 0.5 MB, trivial.
But careful: input sample shows strings may have newline after each line. We'll read normally. So we can read all strings into a list, then combine.
Alternatively, we could process streaming: keep track of current run length across days, resetting on non-C. But must handle boundary: when day ends with C and next day starts with C, the run continues. So we can process sequentially: maintain current run length, and max overall Y. Also track each day's max for X. But careful: to know if current run continues from previous day, we need to know if previous day ended with C. So we can compute suffix length of previous day to connect, but simpler is to just process the concatenated string char by char.
Implementation plan:
Read integer N.
Initialize full_string = "" (or maybe list of strings, then later join).
For each day i in range(N):
line = input().strip()
Validate length? But problem says exactly 1440; sample is shorter for explanation. We can trust hidden test. Add to full_string.
Alternatively, to reduce memory (not needed), we can compute on the fly: keep current run length that spans days. To do that, we need to know if the previous day ended with C and the length of the trailing C's? Actually if we process day by day, we can compute:
For each day, compute:
longest streak within day: day_max.
prefix: number of C's at start until first non-C.
suffix: number of C's at end.
Also we want Y = longest consecutive C's across boundaries. This can be computed by scanning days in order, maintaining a "current ongoing streak" that might span days. However, there may be cases where a long streak includes middle of days, not necessarily starting at beginning of a day. The longest streak across days could be a combination of suffix of day i and prefix of day i+1. But could also include entire day i and part of day i+1 etc. But we can compute Y by considering all such connections: For each adjacent pair, we can compute suffix_i + prefix_{i+1} as a candidate for a streak that crosses that boundary. However, what if a streak spans more than two days? That would be a combination of suffix of day i, entire day(s) in between that are all C (i.e., day with all C's), and prefix of day j. So we need to compute the longest contiguous sequence of C's in the concatenated sequence. This can be done by scanning all characters. Since total characters is small, easiest is to concatenate.
But if we want to avoid concatenation, we could simulate scanning across days using a state machine: maintain current streak length across days, and update max. When we finish a day, we note its suffix length; if the day ends with C, the current streak continues into next day. But we need to know how to start next day: if the previous day ended with C, then we need to add the prefix of the next day to the current streak. However, careful: The streak might not start at the beginning of the previous day; it could have started in the middle of that day. So the current streak we are tracking while scanning the concatenated string is exactly that: we process characters sequentially. To simulate without concatenation, we can loop over days and for each day, iterate over its characters, updating current streak and max overall. This is essentially the same as concatenation but without building one big string. This is even more efficient: just read each string and iterate through its characters. Keep a variable current_streak = 0. For each character c in each string (in order of days), if c == 'C', increment current_streak and update max_overall = max(max_overall, current_streak). Else (E or S), reset current_streak = 0. This yields Y. Also for X, we need per day max. So for each day, we also compute day_max using a separate counter, and after processing day, update X = max(X, day_max). That's it.
But wait: There's a catch: Suppose day1 ends with C, we finish day1 with current_streak = some value (the suffix length). Then when we start day2, we continue with the same current_streak, and as we process day2 characters, we keep counting C's. This works because we process characters sequentially across days. So yes, we can just treat it as a continuous stream. So we can compute everything in one pass.
Thus algorithm:
Initialize:
X = 0
Y = 0
current_streak = 0
Loop for each day i = 1..N:
read line (string s)
day_max = 0
day_streak = 0
for each character ch in s:
if ch == 'C':
current_streak += 1
day_streak += 1
if current_streak > Y: Y = current_streak
if day_streak > day_max: day_max = day_streak
else:
current_streak = 0
day_streak = 0
# after day done
if day_max > X: X = day_max
Print X and Y
Check sample: Input lines as given (though sample lines are not 1440). Let's simulate sample:
Day1: "SSSSEEEECCCCEECCCC"
Processing:
Initially current_streak=0, day_streak=0, day_max=0, Y=0.
S,S,S,S: all non-C => reset to 0 (but already 0). So no updates.
E,E,E,E: same.
C,C,C,C: streak builds: after first C: current_streak=1, day_streak=1 -> Y=1, day_max=1; after second: 2,2 -> Y=2, day_max=2; after third:3,3->Y=3, day_max=3; after fourth:4,4->Y=4,day_max=4.
Then E,E: resets current_streak=0, day_streak=0.
Then C,C,C,C: current_streak becomes 1,2,3,4; day_streak 1,2,3,4; Y=4 (since 4 not >4), day_max remains 4? Actually day_max updates to 4 again? But day_max remains 4 (since max is 4). So day_max=4.
So day1 max=4. After day1, current_streak=4 (since ended with C's). So continuing streak =4.
Day2: "CCCCCSSSSEEECCCCSS"
Process chars:
C: current_streak=5, day_streak=1 => Y=5, day_max=1
C: 6,2 => Y=6, day_max=2
C:7,3=>Y=7,day_max=3
C:8,4=>Y=8,day_max=4
C:9,5=>Y=9,day_max=5
S: reset -> current_streak=0, day_streak=0
S,S,S: resets.
E,E,E: resets.
C,C,C,C: C: current_streak=1, day_streak=1 => Y=9 (1<9), day_max stays 5? Actually day_max becomes max(5,1)=5; second C:2; third:3; fourth:4; day_max remains5.
S,S: reset.
End of day2: day_max=5 (since max within day2: first streak of 5 and later 4, max=5). After day2, current_streak=0? Actually last char is S, so current_streak=0. So no carryover.
Day3: "SSSSSEEESSCCCCCCCS"
Process:
S,S,S,S,S: resets.
E,E,E: resets.
S,S: resets? Actually char after E is S? Actually string: "SSSSSEEESSCCCCCCCS". Let's parse: after "SSSSSEEESS" then "CCCCCCCS"? Wait maybe not needed. We'll compute.
But sample's day3 max=7, as per description.
At end day3, current_streak? Last char is S, so reset to 0.
Day4: "EESSSSCCCCCCSSEEEE" (actually sample says "EESSSSCCCCCCSSEEEE"? The input line: "EESSSSCCCCCCSSEEEESAMPLE"? That seems like they truncated the sample for explanation. In the problem statement, sample input is:
4
SSSSEEEECCCCEECCCC
CCCCCSSSSEEECCCCSS
SSSSSEEESSCCCCCCCS
EESSSSCCCCCCSSEEEESAMPLE OUTPUT
But it's messy: The last line likely is "EESSSSCCCCCCSSEEEE"? Actually the description says "Day 4: 6". So day4 has max 6. Also sample output: 7 9. So we'll trust the algorithm.
Our algorithm would produce X = max of day_max = 7, Y = max overall streak: from sample, we got Y=9 (from combination day1 suffix 4 and day2 prefix 5). At day2 first 5 C's, current_streak grew from 4 to 9, so Y=9. Good.
Thus algorithm works.
Edge cases: What if N=0? Not possible (N>=1). Also strings may be exactly 1440 length. All good.
Complexity: O(N*1440) which is at most ~525,600 iterations, trivial.
One nuance: Input reading. Since lines are exactly 1440 characters, we must ensure we read the entire line including possible newline, but .strip() will remove whitespace but also any trailing spaces? It shouldn't have spaces. Using .strip() might remove leading/trailing whitespace, but the string should consist of only 'C','E','S'. However, if there is a newline, .strip() would remove it, but also if the line itself has spaces? No. But careful: If the line is exactly 1440 characters, using .strip() will remove any trailing newline, but it will not affect the characters if there are no leading/trailing spaces. However, if the line contains spaces? No. So .strip() is safe. Alternatively, we could use input() directly; input() returns the line without trailing newline, so that's fine. But if the line might have extra spaces? Unlikely. So we can just s = input().strip().
But to be safe, we can just s = input() since input() strips newline automatically. However, if there is a blank line? No.
Thus implement.
We also need to be careful about large input reading speed; but it's small.
Let's write code in Python:
def solve():
import sys
data = sys.stdin.read().splitlines()
if not data: return
N = int(data[0].strip())
X = 0
Y = 0
current_streak = 0
idx = 1
for i in range(N):
if idx >= len(data):
break # but shouldn't happen
s = data[idx].strip()
idx += 1
# If there is any possibility that blank lines exist, skip? We'll assume not.
# Optionally ensure length; but not needed.
day_streak = 0
day_max = 0
for ch in s:
if ch == 'C':
current_streak += 1
day_streak += 1
if current_streak > Y:
Y = current_streak
if day_streak > day_max:
day_max = day_streak
else:
current_streak = 0
day_streak = 0
if day_max > X:
X = day_max
print(X, Y)
But careful: Using sys.stdin.read().splitlines() might be fine. However, if lines are huge, it's still fine. Alternative: use sys.stdin.readline in loop.
Simplify: Use sys.stdin.readline.
Pseudo:
import sys
def main():
input = sys.stdin.readline
N_line = input()
if not N_line:
return
N = int(N_line.strip())
X = 0
Y = 0
cur = 0
for _ in range(N):
s = input().strip()
day_streak = 0
day_max = 0
for ch in s:
if ch == 'C':
cur += 1
day_streak += 1
if cur > Y:
Y = cur
if day_streak > day_max:
day_max = day_streak
else:
cur = 0
day_streak = 0
if day_max > X:
X = day_max
print(X, Y)
if name == "main":
main()
Check sample: We need to ensure the sample input is read correctly. In the sample input, the last line "EESSSSCCCCCCSSEEEESAMPLE OUTPUT" is actually truncated? Actually in problem statement sample, they have:
But likely the last line is "EESSSSCCCCCCSSEEEE"? Because "SAMPLE OUTPUT" is probably part of the problem description, not the input. So the real sample input would be:
But they appended "SAMPLE OUTPUT" to indicate the output line, not part of input. So ignore.
Thus code should work.
Now consider edge cases: All days are all C's. Then for N days, Y = N1440, X = 1440. Our algorithm would maintain current_streak across all characters, Y updates to N1440, correct.
If a day ends with C and next day starts with C, we combine, as tested.
If there are leading/trailing whitespace, .strip() might remove needed C's? But not possible because strings consist of only E,S,C and no spaces. So .strip() is safe. However, if the string has no trailing newline, input().strip() returns the whole string. Good.
Thus solution is straightforward.
But wait: There's a potential nuance: The longest coding streak across all days might be measured in terms of minutes across days, but are days considered continuous? Yes, based on description: "we should also check if Roy continued his coding from previous days." So the concatenation is correct.
Thus final answer.
We'll produce Python code.
But note: The problem might have large N up to 365, each string length 1440, so total characters ~525k, which is fine.
We'll provide solution.
Now produce final response: explanation and code.
```python
import sys
def solve() -> None:
input = sys.stdin.readline
N_line = input()
if not N_line:
return
N = int(N_line.strip())
code
X = 0 # max intra‑day streak
Y = 0 # max overall streak (over all minutes)
cur = 0 # current running streak of C's across days
for _ in range(N):
s = input().strip()
day_streak = 0
day_max = 0
for ch in s:
if ch == 'C':
cur += 1
day_streak += 1
if cur > Y:
Y = cur
if day_streak > day_max:
day_max = day_streak
else:
cur = 0
day_streak = 0
if day_max > X:
X = day_max
print(X, Y)