Even Subset Sum Problem (Codeforces 1323A)
Tags: Greedy, brute force

You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.

Input: The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow.A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$.The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).

Output: For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.

Note: There are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.

Sample Inputs:
3
3
1 4 3
1
15
2
3 5

Sample Outputs:
1
2
-1
2
1 2

Solution (Python):
total = int(input())
for _ in range(total):
    n = int(input())
    arr = list(map(int, input().split()))
    if arr[0] % 2 == 0:
        print('1\n1')
        continue
    found = False
    for i in range(1, len(arr)):
        if arr[i] % 2 == 0:
            print(f'1\n{i + 1}')
            found = True
            break
        elif arr[i] % 2 and arr[i - 1] % 2:
            print(f'2\n{i} {i + 1}')
            found = True
            break
    if not found:
        print('-1')

Solution (Python):
t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(n):
        if a[i] % 2 == 0:
            print(1)
            print(i + 1)
            break
    else:
        if n > 1:
            print(2)
            print(1, 2)
        else:
            print(-1)

Solution (Python):
def solve():
    size = int(input())
    numbers = tuple(map(int, input().split()))
    for i in range(size + 1):
        if i == size:
            break
        if not numbers[i] & 1:
            break
    if i < size:
        print(1)
        print(i + 1)
    elif size > 1:
        print(2)
        print(1, 2)
    else:
        print(-1)
if __name__ == '__main__':
    for test in range(int(input())):
        solve()