# Python program to implement
# the above approach
# Function to find triplets such that
# replacing them with their XOR make
# all array elements equal
def checkXOR(arr, N):
# If N is even
if (N % 2 == 0):
# Calculate xor of
# array elements
xro = 0;
# Traverse the array
for i in range(N):
# Update xor
xro ^= arr[i];
# If xor is not equal to 0
if (xro != 0):
print(-1);
return;
# Selecting the triplets such that
# elements of the pairs (arr[0], arr[1]),
# (arr[2], arr[3])... can be made equal
for i in range(0, N - 3, 2):
print(i, " ", (i + 1), " ", (i + 2), end=" ");
# Selecting the triplets such that
# all array elements can be made
# equal to arr[N - 1]
for i in range(0, N - 3, 2):
print(i, " ", (i + 1), " ", (N - 1), end=" ");
else:
# Selecting the triplets such that
# elements of the pairs (arr[0], arr[1]),
# (arr[2], arr[3])... can be made equal
for i in range(0, N - 2, 2):
print(i, " ", (i + 1), " ", (i + 2));
# Selecting the triplets such that
# all array elements can be made
# equal to arr[N - 1]
for i in range(0, N - 2, 2):
print(i, " ", (i + 1), " ", (N - 1));
# Driver code
if __name__ == '__main__':
# Given array
arr = [4, 2, 1, 7, 2];
# Size of array
N = len(arr);
# Function call
checkXOR(arr, N);
# This code is contributed by 29AjayKumar