<p>You are given an array <code>arr</code> which consists of only zeros and ones, divide the array into <strong>three non-empty parts</strong> such that all of these parts represent the same binary value.</p>

<p>If it is possible, return any <code>[i, j]</code> with <code>i + 1 &lt; j</code>, such that:</p>

<ul>
	<li><code>arr[0], arr[1], ..., arr[i]</code> is the first part,</li>
	<li><code>arr[i + 1], arr[i + 2], ..., arr[j - 1]</code> is the second part, and</li>
	<li><code>arr[j], arr[j + 1], ..., arr[arr.length - 1]</code> is the third part.</li>
	<li>All three parts have equal binary values.</li>
</ul>

<p>If it is not possible, return <code>[-1, -1]</code>.</p>

<p>Note that the entire part is used when considering what binary value it represents. For example, <code>[1,1,0]</code> represents <code>6</code> in decimal, not <code>3</code>. Also, leading zeros <strong>are allowed</strong>, so <code>[0,1,1]</code> and <code>[1,1]</code> represent the same value.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> arr = [1,0,1,0,1]
<strong>Output:</strong> [0,3]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> arr = [1,1,0,1,1]
<strong>Output:</strong> [-1,-1]
</pre><p><strong class="example">Example 3:</strong></p>
<pre><strong>Input:</strong> arr = [1,1,0,0,1]
<strong>Output:</strong> [0,2]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>3 &lt;= arr.length &lt;= 3 * 10<sup>4</sup></code></li>
	<li><code>arr[i]</code> is <code>0</code> or <code>1</code></li>
</ul>

class Solution:
    def threeEqualParts(self, arr: List[int]) -> List[int]:
        # Count the total number of ones in the array
        total_ones = sum(arr)
        
        # If the total number of ones is not divisible by 3, it's impossible
        if total_ones % 3 != 0:
            return [-1, -1]
        
        # If the array is all zeros, any division is valid
        if total_ones == 0:
            return [0, len(arr) - 1]
        
        # Calculate the number of ones each part should have
        ones_per_part = total_ones // 3
        
        # Find the starting indices of each part
        first_start = -1
        second_start = -1
        third_start = -1
        count_ones = 0
        
        for i, num in enumerate(arr):
            if num == 1:
                count_ones += 1
                if first_start == -1 and count_ones == 1:
                    first_start = i
                elif second_start == -1 and count_ones == ones_per_part + 1:
                    second_start = i
                elif third_start == -1 and count_ones == 2 * ones_per_part + 1:
                    third_start = i
                    break
        
        # Ensure the parts have the same binary value
        while third_start < len(arr):
            if arr[first_start] != arr[second_start] or arr[first_start] != arr[third_start]:
                return [-1, -1]
            first_start += 1
            second_start += 1
            third_start += 1
        
        # Calculate the indices to return
        return [first_start - 1, second_start]

# Example usage:
solution = Solution()
arr = [1, 0, 1, 0, 1]
print(solution.threeEqualParts(arr))  # Output: [0, 3]
17800