input: def tribonacci_sequence(n):
      """The Tribonacci sequence is an interesting numerical series, not as widely known 
      as the Fibonacci sequence, but intriguing nonetheless. It's defined by these rules:
      tribonacci_sequence(1) = 3
      tribonacci_sequence(n) = 1 + n / 2, when n is even.
      tribonacci_sequence(n) = tribonacci_sequence(n - 1) + tribonacci_sequence(n - 2) + tribonacci_sequence(n + 1), when n is odd.
      For example:
      tribonacci_sequence(2) = 1 + (2 / 2) = 2
      tribonacci_sequence(4) = 3
      tribonacci_sequence(3) = tribonacci_sequence(2) + tribonacci_sequence(1) + tribonacci_sequence(4)
                              = 2 + 3 + 3 = 8 
      Given a non-negative integer n, the task is to return a list containing the sequence's 
      first n + 1 elements.
      Example:
      tribonacci_sequence(3) = [1, 3, 2, 8]
      """
output:     
      if n == 0:
          return [1]
      
      sequence = [0] * (n + 1)
      sequence[0] = 1
      
      for i in range(1, n + 1):
          if i == 1:
              sequence[i] = 3
          elif i % 2 == 0:
              sequence[i] = 1 + i / 2
          else:
              if i - 2 < 0 or i + 1 >= len(sequence):
                  # Assume out-of-bounds entries as 0 for simplicity
                  sequence[i - 2] = 0 
                  sequence[i + 1] = 0
              sequence[i] = sequence[i - 1] + sequence[i - 2] + 3
      
      return sequence
  