output_description: Print `YES` if it is possible to turn S into a palindrome; print `NO` if it is
  impossible.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      S
      N
      L_1 R_1
      L_2 R_2
      :
      L_N R_N
attempt: import sys
  
  readline = sys.stdin.readline
  readlines = sys.stdin.readlines
  sys.setrecursionlimit(10**7)
  
  S = [ord(x) - ord("a") for x in readline().rstrip()]
  N = int(readline())
  LR = (tuple(int(x) - 1 for x in line.split()) for line in readlines())
  
  LS = len(S)
  M = (LS + 1) // 2
  
  # 左側の区間内の反転に帰着
  
  L_to_R = [[] for _ in range(M + 1)]
  for L, R in LR:
      if R <= M:
          pass
      elif M < L:
          L, R = LS - 1 - R, LS - 1 - L
      elif L + R > LS - 1:
          L, R = LS - 1 - R, L - 1
      elif L + R <= LS - 1:
          L, R = L, LS - R - 2
      if L <= R:
          L_to_R[L].append(R)
  
  bl = True
  add = 0
  diff_add = [0] * (LS + 1)
  for L in range(LS // 2):
      add += diff_add[L]
      left = S[L]
      right = S[LS - L - 1]
      arr = sorted(set(L_to_R[L]))
      if len(arr) == 0:
          if (left + add) % 26 != right:
              bl = False
              break
      else:
          R0 = arr[0]
          for R in arr[1:]:
              L_to_R[R0 + 1].append(R)
          n = (right - left - add) % 26
          add += n
          diff_add[R0 + 1] -= n
  
  answer = "YES" if bl else "NO"
  print(answer)
  
problem_description: Statement
  
  Ringo has a string S.
  
  He can perform the following N kinds of operations any number of times in any
  order.
  
    * Operation i: For each of the characters from the L_i-th through the R_i-th characters in S, replace it with its succeeding letter in the English alphabet. (That is, replace `a` with `b`, replace `b` with `c` and so on.) For `z`, we assume that its succeeding letter is `a`.
  
  Ringo loves palindromes and wants to turn S into a palindrome. Determine
  whether this is possible.
samples: [{"input": "bixzja\n    2\n    2 3\n    3 6", "output": "YES\n    \n\nFor example, if we perform Operation 1, 2 and 1 in this order, S changes as\n`bixzja` \u2192 `bjyzja` \u2192 `bjzakb` \u2192 `bkaakb` and becomes a palindrome.\n\n* * *"}, {"input": "abc\n    1\n    2 2", "output": "NO\n    \n\n* * *"}, {"input": "cassert\n    4\n    1 2\n    3 4\n    1 1\n    2 2", "output": "YES"}]