output_description: If Snuke can make the grid symmetric, print `YES`; if he cannot, print `NO`.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      H W
      S_1
      S_2
      :
      S_H
attempt: H, W = map(int, input().split())
  S = [list(input()) for i in range(H)]
  TH = [sorted(S[i]) for i in range(H)]
  PH = [-1 for i in range(H)]
  TW = [sorted([S[i][j] for i in range(H)]) for j in range(W)]
  PW = [-1 for j in range(W)]
  # 0<=i<H,0<=j<W
  for i in range(H):
      if PH[i] != -1:
          continue
      else:
          for k in range(H):
              if k == i:
                  continue
              if TH[k] == TH[i]:
                  PH[i] = k
                  PH[k] = i
                  break
  for j in range(W):
      if PW[j] != -1:
          continue
      else:
          for k in range(W):
              if k == j:
                  continue
              if TW[k] == TW[j]:
                  PW[j] = k
                  PW[k] = j
                  break
  if H % 2 == 0:
      for i in range(H):
          if PH[i] == -1:
              print("NO")
              exit()
  else:
      if PH.count(-1) >= 2:
          print("NO")
          exit()
  if W % 2 == 0:
      for i in range(W):
          if PW[i] == -1:
              print("NO")
              exit()
  else:
      if PW.count(-1) >= 2:
          print("NO")
          exit()
  # usedcheck
  QH = [0 for i in range(H)]
  QW = [0 for j in range(W)]
  RH = []
  RW = []
  SH = [-1 for i in range(H)]
  SW = [-1 for j in range(W)]
  for i in range(H):
      if QH[i] == 0:
          if PH[i] == -1:
              SH[H // 2] = i
              continue
          RH.append((i, PH[i]))
          QH[i] = 1
          QH[PH[i]] = 1
  for j in range(W):
      if QW[j] == 0:
          if PW[j] == -1:
              SW[W // 2] = j
              continue
          RW.append((j, PW[j]))
          QW[j] = 1
          QW[PW[j]] = 1
  for i in range(H // 2):
      SH[i] = RH[i][0]
      SH[H - 1 - i] = RH[i][1]
  for j in range(W // 2):
      SW[j] = RW[j][0]
      SW[W - 1 - j] = RW[j][1]
  """
  XH=sorted(SH)
  XW=sorted(SW)
  for i in range(H):
      if i!=XH[i]:
          print("NO")
          exit()
  for j in range(W):
      if j!=XW[j]:
          print("NO")
          exit()
  """
  U = [[S[SH[i]][SW[j]] for j in range(W)] for i in range(H)]
  for i in range(H):
      for j in range(W):
          if U[i][j] != U[H - 1 - i][W - 1 - j]:
              print("NO")
              exit()
  print("YES")
  
problem_description: Statement
  
  There is an H \times W grid (H vertical, W horizontal), where each square
  contains a lowercase English letter. Specifically, the letter in the square at
  the i-th row and j-th column is equal to the j-th character in the string S_i.
  
  Snuke can apply the following operation to this grid any number of times:
  
    * Choose two different rows and swap them. Or, choose two different columns and swap them.
  
  Snuke wants this grid to be _symmetric_. That is, for any 1 \leq i \leq H and
  1 \leq j \leq W, the letter in the square at the i-th row and j-th column and
  the letter in the square at the (H + 1 - i)-th row and (W + 1 - j)-th column
  should be equal.
  
  Determine if Snuke can achieve this objective.
samples: [{"input": "2 3\n    arc\n    rac", "output": "YES\n    \n\nIf the second and third columns from the left are swapped, the grid becomes\nsymmetric, as shown in the image below:\n\n![](https://img.atcoder.jp/arc095/2b61caf45e7c5c7311e3944f3418b0bb.png)\n\n* * *"}, {"input": "3 7\n    atcoder\n    regular\n    contest", "output": "NO\n    \n\n* * *"}, {"input": "12 12\n    bimonigaloaf\n    faurwlkbleht\n    dexwimqxzxbb\n    lxdgyoifcxid\n    ydxiliocfdgx\n    nfoabgilamoi\n    ibxbdqmzxxwe\n    pqirylfrcrnf\n    wtehfkllbura\n    yfrnpflcrirq\n    wvcclwgiubrk\n    lkbrwgwuiccv", "output": "YES"}]