output_description: If we cannot turn S into a palindrome, print `-1`. Otherwise, print the
  minimum required number of operations.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      S
attempt: import string
  
  
  def main():
      l = list(input())
      N = len(l)
      count = 0
      flag = True
      middle_letter = None
      i = 0
      dic = {i: l.count(i) for i in string.ascii_lowercase}
      while i <= N >> 1:
          if l[i] != l[N - i - 1]:
              if dic[l[i]] % 2 and N % 2:
                  if flag:
                      middle_letter = l[i]
                      tar_index = N >> 1
                      f_index = i
                      count += tar_index - f_index
                      l[f_index:tar_index] = l[f_index + 1 : tar_index + 1]
                      l[tar_index] = middle_letter
                      flag = False
                  elif not flag and l[i] == middle_letter:
                      pos = list(reversed(l)).index(l[i], i, N - i)
                      temp = l[i]
                      tar_index = N - 1 - i
                      f_index = N - pos - 1
                      count += tar_index - f_index
                      l[f_index:tar_index] = l[f_index + 1 : tar_index + 1]
                      l[tar_index] = temp
                      i += 1
                  else:
                      print(-1)
                      exit()
              else:
                  pos = list(reversed(l)).index(l[i], i, N - i)
                  temp = l[i]
                  tar_index = N - 1 - i
                  f_index = N - pos - 1
                  count += tar_index - f_index
                  l[f_index:tar_index] = l[f_index + 1 : tar_index + 1]
                  l[tar_index] = temp
                  i += 1
          else:
              i += 1
      print(count)
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  You are given a string S consisting of lowercase English letters. Determine
  whether we can turn S into a palindrome by repeating the operation of swapping
  two adjacent characters. If it is possible, find the minimum required number
  of operations.
samples: [{"input": "eel", "output": "1\n    \n\nWe can turn S into a palindrome by the following operation:\n\n  * Swap the 2-nd and 3-rd characters. S is now `ele`.\n\n* * *"}, {"input": "ataatmma", "output": "4\n    \n\nWe can turn S into a palindrome by the following operation:\n\n  * Swap the 5-th and 6-th characters. S is now `ataamtma`.\n  * Swap the 4-th and 5-th characters. S is now `atamatma`.\n  * Swap the 3-rd and 4-th characters. S is now `atmaatma`.\n  * Swap the 2-nd and 3-rd characters. S is now `amtaatma`.\n\n* * *"}, {"input": "snuke", "output": "-1\n    \n\nWe cannot turn S into a palindrome."}]