Time Limit: 8 sec / Memory Limit: 64 MB Example Input 5 3 2 aaaaa aaa aab Output 1 6
- User
Time Limit: 8 sec / Memory Limit: 64 MB
Example Input
5 3 2 aaaaa aaa aab
Output
1 6
Assistant
def find_all_occurrences(s, substr): n = len(substr) positions = [] for i in range(len(s) - n + 1): if s[i:i+n] == substr: positions.append(i) return positions n, m, k = map(int, input().split()) s = input().strip() t = input().strip() u = input().strip() total_length = m + k if total_length > n: print(0, 0) else: concat1 = t + u concat2 = u + t pos1 = find_all_occurrences(s, concat1) pos2 = find_all_occurrences(s, concat2) count1 = len(pos1) count2 = len(pos2) max_count = max(count1, count2) if max_count == 0: print(0, 0) else: sum_pos = 0 if count1 == max_count: sum_pos += sum(pos1) if count2 == max_count: sum_pos += sum(pos2) print(max_count, sum_pos)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.