package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/sum-of-even-numbers-after-queries/
 */
public class Problem985 {
    public int[] sumEvenAfterQueries(int[] A, int[][] queries) {
        int[] answer = new int[A.length];
        for (int i = 0; i < queries.length; i++) {
            int val = queries[i][0];
            int index = queries[i][1];
            A[index] += val;
            int sum = 0;
            for (int a : A) {
                if (a % 2 == 0) {
                    sum += a;
                }
            }
            answer[i] = sum;
        }
        return answer;
    }

    public static void main(String[] args) {
        Problem985 prob = new Problem985();
        System.out.println(Arrays.toString(prob.sumEvenAfterQueries(new int[]{1, 2, 3, 4}, new int[][]{
            {1, 0}, {-3, 1}, {-4, 0}, {2, 3}
        }))); // [8,6,2,4]
    }
}

@@ -16,34 +16,8 @@
 e;%0A%0A
-import java.util.Arrays;%0A%0A
 /**%0A
@@ -175,24 +175,151 @@
  queries) %7B%0A
+        int sum = 0;%0A        for (int a : A) %7B%0A            if (a %25 2 == 0) %7B%0A                sum += a;%0A            %7D%0A        %7D%0A
         int%5B
@@ -487,16 +487,20 @@
         
+if (
 A%5Bindex%5D
@@ -504,15 +504,19 @@
 ex%5D 
-+= val;
+%25 2 == 0) %7B
 %0A   
@@ -520,35 +520,43 @@
             
-int
+   
  sum 
+-
 = 
-0
+A%5Bindex%5D
 ;%0A          
@@ -557,38 +557,47 @@
         
-for (int a : A) %7B%0A    
+%7D%0A            A%5Bindex%5D += val;%0A
         
@@ -596,36 +596,42 @@
             if (
-a
+A%5Bindex%5D
  %25
- 
 2 == 0) %7B%0A      
@@ -640,34 +640,33 @@
         
-    
 sum += 
-a;%0A    
+A%5Bindex%5D;%0A
         
@@ -671,30 +671,16 @@
       %7D%0A
-            %7D%0A
         
@@ -742,279 +742,7 @@
    %7D
-%0A%0A    public static void main(String%5B%5D args) %7B%0A        Problem985 prob = new Problem985();%0A        System.out.println(Arrays.toString(prob.sumEvenAfterQueries(new int%5B%5D%7B1, 2, 3, 4%7D, new int%5B%5D%5B%5D%7B%0A            %7B1, 0%7D, %7B-3, 1%7D, %7B-4, 0%7D, %7B2, 3%7D%0A        %7D))); // %5B8,6,2,4%5D%0A    %7D
 %0A%7D%0A

Solve problem 985