input: from typing import List
  
  
  def count_unique_subarrays(nums: List[int]) -> int:
      """
      Given an array of positive integers nums.
      Calculate the number of subarrays in which the first and the last elements are equal to the maximum element within the subarray.
      
      Parameters:
      nums (List[int]): The input list of positive integers.
      
      Returns:
      int: The count of subarrays satisfying the condition.
      
      Examples:
      >>> count_unique_subarrays([1, 4, 3, 3, 2])
      6
      >>> count_unique_subarrays([3, 3, 3])
      6
      >>> count_unique_subarrays([1])
      1
      """
output:     count = 0
      n = len(nums)
      
      for i in range(n):
          max_elem = nums[i]
          for j in range(i, n):
              if nums[j] > max_elem:
                  max_elem = nums[j]
              if max_elem == nums[i] == nums[j]:
                  count += 1
  
      return count