output_description: Print the K-th element.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      K
attempt: a = input()
  a_l = len(a)
  b = input()
  b_l = len(b)
  c = input()
  c_l = len(c)
  
  
  def check(s1, s2):
      l1 = len(s1)
      l2 = len(s2)
      ret = [0] * (l1 + l2 - 1)
      for i in range(l1 + l2 - 1):
          flag = True
          if i - l2 + 1 < 0:
              for j in range(i + 1):
                  if (
                      s1[j] != "?"
                      and s2[l2 - i + j - 1] != "?"
                      and s1[j] != s2[l2 - i + j - 1]
                  ):
                      flag = False
                      break
          elif i - l2 + 1 >= 0 and i <= l1 - 1:
              for j in range(l2):
                  if (
                      s1[i - l2 + j + 1] != "?"
                      and s2[j] != "?"
                      and s1[i - l2 + j + 1] != s2[j]
                  ):
                      flag = False
                      break
          else:
              for j in range(l1 + l2 - i - 1):
                  if (
                      s1[i - l2 + j + 1] != "?"
                      and s2[j] != "?"
                      and s1[i - l2 + j + 1] != s2[j]
                  ):
                      flag = False
                      break
          ret[i] = flag
      return ret
  
  
  ab = check(a, b)
  ab_l = len(ab)
  ac = check(a, c)
  ac_l = len(ac)
  bc = check(b, c)
  bc_l = len(bc)
  ans = a_l + b_l + c_l
  for i in range(-3000, ab_l + 3000):
      if i < 0 or i >= ab_l or ab[i]:
          for j in range(-3000, ac_l + 3000):
              if j < 0 or j >= ac_l or ac[j]:
                  if (
                      (0 <= j - i + b_l + 1 < bc_l and bc[j - i + b_l + 1])
                      or j - i + b_l + 1 < 0
                      or j - i + b_l + 1 >= bc_l
                  ):
                      l = max(a_l - 1, i, j) - min(0, i - b_l + 1, j - c_l + 1) + 1
                      ans = min(ans, l)
  print(ans)
  
problem_description: Statement
  
  Print the K-th element of the following sequence of length 32:
  
      
      
      1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
samples: [{"input": "6", "output": "2\n    \n\nThe 6-th element is 2.\n\n* * *"}, {"input": "27", "output": "5\n    \n\nThe 27-th element is 5."}]