trajectory_sampled_h_from_sampled_len
list | sampled_len_from_5
int64 | sampled_h_from_sampled_len
int64 |
---|---|---|
[
{
"content": "Write Python code to solve the task:\nMike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. \n\nA palindrome is a string that reads the same backward as forward, for example strings \"z\", \"aaa\", \"aba\", \"abccba\" are palindromes, but strings \"codeforces\", \"reality\", \"ab\" are not.\n\nInput\n\nThe first and single line contains string s (1 ≤ |s| ≤ 15).\n\nOutput\n\nPrint \"YES\" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or \"NO\" (without quotes) otherwise. \n\nExamples\n\nInput\n\nabccaa\n\n\nOutput\n\nYES\n\n\nInput\n\nabbcca\n\n\nOutput\n\nNO\n\n\nInput\n\nabcda\n\n\nOutput\n\nYES",
"role": "user"
},
{
"content": "Here's a Python solution for the problem:\n\n```python\ndef is_palindrome(s):\n \"\"\"\n Returns True if the string is a palindrome, False otherwise.\n \"\"\"\n return s == s[::-1]\n\ndef can_change_to_palindrome(s):\n \"\"\"\n Returns True if there is exactly one character that can be changed to make the string a palindrome,\n False otherwise.\n \"\"\"\n char_count = {}\n for char in s:\n if char in char_count:\n char_count[char] += 1\n else:\n char_count[char] = 1\n\n for key, value in char_count.items():\n if value > 1:\n return False\n return True\n\ndef can_change(s):\n \"\"\"\n Returns True if there is exactly one character that can change to make the string a palindrome, False otherwise.\n \"\"\"\n return can_change_to_palindrome(s) and 'a' not in s\n\n# Get input string from user\ns = input()\n\n# Check if s can be changed to palindrome\nif can_change(s):\n print(\"YES\")\nelse:\n print(\"NO\")\n```\n\nThis code defines three helper functions:\n\n- is_palindrome checks if the string is a palindrome.\n- can_change_to_palindrome checks if it is possible to change the string to a palindrome by changing exactly one character.\n- can_change checks if there is exactly one character that can change to make the string a palindrome.\n\nThe main function gets the input string from the user, calls can_change_to_palindrome and can_change, and prints the result.",
"role": "assistant"
}
] | 4 | 0 |