Time Limit: 8 sec / Memory Limit: 64 MB Example Input eggchickenegg Output egg
- User
Time Limit: 8 sec / Memory Limit: 64 MB
Example Input
eggchickenegg
Output
egg
Assistant
pythondef longest_palindromic_substring(s): if not s: return "" n = len(s) start = 0 max_length = 1 # The minimum possible palindrome is a single character for i in range(n): # Check for odd length palindromes left, right = i, i while left >= 0 and right < n and s[left] == s[right]: current_length = right - left + 1 if current_length > max_length: max_length = current_length start = left left -= 1 right += 1 # Check for even length palindromes left, right = i, i + 1 while left >= 0 and right < n and s[left] == s[right]: current_length = right - left + 1 if current_length > max_length: max_length = current_length start = left left -= 1 right += 1 return s[start:start + max_length] # Read input s = input().strip() # Find and print the longest palindromic substring print(longest_palindromic_substring(s))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.