import java.util.*;
//import java.io.*;


public class Main{

    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());

        int n =sc.nextInt();
        int[] w = new int[n];
        for(int i=0;i<n;i++){
            w[i]=sc.nextInt();
        }
        sc.close();

        int formerPartSum[]= new int[n+1];
        int latterPartSum[]= new int[n+1];

        formerPartSum[0]=0;
        for(int i=0;i<n;i++){
            latterPartSum[0]+=w[i];
        }

        int minAbs=Math.abs(latterPartSum[0]-formerPartSum[0]);

        for(int i=0;i<n;i++){
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        }
        System.out.println(minAbs);
    }


} import java.util.*; util.* java public class Main{

    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());

        int n =sc.nextInt();
        int[] w = new int[n];
        for(int i=0;i<n;i++){
            w[i]=sc.nextInt();
        }
        sc.close();

        int formerPartSum[]= new int[n+1];
        int latterPartSum[]= new int[n+1];

        formerPartSum[0]=0;
        for(int i=0;i<n;i++){
            latterPartSum[0]+=w[i];
        }

        int minAbs=Math.abs(latterPartSum[0]-formerPartSum[0]);

        for(int i=0;i<n;i++){
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        }
        System.out.println(minAbs);
    }


} Main public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());

        int n =sc.nextInt();
        int[] w = new int[n];
        for(int i=0;i<n;i++){
            w[i]=sc.nextInt();
        }
        sc.close();

        int formerPartSum[]= new int[n+1];
        int latterPartSum[]= new int[n+1];

        formerPartSum[0]=0;
        for(int i=0;i<n;i++){
            latterPartSum[0]+=w[i];
        }

        int minAbs=Math.abs(latterPartSum[0]-formerPartSum[0]);

        for(int i=0;i<n;i++){
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        }
        System.out.println(minAbs);
    } main {
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());

        int n =sc.nextInt();
        int[] w = new int[n];
        for(int i=0;i<n;i++){
            w[i]=sc.nextInt();
        }
        sc.close();

        int formerPartSum[]= new int[n+1];
        int latterPartSum[]= new int[n+1];

        formerPartSum[0]=0;
        for(int i=0;i<n;i++){
            latterPartSum[0]+=w[i];
        }

        int minAbs=Math.abs(latterPartSum[0]-formerPartSum[0]);

        for(int i=0;i<n;i++){
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        }
        System.out.println(minAbs);
    } 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 for(int i=0;i<n;i++){
            w[i]=sc.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            w[i]=sc.nextInt();
        } {
            w[i]=sc.nextInt();
        } w[i]=sc.nextInt() w[i] w i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int formerPartSum[]= new int[n+1]; formerPartSum new int[n+1] n+1 n 1 int latterPartSum[]= new int[n+1]; latterPartSum new int[n+1] n+1 n 1 formerPartSum[0]=0 formerPartSum[0] formerPartSum 0 0 for(int i=0;i<n;i++){
            latterPartSum[0]+=w[i];
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            latterPartSum[0]+=w[i];
        } {
            latterPartSum[0]+=w[i];
        } latterPartSum[0]+=w[i] latterPartSum[0] latterPartSum 0 w[i] w i int minAbs=Math.abs(latterPartSum[0]-formerPartSum[0]); minAbs Math.abs(latterPartSum[0]-formerPartSum[0]) Math.abs Math latterPartSum[0]-formerPartSum[0] latterPartSum[0] latterPartSum 0 formerPartSum[0] formerPartSum 0 for(int i=0;i<n;i++){
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        } {
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        } latterPartSum[i+1]=latterPartSum[i]-w[i] latterPartSum[i+1] latterPartSum i+1 i 1 latterPartSum[i]-w[i] latterPartSum[i] latterPartSum i w[i] w i formerPartSum[i+1]=formerPartSum[i]+w[i] formerPartSum[i+1] formerPartSum i+1 i 1 formerPartSum[i]+w[i] formerPartSum[i] formerPartSum i w[i] w i int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]); minAbsCandidate Math.abs(latterPartSum[i]-formerPartSum[i]) Math.abs Math latterPartSum[i]-formerPartSum[i] latterPartSum[i] latterPartSum i formerPartSum[i] formerPartSum i minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate minAbs minAbs<=minAbsCandidate?minAbs:minAbsCandidate minAbs<=minAbsCandidate minAbs minAbsCandidate minAbs minAbsCandidate System.out.println(minAbs) System.out.println System.out System System.out minAbs String args[] args public class Main{

    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());

        int n =sc.nextInt();
        int[] w = new int[n];
        for(int i=0;i<n;i++){
            w[i]=sc.nextInt();
        }
        sc.close();

        int formerPartSum[]= new int[n+1];
        int latterPartSum[]= new int[n+1];

        formerPartSum[0]=0;
        for(int i=0;i<n;i++){
            latterPartSum[0]+=w[i];
        }

        int minAbs=Math.abs(latterPartSum[0]-formerPartSum[0]);

        for(int i=0;i<n;i++){
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        }
        System.out.println(minAbs);
    }


} public class Main{

    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());

        int n =sc.nextInt();
        int[] w = new int[n];
        for(int i=0;i<n;i++){
            w[i]=sc.nextInt();
        }
        sc.close();

        int formerPartSum[]= new int[n+1];
        int latterPartSum[]= new int[n+1];

        formerPartSum[0]=0;
        for(int i=0;i<n;i++){
            latterPartSum[0]+=w[i];
        }

        int minAbs=Math.abs(latterPartSum[0]-formerPartSum[0]);

        for(int i=0;i<n;i++){
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        }
        System.out.println(minAbs);
    }


} Main
import java.util.*;
//import java.io.*;


public class Main{

    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        // try{
            // int n = Integer.parseInt(br.readLine());

        int n =sc.nextInt();
        int[] w = new int[n];
        for(int i=0;i<n;i++){
            w[i]=sc.nextInt();
        }
        sc.close();

        int formerPartSum[]= new int[n+1];
        int latterPartSum[]= new int[n+1];

        formerPartSum[0]=0;
        for(int i=0;i<n;i++){
            latterPartSum[0]+=w[i];
        }

        int minAbs=Math.abs(latterPartSum[0]-formerPartSum[0]);

        for(int i=0;i<n;i++){
            latterPartSum[i+1]=latterPartSum[i]-w[i];
            formerPartSum[i+1]=formerPartSum[i]+w[i];
            int minAbsCandidate=Math.abs(latterPartSum[i]-formerPartSum[i]);
            minAbs= minAbs<=minAbsCandidate?minAbs:minAbsCandidate;
        }
        System.out.println(minAbs);
    }


}