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;
    for(int i=0; i<n; i++){
        w[i] = sc.nextInt();
        all += w[i];
    }
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	}
    }
    int A = all-mae-mae;
    A = Math.abs(A);
    int B = all-(mae-w[cou-1])-(mae-w[cou-1]);
    B = Math.abs(B);
    
    System.out.println(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;
    for(int i=0; i<n; i++){
        w[i] = sc.nextInt();
        all += w[i];
    }
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	}
    }
    int A = all-mae-mae;
    A = Math.abs(A);
    int B = all-(mae-w[cou-1])-(mae-w[cou-1]);
    B = Math.abs(B);
    
    System.out.println(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;
    for(int i=0; i<n; i++){
        w[i] = sc.nextInt();
        all += w[i];
    }
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	}
    }
    int A = all-mae-mae;
    A = Math.abs(A);
    int B = all-(mae-w[cou-1])-(mae-w[cou-1]);
    B = Math.abs(B);
    
    System.out.println(Math.min(A, B));
    } main {
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[]w = new int[n];
 
    int all = 0;
    for(int i=0; i<n; i++){
        w[i] = sc.nextInt();
        all += w[i];
    }
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	}
    }
    int A = all-mae-mae;
    A = Math.abs(A);
    int B = all-(mae-w[cou-1])-(mae-w[cou-1]);
    B = Math.abs(B);
    
    System.out.println(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 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 int mae = 0; mae 0 int cou = 0; cou 0 for(int i=0; i<n; i++) {
    	if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	}
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
    	if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	}
    } {
    	if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	}
    } if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	} mae*2 < all mae*2 mae 2 all {
    		mae += w[i];
    		cou++;
    	} mae += w[i] mae w[i] w i cou++ cou int A = all-mae-mae; A all-mae-mae all-mae-mae all mae mae A = Math.abs(A) A Math.abs(A) Math.abs Math A int B = all-(mae-w[cou-1])-(mae-w[cou-1]); B all-(mae-w[cou-1])-(mae-w[cou-1]) all-(mae-w[cou-1])-(mae-w[cou-1]) all (mae-w[cou-1]) mae w[cou-1] w cou-1 cou 1 (mae-w[cou-1]) mae w[cou-1] w cou-1 cou 1 B = Math.abs(B) B Math.abs(B) Math.abs Math B System.out.println(Math.min(A, B)) System.out.println 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;
    for(int i=0; i<n; i++){
        w[i] = sc.nextInt();
        all += w[i];
    }
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	}
    }
    int A = all-mae-mae;
    A = Math.abs(A);
    int B = all-(mae-w[cou-1])-(mae-w[cou-1]);
    B = Math.abs(B);
    
    System.out.println(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;
    for(int i=0; i<n; i++){
        w[i] = sc.nextInt();
        all += w[i];
    }
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	}
    }
    int A = all-mae-mae;
    A = Math.abs(A);
    int B = all-(mae-w[cou-1])-(mae-w[cou-1]);
    B = Math.abs(B);
    
    System.out.println(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;
    for(int i=0; i<n; i++){
        w[i] = sc.nextInt();
        all += w[i];
    }
    int mae = 0;
    int cou = 0;
    for(int i=0; i<n; i++) {
    	if(mae*2 < all) {
    		mae += w[i];
    		cou++;
    	}
    }
    int A = all-mae-mae;
    A = Math.abs(A);
    int B = all-(mae-w[cou-1])-(mae-w[cou-1]);
    B = Math.abs(B);
    
    System.out.println(Math.min(A, B));
    }
}
