<p>You are given an integer array&nbsp;<code>nums</code>. You can choose <strong>exactly one</strong> index (<strong>0-indexed</strong>) and remove the element. Notice that the index of the elements may change after the removal.</p>

<p>For example, if <code>nums = [6,1,7,4,1]</code>:</p>

<ul>
	<li>Choosing to remove index <code>1</code> results in <code>nums = [6,7,4,1]</code>.</li>
	<li>Choosing to remove index <code>2</code> results in <code>nums = [6,1,4,1]</code>.</li>
	<li>Choosing to remove index <code>4</code> results in <code>nums = [6,1,7,4]</code>.</li>
</ul>

<p>An array is <strong>fair</strong> if the sum of the odd-indexed values equals the sum of the even-indexed values.</p>

<p>Return the <em><strong>number</strong> of indices that you could choose such that after the removal, </em><code>nums</code><em> </em><em>is <strong>fair</strong>. </em></p>

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

<pre>
<strong>Input:</strong> nums = [2,1,6,4]
<strong>Output:</strong> 1
<strong>Explanation:</strong>
Remove index 0: [1,6,4] -&gt; Even sum: 1 + 4 = 5. Odd sum: 6. Not fair.
Remove index 1: [2,6,4] -&gt; Even sum: 2 + 4 = 6. Odd sum: 6. Fair.
Remove index 2: [2,1,4] -&gt; Even sum: 2 + 4 = 6. Odd sum: 1. Not fair.
Remove index 3: [2,1,6] -&gt; Even sum: 2 + 6 = 8. Odd sum: 1. Not fair.
There is 1 index that you can remove to make nums fair.
</pre>

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

<pre>
<strong>Input:</strong> nums = [1,1,1]
<strong>Output:</strong> 3
<strong>Explanation:</strong>&nbsp;You can remove any index and the remaining array is fair.
</pre>

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

<pre>
<strong>Input:</strong> nums = [1,2,3]
<strong>Output:</strong> 0
<strong>Explanation:</strong>&nbsp;You cannot make a fair array after removing any index.
</pre>

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

<ul>
	<li><code>1 &lt;= nums.length &lt;= 10<sup>5</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 10<sup>4</sup></code></li>
</ul>

// code i written is shit see code below for better solution and how to write short

class Solution {
public:
    int waysToMakeFair(vector<int>& nums) {
        int n = nums.size();
        if(n==1) return 1;
        vector<pair<int,int>> pre(nums.size(),{0,0});
        vector<pair<int,int>> po(nums.size(),{0,0});
        //first - odd  second - even
        int s = 0;
        pre[0].first = 0;
        pre[0].second = nums[0];
        for(int i=1;i<n;i++)
        {
            
           if(i&1) // odd
           {
            pre[i].first = pre[i-1].first + nums[i];
            pre[i].second = pre[i-1].second ;
           }
           else{
            pre[i].first = pre[i-1].first;
            pre[i].second = pre[i-1].second + nums[i];
           }
        }

        if(n&1)
        {
            po[n-1].first = 0;
            po[n-1].second = nums[n-1];
        }
        else{
            po[n-1].first = nums[n-1];
            po[n-1].second = 0;
        }

         for(int i=n-2;i>=0;i--)
        {
            
           if(i&1) // odd
           {
            po[i].first = po[i+1].first + nums[i];
            po[i].second = po[i+1].second ;
           }
           else{
            po[i].first = po[i+1].first;
            po[i].second = po[i+1].second + nums[i];
           }
        }
        int f =0;
        for(int i=1;i<n-1;i++)
        {
            if(pre[i-1].first + po[i+1].second == pre[i-1].second+po[i+1].first) f+=1;
        }

        if(pre[n-2].first == pre[n-2].second) f++;
        if(po[1].first == po[1].second) f++;


        return f;
    }};

//better code 2nd fastest see how nice it written
// class Solution {
// public:
//     int waysToMakeFair(vector<int>& nums) {
//         int n = nums.size();
//         if (n <= 1) return n;

//         int suffixSum[2] = {0};
//         int prefixSum[2] = {0};

//         for (int i = 0; i < n; ++i)
//         {
//             suffixSum[i & 1] += nums[i];
//         }

//         int cnt = 0;

//         for (int i = 0; i < n; ++i)
//         {
//             // remove current num from suffixSum
//             suffixSum[i & 1] -= nums[i];

//             cnt += (prefixSum[1] + suffixSum[0] == prefixSum[0] + suffixSum[1]);

//             // add current num to prefixSum
//             prefixSum[i & 1] += nums[i];
//         }

//         return cnt;
//     }
113900