input: from typing import List
  
  def min_cost_to_partition_array(arr: List[int]) -> int:
      """
      You are given a list of integers arr of length n.
  
      The expense of a list is determined by its initial element. For instance, the expense of [5,2,9] is 5 whereas the expense of [7,1,4] is 7.
  
      Your task is to partition arr into 3 non-overlapping contiguous subarrays.
  
      Return the minimum achievable sum of the expenses of these subarrays.
  
      Examples:
      >>> arr = [1,2,3,12]
      6
      >>> arr = [5,4,3]
      12
      >>> arr = [10,3,1,1]
      12
  
      Constraints:
      3 <= n <= 50
      1 <= arr[i] <= 50
      """
output:     n = len(arr)
      
      # Dynamic programming table
      dp = [[float('inf')] * (n + 1) for _ in range(4)]
      
      # Initial state
      dp[0][0] = 0
      
      for k in range(1, 4):  # For 1 to 3 subarrays
          for i in range(k, n + 1):
              for j in range(i):
                  if k == 3 and j < 2:
                      continue  # Ensure there are enough elements for three subarrays
                  dp[k][i] = min(dp[k][i], dp[k - 1][j] + arr[j])
      
      return dp[3][n]
  
  # Testing the function
  print(min_cost_to_partition_array([1, 2, 3, 12]))  # Expected output: 6
  print(min_cost_to_partition_array([5, 4, 3]))  # Expected output: 12
  print(min_cost_to_partition_array([10, 3, 1, 1]))  # Expected output: 12