import java.util.Scanner; public class Main{//搜索-深搜 static int min=0,n; public static void main(String[] args) { Scanner input=new Scanner(System.in); while(input.hasNext()){ n=input.nextInt(); min=Integer.MAX_VALUE; int a[]=new int[n]; for(int i=0;i<n;i++) a[i]=input.nextInt(); dfs(a,0,0,0); System.out.println(min); } } private static void dfs(int[] a, int i, int j, int k) { if(i==n){ int b=Math.abs(j-k); if(b<min) min=b; return; } dfs(a,i+1,j+a[i],k); dfs(a,i+1,j,k+a[i]); } }