output_description: Print the K-th element.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      K
attempt: a = list(input())
  b = list(input())
  c = list(input())
  A, B, C = map(len, (a, b, c))
  OFFSET = 4000
  L = 8001
  ab = [True] * L
  ac = [True] * L
  bc = [True] * L
  
  for i in range(A):
      for j in range(B):
          if a[i] != b[j] and a[i] != "?" and b[j] != "?":
              ab[i - j + OFFSET] = False  # BをAからi-jずらした時を考える
  
  for i in range(A):
      for j in range(C):
          if a[i] != c[j] and a[i] != "?" and c[j] != "?":
              ac[i - j + OFFSET] = False  # CをAからi-jずらした時を考える
  
  for i in range(B):
      for j in range(C):
          if b[i] != c[j] and c[i] != "?" and b[j] != "?":
              bc[i - j + OFFSET] = False  # CをBからi-jずらした時を考える
  
  ans = float("inf")
  for i in range(L):  # Bの左端をずらす
      for j in range(L):  # Cの左端をずらす
          k = j - i + OFFSET
          if k >= L or k < 0:
              continue
          if ab[i] and ac[j] and bc[k]:
              head = min(i, j, OFFSET)
              tail = max(A + OFFSET, B + i, C + j)
              ans = min(ans, tail - head)
  
  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."}]