import java.util.*;
class Main{
    public static void main(String[] args) {
       Scanner stdIn = new Scanner(System.in); 
       int n = stdIn.nextInt();
       int[] w = new int[n];
       int s1 = 0;
       int s2 = 0;
       for(int i = 0; i < n;i++){
            w[i] = stdIn.nextInt();
            s1 += w[i];
       }
       int min = Math.abs(s1 - s2);
       for(int i = n - 1 ; i >= 0 ; i--){
           s1 -= w[i];
           s2 += w[i];
           if(Math.abs(s1 - s2) < min)
           min = Math.abs(s1 - s2);
       } 
       System.out.println(min);
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args) {
       Scanner stdIn = new Scanner(System.in); 
       int n = stdIn.nextInt();
       int[] w = new int[n];
       int s1 = 0;
       int s2 = 0;
       for(int i = 0; i < n;i++){
            w[i] = stdIn.nextInt();
            s1 += w[i];
       }
       int min = Math.abs(s1 - s2);
       for(int i = n - 1 ; i >= 0 ; i--){
           s1 -= w[i];
           s2 += w[i];
           if(Math.abs(s1 - s2) < min)
           min = Math.abs(s1 - s2);
       } 
       System.out.println(min);
    }
} Main public static void main(String[] args) {
       Scanner stdIn = new Scanner(System.in); 
       int n = stdIn.nextInt();
       int[] w = new int[n];
       int s1 = 0;
       int s2 = 0;
       for(int i = 0; i < n;i++){
            w[i] = stdIn.nextInt();
            s1 += w[i];
       }
       int min = Math.abs(s1 - s2);
       for(int i = n - 1 ; i >= 0 ; i--){
           s1 -= w[i];
           s2 += w[i];
           if(Math.abs(s1 - s2) < min)
           min = Math.abs(s1 - s2);
       } 
       System.out.println(min);
    } main {
       Scanner stdIn = new Scanner(System.in); 
       int n = stdIn.nextInt();
       int[] w = new int[n];
       int s1 = 0;
       int s2 = 0;
       for(int i = 0; i < n;i++){
            w[i] = stdIn.nextInt();
            s1 += w[i];
       }
       int min = Math.abs(s1 - s2);
       for(int i = n - 1 ; i >= 0 ; i--){
           s1 -= w[i];
           s2 += w[i];
           if(Math.abs(s1 - s2) < min)
           min = Math.abs(s1 - s2);
       } 
       System.out.println(min);
    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] w = new int[n]; w new int[n] n int s1 = 0; s1 0 int s2 = 0; s2 0 for(int i = 0; i < n;i++){
            w[i] = stdIn.nextInt();
            s1 += w[i];
       } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            w[i] = stdIn.nextInt();
            s1 += w[i];
       } {
            w[i] = stdIn.nextInt();
            s1 += w[i];
       } w[i] = stdIn.nextInt() w[i] w i stdIn.nextInt() stdIn.nextInt stdIn s1 += w[i] s1 w[i] w i int min = Math.abs(s1 - s2); min Math.abs(s1 - s2) Math.abs Math s1 - s2 s1 s2 for(int i = n - 1 ; i >= 0 ; i--){
           s1 -= w[i];
           s2 += w[i];
           if(Math.abs(s1 - s2) < min)
           min = Math.abs(s1 - s2);
       } int i = n - 1 ; int i = n - 1 ; i n - 1 n 1 i >= 0 i 0 i-- i-- i {
           s1 -= w[i];
           s2 += w[i];
           if(Math.abs(s1 - s2) < min)
           min = Math.abs(s1 - s2);
       } {
           s1 -= w[i];
           s2 += w[i];
           if(Math.abs(s1 - s2) < min)
           min = Math.abs(s1 - s2);
       } s1 -= w[i] s1 w[i] w i s2 += w[i] s2 w[i] w i if(Math.abs(s1 - s2) < min)
           min = Math.abs(s1 - s2); Math.abs(s1 - s2) < min Math.abs(s1 - s2) Math.abs Math s1 - s2 s1 s2 min min = Math.abs(s1 - s2) min Math.abs(s1 - s2) Math.abs Math s1 - s2 s1 s2 System.out.println(min) System.out.println System.out System System.out min String[] args args
import java.util.*;
class Main{
    public static void main(String[] args) {
       Scanner stdIn = new Scanner(System.in); 
       int n = stdIn.nextInt();
       int[] w = new int[n];
       int s1 = 0;
       int s2 = 0;
       for(int i = 0; i < n;i++){
            w[i] = stdIn.nextInt();
            s1 += w[i];
       }
       int min = Math.abs(s1 - s2);
       for(int i = n - 1 ; i >= 0 ; i--){
           s1 -= w[i];
           s2 += w[i];
           if(Math.abs(s1 - s2) < min)
           min = Math.abs(s1 - s2);
       } 
       System.out.println(min);
    }
}