using System;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
class GFG {
/// Function to print the equal sum sets
static void printSets(List<int> set1,
List<int> set2)
{
int i;
/// Print set 1.
for (i = 0; i < set1.Count; i++) {
Console.Write(set1[i] + " ");
}
Console.WriteLine();
/// Print set 2.
for (i = 0; i < set2.Count; i++) {
Console.Write(set2[i] + " ");
}
}
static bool findSets(int[] arr, int n,
ref List<int> set1,
ref List<int> set2,
int sum1, int sum2,
int pos)
{
if (pos == n) {
if (sum1 == sum2) {
printSets(set1, set2);
return true;
}
else
return false;
}
set1.Add(arr[pos]);
bool res = findSets(arr, n, ref set1,
ref set2, sum1 + arr[pos],
sum2, pos + 1);
if (res == true)
return res;
set1.RemoveAt(set1.Count - 1);
set2.Add(arr[pos]);
res = findSets(arr, n, ref set1,
ref set2, sum1, sum2
+ arr[pos],
pos + 1);
if (res == false)
set2.RemoveAt(set2.Count - 1);
return res;
}
static bool isPartitionPoss(int[] arr,
int n)
{
int sum = 0;
for (int i = 0; i < n; i++)
sum += arr[i];
if (sum % 2 != 0)
return false;
List<int> set1 = new List<int>();
List<int> set2 = new List<int>();
/// Find both the sets.
return findSets(arr, n, ref set1,
ref set2, 0, 0, 0);
}
public static void Main()
{
int[] arr = { 5, 5, 1, 11 };
int n = arr.Length;
if (isPartitionPoss(arr, n) == false) {
Console.Write("-1");
}
}
}