import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]w = new int[n];

    int all = 0;
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	w[i] = sc.nextInt();
    		all += w[i];
      	}
    for(int i=0; i<=n; i++) {
    	if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	}
    	}
    int usiro = all - mae;
    int A = mae - usiro;
    A =	Math.abs(A);
    int B = (mae - w[cou-1]) - (usiro + w[cou-1]);
    B = Math.abs(B);
    
    System.out.print(Math.min(A, B));
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]w = new int[n];

    int all = 0;
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	w[i] = sc.nextInt();
    		all += w[i];
      	}
    for(int i=0; i<=n; i++) {
    	if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	}
    	}
    int usiro = all - mae;
    int A = mae - usiro;
    A =	Math.abs(A);
    int B = (mae - w[cou-1]) - (usiro + w[cou-1]);
    B = Math.abs(B);
    
    System.out.print(Math.min(A, B));
    }
} Main public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]w = new int[n];

    int all = 0;
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	w[i] = sc.nextInt();
    		all += w[i];
      	}
    for(int i=0; i<=n; i++) {
    	if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	}
    	}
    int usiro = all - mae;
    int A = mae - usiro;
    A =	Math.abs(A);
    int B = (mae - w[cou-1]) - (usiro + w[cou-1]);
    B = Math.abs(B);
    
    System.out.print(Math.min(A, B));
    } main {
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]w = new int[n];

    int all = 0;
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	w[i] = sc.nextInt();
    		all += w[i];
      	}
    for(int i=0; i<=n; i++) {
    	if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	}
    	}
    int usiro = all - mae;
    int A = mae - usiro;
    A =	Math.abs(A);
    int B = (mae - w[cou-1]) - (usiro + w[cou-1]);
    B = Math.abs(B);
    
    System.out.print(Math.min(A, B));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[]w = new int[n]; w new int[n] n int all = 0; all 0 int mae = 0; mae 0 int cou = 0; cou 0 for(int i=0; i<n; i++) {
    	w[i] = sc.nextInt();
    		all += w[i];
      	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
    	w[i] = sc.nextInt();
    		all += w[i];
      	} {
    	w[i] = sc.nextInt();
    		all += w[i];
      	} w[i] = sc.nextInt() w[i] w i sc.nextInt() sc.nextInt sc all += w[i] all w[i] w i for(int i=0; i<=n; i++) {
    	if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	}
    	} int i=0; int i=0; i 0 i<=n i n i++ i++ i {
    	if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	}
    	} {
    	if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	}
    	} if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	} mae < all/2 mae all/2 all 2 {
    		mae += w[i];
    	   	cou++;
    	   	   	} mae += w[i] mae w[i] w i cou++ cou int usiro = all - mae; usiro all - mae all mae int A = mae - usiro; A mae - usiro mae usiro A =	Math.abs(A) A Math.abs(A) Math.abs Math A int B = (mae - w[cou-1]) - (usiro + w[cou-1]); B (mae - w[cou-1]) - (usiro + w[cou-1]) (mae - w[cou-1]) mae w[cou-1] w cou-1 cou 1 (usiro + w[cou-1]) usiro w[cou-1] w cou-1 cou 1 B = Math.abs(B) B Math.abs(B) Math.abs Math B System.out.print(Math.min(A, B)) System.out.print System.out System System.out Math.min(A, B) Math.min Math A B String[] args args public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]w = new int[n];

    int all = 0;
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	w[i] = sc.nextInt();
    		all += w[i];
      	}
    for(int i=0; i<=n; i++) {
    	if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	}
    	}
    int usiro = all - mae;
    int A = mae - usiro;
    A =	Math.abs(A);
    int B = (mae - w[cou-1]) - (usiro + w[cou-1]);
    B = Math.abs(B);
    
    System.out.print(Math.min(A, B));
    }
} public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]w = new int[n];

    int all = 0;
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	w[i] = sc.nextInt();
    		all += w[i];
      	}
    for(int i=0; i<=n; i++) {
    	if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	}
    	}
    int usiro = all - mae;
    int A = mae - usiro;
    A =	Math.abs(A);
    int B = (mae - w[cou-1]) - (usiro + w[cou-1]);
    B = Math.abs(B);
    
    System.out.print(Math.min(A, B));
    }
} Main
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]w = new int[n];

    int all = 0;
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	w[i] = sc.nextInt();
    		all += w[i];
      	}
    for(int i=0; i<=n; i++) {
    	if(mae < all/2) {
    		mae += w[i];
    	   	cou++;
    	   	   	}
    	}
    int usiro = all - mae;
    int A = mae - usiro;
    A =	Math.abs(A);
    int B = (mae - w[cou-1]) - (usiro + w[cou-1]);
    B = Math.abs(B);
    
    System.out.print(Math.min(A, B));
    }
}
