You are given an integer array nums and an array queries where queries[i] = [vali, indexi].

For each query i, first, apply nums[indexi] = nums[indexi] + vali, then print the sum of the even values of nums.

Return an integer array answer where answer[i] is the answer to the ith query.

&nbsp;
Example 1:

Input: nums = [1,2,3,4], queries = [[1,0],[-3,1],[-4,0],[2,3]]
Output: [8,6,2,4]
Explanation: At the beginning, the array is [1,2,3,4].
After adding 1 to nums[0], the array is [2,2,3,4], and the sum of even values is 2 + 2 + 4 = 8.
After adding -3 to nums[1], the array is [2,-1,3,4], and the sum of even values is 2 + 4 = 6.
After adding -4 to nums[0], the array is [-2,-1,3,4], and the sum of even values is -2 + 4 = 2.
After adding 2 to nums[3], the array is [-2,-1,3,6], and the sum of even values is -2 + 6 = 4.


Example 2:

Input: nums = [1], queries = [[4,0]]
Output: [0]


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 104
	-104 &lt;= nums[i] &lt;= 104
	1 &lt;= queries.length &lt;= 104
	-104 &lt;= vali &lt;= 104
	0 &lt;= indexi &lt; nums.length


class Solution:
# O(n) || O(1)
    def sumEvenAfterQueries(self, nums: List[int], queries: List[List[int]]) -> List[int]:
        totalEvenNumSum = sum([num for num in nums if num % 2 == 0])
        result = []

        for val, idx in queries:
            oldVal = nums[idx]
            nums[idx] += val

            if oldVal % 2 == 0:
                totalEvenNumSum -= oldVal

            if nums[idx] % 2 == 0:
                totalEvenNumSum += nums[idx]

            result.append(totalEvenNumSum)

        return result
class Solution {
    public int[] sumEvenAfterQueries(int[] nums, int[][] queries) {
        int sum = 0;
        for (int i : nums) {
            if ((i & 1) == 0) { // (i % 2 == 0)
                sum += i;
            }
        }
        int[] ans = new int[nums.length];
        int k = 0;
        for (int[] q : queries) {
            int idx = q[1];
            if ((nums[idx] & 1) == 0) { // (nums[idx] % 2 == 0)
                sum -= nums[idx];
            }
            nums[idx] += q[0];
            if ((nums[idx] & 1) == 0) { // (nums[idx] % 2 == 0)
                sum += nums[idx];
            }
            ans[k++] = sum;
        }
        return ans;
    }
}
class Solution {
public:
    vector<int> sumEvenAfterQueries(vector<int>& nums, vector<vector<int>>& queries) {
    //Sum of all even numbers in the array intially
        int tes=accumulate(nums.begin(),nums.end(),0,[](int curr,int a) {if(a%2==0) return curr+=a;
                else return curr;});
        vector<int> ans(queries.size());
        bool a=false,b=false;
        for(int i=0;i<queries.size();i++)
        {
            //If both are even or odd it stays even then
            a=nums[queries[i][1]]%2==0 && queries[i][0]%2==0;
            b=abs(nums[queries[i][1]]%2)==1 && abs(queries[i][0]%2)==1;
            if(a)
                tes+=queries[i][0];
            else if(b)
                tes+=queries[i][0]+nums[queries[i][1]];
            else if(nums[queries[i][1]]%2==0)
                tes-=nums[queries[i][1]]; //If even turns to odd because of operation remove that even value from ans
            ans[i]=tes; //Adding the result
            nums[queries[i][1]]+=queries[i][0]; //now completing the operation in queries to use in further operations
        }
        return ans;
    }
};
/**
 * @param {number[]} nums
 * @param {number[][]} queries
 * @return {number[]}
 */
var sumEvenAfterQueries = function(nums, queries) {
    let sumEven = 0, ans = []
    for (let i = 0; i < nums.length; i++) {
        if (nums[i] % 2 == 0) sumEven += nums[i]
    }

    for (let [val, idx] of queries) {
        if (nums[idx] % 2 == 0) {
            if (val % 2 == 0) sumEven += val
            else sumEven -= nums[idx]
        } else {
            // odd + odd
            if (val % 2 !== 0) sumEven += nums[idx] + val
        }
        nums[idx] += val
        ans.push(sumEven)
    }

    return ans
};
Sum of Even Numbers After Queries