Flip bits in array using python
<p>You are given an integer array with <code>N</code> elements: <code>d[0], d[1], ... d[N - 1]</code>. 
You can perform AT MOST one move on the array: choose any two integers <code>[L, R]</code>, and flip all the elements between (and including) the <code>L</code>-th and <code>R</code>-th bits. <code>L</code> and <code>R</code> represent the left-most and right-most index of the bits marking the boundaries of the segment which you have decided to flip.</p>

<p>What is the maximum number of <code>1</code>-bits (indicated by <code>S</code>) which you can obtain in the final bit-string? </p>

<p>'Flipping' a bit means, that a <code>0</code> is transformed to a <code>1</code> and a <code>1</code> is transformed to a <code>0</code> (<code>0-&gt;1</code>,<code>1-&gt;0</code>). </p>

<p>Input Format: An integer <code>N</code>, next line contains the <code>N</code> bits, separated by spaces: <code>d[0] d[1] ... d[N - 1]</code></p>

<p>Output: <code>S</code> </p>

<p>Constraints: </p>

<pre><code>1 &lt;= N &lt;= 100000,
d[i] can only be 0 or 1 ,
0 &lt;= L &lt;= R &lt; n ,
</code></pre>

<p>Sample Input: </p>

<pre><code>8

1 0 0 1 0 0 1 0 
</code></pre>

<p>Sample Output:  <code>6</code> </p>

<p>Explanation: </p>

<p>We can get a maximum of 6 ones in the given binary array by performing either of the following operations: </p>

<pre><code>Flip [1, 5] ==&gt; 1 1 1 0 1 1 1 0
</code></pre>