import java.util.*;
class Ideone{
public static void main
(String[] args
){ int set[] = {3,5,4,6,1,7}; //{3,4,6}, {1,7,5}
int n = set.length;
int totalSum = 0;
for(int x:set) totalSum+=x;
if(totalSum%2 == 1) {
System.
out.
println("Equal partition not possible as summ is odd"); return;
}
//This code has complexity of O(N * SUM) and uses O(N * SUM) extra space.
int sum = totalSum/2; //Find out whether sum can be formed or not
boolean[][] partitionSum = new boolean[n+1][sum+1];
//If sum is zero, we don't require to include any element. So default value will be true
for(int i=0; i<n+1; i++){
partitionSum[i][0] = true;
}
//If set is empty, we can't get sum without including any element
for(int i=0; i<sum+1; i++){
partitionSum[0][i] = false;
}
for(int i=1; i<n+1; i++){
for(int j=1; j<sum+1; j++){
if(partitionSum[i-1][j] || (j >=set[i-1] && partitionSum[i-1][j-set[i-1]])){
partitionSum[i][j] = true;
}
}
}
if(partitionSum[n][sum]){
System.
out.
println("Equal partition possible"); }else{
System.
out.
println("Equal partition not possible with given input set"); }
}
}