<p>You are given two arrays of integers <code>nums1</code> and <code><font face="monospace">nums2</font></code>, possibly of different lengths. The values in the arrays are between <code>1</code> and <code>6</code>, inclusive.</p>

<p>In one operation, you can change any integer&#39;s value in <strong>any </strong>of the arrays to <strong>any</strong> value between <code>1</code> and <code>6</code>, inclusive.</p>

<p>Return <em>the minimum number of operations required to make the sum of values in </em><code>nums1</code><em> equal to the sum of values in </em><code>nums2</code><em>.</em> Return <code>-1</code>​​​​​ if it is not possible to make the sum of the two arrays equal.</p>

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

<pre>
<strong>Input:</strong> nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]
<strong>Output:</strong> 3
<strong>Explanation:</strong> You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed.
- Change nums2[0] to 6. nums1 = [1,2,3,4,5,6], nums2 = [<u><strong>6</strong></u>,1,2,2,2,2].
- Change nums1[5] to 1. nums1 = [1,2,3,4,5,<strong><u>1</u></strong>], nums2 = [6,1,2,2,2,2].
- Change nums1[2] to 2. nums1 = [1,2,<strong><u>2</u></strong>,4,5,1], nums2 = [6,1,2,2,2,2].
</pre>

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

<pre>
<strong>Input:</strong> nums1 = [1,1,1,1,1,1,1], nums2 = [6]
<strong>Output:</strong> -1
<strong>Explanation:</strong> There is no way to decrease the sum of nums1 or to increase the sum of nums2 to make them equal.
</pre>

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

<pre>
<strong>Input:</strong> nums1 = [6,6], nums2 = [1]
<strong>Output:</strong> 3
<strong>Explanation:</strong> You can make the sums of nums1 and nums2 equal with 3 operations. All indices are 0-indexed. 
- Change nums1[0] to 2. nums1 = [<strong><u>2</u></strong>,6], nums2 = [1].
- Change nums1[1] to 2. nums1 = [2,<strong><u>2</u></strong>], nums2 = [1].
- Change nums2[0] to 4. nums1 = [2,2], nums2 = [<strong><u>4</u></strong>].
</pre>

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

<ul>
	<li><code>1 &lt;= nums1.length, nums2.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums1[i], nums2[i] &lt;= 6</code></li>
</ul>

class Solution:
    def minOperations(self, nums1: List[int], nums2: List[int]) -> int:

        n1 = len(nums1)
        n2 = len(nums2)

        # Count number of 1s to 6s of each
        from collections import defaultdict

        sum1 = 0
        dict1 = defaultdict(int)

        sum2 = 0
        dict2 = defaultdict(int)

        for i in range(0,n1):
            sum1 += nums1[i]
            dict1[nums1[i]] += 1
        for i in range(0,n2):
            sum2 += nums2[i]
            dict2[nums2[i]] += 1

        dict1,dict2,sum1,sum2

        # If sum already equal, done
        if sum1 == sum2:
            return 0

        if sum1 > sum2:
            dict1, dict2 = dict2, dict1
            sum1, sum2 = sum2, sum1

        print(dict1,dict2,sum1,sum2)

        # Count the number of 1s to 6s of each
        # WLOG let nums1 be the one with the smaller sum, i.e. sum(nums1) < sum(nums2)
            # If not, just switch the naming convention of the two
        # See if difference can be covered by all the 1s from nums1 and 2s from nums2, i.e., if diff > 5*(nums1's 1s + nums2's 6s)
        # If 1/6s don't work, try 4*(2s+5s)
        # Do it until all candidates are exhausted
        # If difference is too large, then stop

        diff = sum2 - sum1
        count = 0

        for i in range(1,7):

            delta_each = 6 - i
            num_this_delta = dict1[i] + dict2[7-i]

            delta = delta_each * num_this_delta
            
            print(i,diff,delta_each,num_this_delta,delta)

            if diff <= delta:

                count += math.ceil(diff/delta_each)
                return count
            
            else:
                
                count += num_this_delta
                diff -= delta
        
        return -1

        # arr1 = nums1
        # arr2 = nums2

        # # WLOG make arr1 the larger one
        # if sum(arr1) < sum(arr2):
        #     temp = arr2[:]
        #     arr2 = arr1[:]
        #     arr1 = temp[:]

        # arr1, arr2
            
        # # Go through, collect number of 1,2,3,4,5,6's in each of arr1 and arr2

        # n1 = len(arr1)
        # n2 = len(arr2)

        # from collections import defaultdict

        # dict1 = defaultdict(int)
        # dict2 = defaultdict(int)

        # for i in range(0,n1,1):
        #     dict1[arr1[i]] += 1
            
        # for j in range(0,n2,1):
        #     dict2[arr2[j]] += 1
            
        # print(dict1, dict2)

        # # Minimum number: figure out sums of each
        # # Goal is to get target sum of 0

        # target = sum(arr1) - sum(arr2)
        # target # should always be positive #

        # steps = 0

        # # Greedy approach: always want to cancel 6's first, then 5's, etc.
        # # Two pointers
        # # If diff exceeds number of 6's in arr1 * (6-1), get all
        # # Then if diff exceeds number of 6's in arr2 * (6-1), get all

        # for curr_arr1_value in range(6,0,-1):
        #     #print('curr_arr1_value',curr_arr1_value)

        #     num_values_arr1 = dict1[curr_arr1_value]
        #     num_values_arr2 = dict2[7 - curr_arr1_value]

        #     num_values = num_values_arr1 + num_values_arr2
        #     #print('num_values',num_values)

        #     max_diff = num_values * (curr_arr1_value - 1)
        #     #print('max_diff',max_diff)

        #     # If exceeds target, then enough, so answer is ceiling of target / (curr_arr1_value - 1)
        #     # E.g., target = 17, and we have 8 6's, then need to do ceil(17/5) = 4, since change 3 6's to 1's (-15) and then 1 6 to 4 (-2)
        #     if max_diff > target:
        #         steps += math.ceil(target / (curr_arr1_value - 1))
        #         #print("ANSWER FOUND",steps)
        #         return steps
        #     elif max_diff == target:
        #         steps += num_values
        #         return steps
        #     else:
        #         steps += num_values
        #         target -= max_diff

        # return -1
932