import sys class Solution: def sumEvenAfterQueries(self, A: 'List[int]', queries: 'List[List[int]]') -> 'List[int]': result = list() len0 = len(A) len1 = len(queries) len2 = len(queries[0]) sums = sys.maxsize for i in range(len1): #print(i) val = queries[i][0] index = queries[i][1] if sums == sys.maxsize: A[index] += val sums = 0 for j in range(len0): cur0 = A[j] if cur0 % 2 == 0: sums += cur0 else: cur = A[index] + val if cur % 2 == 0: if A[index] % 2 == 0: sums += val else: sums += cur A[index] = cur else: if A[index] % 2 == 0: sums -= A[index] else: sums += 0 A[index] = cur result.append(sums) return result