input: from typing import List
  from collections import Counter
  from heapq import heappush, heappop
  def track_id_frequencies(nums: List[int], freq: List[int]) -> List[int]:
      """
      This task involves monitoring the frequency of IDs within a collection that changes over time. You have two integer arrays, nums and freq, both of the same length n. Each item in nums represents an ID, and the corresponding item in freq indicates how many times that ID should be added to or removed from the collection at each step.
  
      Adding IDs: If freq[i] is greater than zero, it indicates that freq[i] IDs with the value nums[i] are added to the collection at step i.
      Removing IDs: If freq[i] is less than zero, it indicates that -freq[i] IDs with the value nums[i] are removed from the collection at step i.
      Return an array ans of length n, where ans[i] represents the count of the most frequent ID in the collection after the ith step. If the collection is empty at any step, ans[i] should be 0 for that step.
  
      Examples:
      >>> nums = [2,3,2,1], freq = [3,2,-3,1]
      [3,3,2,2]
      >>> nums = [5,5,3], freq = [2,-2,1]
      [2,0,1]
  
      Constraints:
      1 <= nums.length == freq.length <= 10^5
      1 <= nums[i] <= 10^5
      -10^5 <= freq[i] <= 10^5
      freq[i] != 0
      It is ensured that the ID occurrences will not be negative at any step.
      """
output:     counter = Counter()
      most_frequent_heap = []
      ans = []
  
      for i in range(len(nums)):
          id = nums[i]
          count = freq[i]
  
          if count > 0:
              counter[id] += count
              heappush(most_frequent_heap, (-counter[id], id))
          else:
              counter[id] += count
              if counter[id] == 0:
                  del counter[id]
  
          while most_frequent_heap and -most_frequent_heap[0][0] != counter.get(most_frequent_heap[0][1], 0):
              heappop(most_frequent_heap)
  
          if most_frequent_heap:
              ans.append(-most_frequent_heap[0][0])
          else:
              ans.append(0)
  
      return ans