def arithmetic_arranger(problems, showResult = False):  
  if len(problems)>5:
    return "Error: Too many problems."
  matrix = [["", "", "", ""] for i in problems]
  i=0
  for things in problems:
    x = []
    if "+" in things:
      x = things.split("+")
    elif "-" in things:
      x = things.split("-")
    else:
      return "Error: Operator must be '+' or '-'."
    x0 = x[0].strip()
    x1 = x[1].strip()
    width = max(len(x0), len(x1)) + 2

    if max(len(x0), len(x1) ) > 4:
      return "Error: Numbers cannot be more than four digits."       
    if any(c.isalpha() for c in x0+x1):
      return "Error: Numbers must only contain digits."

    if "+" in things:
      result = str(int(x0) + int(x1))

      matrix[i][1] = "+" + x1.rjust(width - 1, " ")
    if "-" in things:
      result = str(int(x0) - int(x1))
      matrix[i][1] = "-" + x1.rjust(width - 1, " ")

    matrix[i][0] = x0.rjust(width, " ")
    matrix[i][2] = "".rjust(width, "-")
    matrix[i][3] = "".rjust(width, " ")
    if showResult:
      matrix[i][3] = result.rjust(width, " ")
    i += 1
  matrix = [[matrix[j][i] for j in range(len(matrix))] for i in range(len(matrix[0]))]
  resultString = ""
  for i in matrix:
    for j in i:
      resultString += j + " "*4
    resultString = resultString[:-4]
    resultString += '\n'
  resultString = resultString.rstrip()

  return resultString

