<p>You are given two <strong>0-indexed</strong> integer arrays <code>nums1</code> and <code>nums2</code> of even length <code>n</code>.</p>

<p>You must remove <code>n / 2</code> elements from <code>nums1</code> and <code>n / 2</code> elements from <code>nums2</code>. After the removals, you insert the remaining elements of <code>nums1</code> and <code>nums2</code> into a set <code>s</code>.</p>

<p>Return <em>the <strong>maximum</strong> possible size of the set</em> <code>s</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [1,2,1,2], nums2 = [1,1,1,1]
<strong>Output:</strong> 2
<strong>Explanation:</strong> We remove two occurences of 1 from nums1 and nums2. After the removals, the arrays become equal to nums1 = [2,2] and nums2 = [1,1]. Therefore, s = {1,2}.
It can be shown that 2 is the maximum possible size of the set s after the removals.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [1,2,3,4,5,6], nums2 = [2,3,2,3,2,3]
<strong>Output:</strong> 5
<strong>Explanation:</strong> We remove 2, 3, and 6 from nums1, as well as 2 and two occurrences of 3 from nums2. After the removals, the arrays become equal to nums1 = [1,4,5] and nums2 = [2,3,2]. Therefore, s = {1,2,3,4,5}.
It can be shown that 5 is the maximum possible size of the set s after the removals.
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> nums1 = [1,1,2,2,3,3], nums2 = [4,4,5,5,6,6]
<strong>Output:</strong> 6
<strong>Explanation:</strong> We remove 1, 2, and 3 from nums1, as well as 4, 5, and 6 from nums2. After the removals, the arrays become equal to nums1 = [1,2,3] and nums2 = [4,5,6]. Therefore, s = {1,2,3,4,5,6}.
It can be shown that 6 is the maximum possible size of the set s after the removals.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>n == nums1.length == nums2.length</code></li>
	<li><code>1 &lt;= n &lt;= 2 * 10<sup>4</sup></code></li>
	<li><code>n</code> is even.</li>
	<li><code>1 &lt;= nums1[i], nums2[i] &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    '''
    There is some greedyness to this, if one set has a lot of 2's but just a single 1, you want to remove the 2's so that the other side doesn't have to remove the 2's, but you can have a bunch of 1's as well, so choosing which one to remove is important
    
    Basically what it comes down to is that if two sets both have a single 1 left, you may want to choose to remove from one set over another because the other set has removed all that it needs to so it is guarenteed to keep the 1 
    
    Issue I have is prematurely removing things, because you may have more duplicates in the future but you shoulnd't feel the need to remove things completely from a set
    
    [1 2 3 3 4 4 8 8 10 10] -> [1 2 3 4 8 10] 4 removed need to remove one more
    [2 4 6 6 6 7 9 9 9 10] -> [2 3 6 7 9 10] -> 4 removed need to remove one more
    
    so they share both 2 and 10
    '''
    
    def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:
        cnts1 = defaultdict(int)
        cnts2 = defaultdict(int)
        
        for num in nums1:
            cnts1[num] += 1
        for num in nums2:
            cnts2[num] += 1
            
        removed1 = len(nums1) // 2
        removed2 = len(nums2) // 2
        
        for num in nums1:
            while cnts1[num] > 1 and removed1 > 0:
                removed1 -= 1
                cnts1[num] -= 1

        for num in nums2:
            while cnts2[num] > 1 and removed2 > 0:
                removed2 -= 1
                cnts2[num] -= 1
            
        for num in cnts1:
            if removed1 > 0 and num in cnts2:
                removed1 -= 1
                del cnts2[num]
                
        for num in cnts2:
            if removed2 > 0 and num in cnts1:
                removed2 -= 1
                del cnts1[num]
                
    
       
        leftover = removed1 + removed2
        
        return (len(set(cnts1.keys()) | set(cnts2.keys()))) - leftover
        
592