input: 
  from typing import List
  from collections import Counter
  
  def max_length_of_subset(nums: List[int]) -> int:
      """
      Given a list of positive integers, find the largest subset that can be arranged in a specific pattern.
  
      The pattern for the selected subset must be in the form of: [x, x2, x4, ..., xk/2, xk, xk/2, ..., x4, x2, x], where k is any non-negative power of 2. 
      Examples that conform to this are [2, 4, 16, 4, 2] and [3, 9, 3], whereas [2, 4, 8, 4, 2] does not.
  
      The function returns the maximum size of such a valid subset.
  
      Examples:
      >>> nums = [5,4,1,2,2]
      3
      >>> nums = [1,3,2,4]
      1
  
      Constraints:
      2 <= len(nums) <= 100000
      1 <= nums[i] <= 1000000000
      """
  
output:     
      counter = Counter(nums)
      max_length = 0
  
      for num in nums:
          length = 0
          temp_counter = counter.copy()
  
          # Ascending sequence
          current_num = num
          while temp_counter[current_num] > 0:
              temp_counter[current_num] -= 1
              length += 1
              current_num *= 2
              if current_num > 1000000000:
                  break
  
          # Descending sequence
          current_num //= 2
          while current_num >= num:
              temp_counter[current_num] += 1
              current_num //= 2
  
          current_num = num // 2
          while current_num >= 1 and temp_counter[current_num] > 0:
              temp_counter[current_num] -= 1
              length += 1
              current_num //= 2
  
          max_length = max(max_length, length)
  
      return max_length
  