import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        int[] ruiseki = new int[n+1];
        for (int i = 0; i <= n; i++) {
            ruiseki[i] = 0;
        }
        int res = Integer.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            ruiseki[i] = ar[i-1]+ruiseki[i-1];
        }

        for (int i = 1; i <= n; i++) {
            res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])));
        }
        System.out.println(res);

    }
}

class io{
    public static void br(){
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }

}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}
 import java.util.*; util.* java import java.math.*; math.* java import java.io.*; io.* java import java.lang.*; lang.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        int[] ruiseki = new int[n+1];
        for (int i = 0; i <= n; i++) {
            ruiseki[i] = 0;
        }
        int res = Integer.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            ruiseki[i] = ar[i-1]+ruiseki[i-1];
        }

        for (int i = 1; i <= n; i++) {
            res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])));
        }
        System.out.println(res);

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        int[] ruiseki = new int[n+1];
        for (int i = 0; i <= n; i++) {
            ruiseki[i] = 0;
        }
        int res = Integer.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            ruiseki[i] = ar[i-1]+ruiseki[i-1];
        }

        for (int i = 1; i <= n; i++) {
            res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])));
        }
        System.out.println(res);

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        int[] ruiseki = new int[n+1];
        for (int i = 0; i <= n; i++) {
            ruiseki[i] = 0;
        }
        int res = Integer.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            ruiseki[i] = ar[i-1]+ruiseki[i-1];
        }

        for (int i = 1; i <= n; i++) {
            res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])));
        }
        System.out.println(res);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] ar = new int[n]; ar new int[n] n for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            ar[i] = sc.nextInt();
        } {
            ar[i] = sc.nextInt();
        } ar[i] = sc.nextInt() ar[i] ar i sc.nextInt() sc.nextInt sc int[] ruiseki = new int[n+1]; ruiseki new int[n+1] n+1 n 1 for (int i = 0; i <= n; i++) {
            ruiseki[i] = 0;
        } int i = 0; int i = 0; i 0 i <= n i n i++ i++ i {
            ruiseki[i] = 0;
        } {
            ruiseki[i] = 0;
        } ruiseki[i] = 0 ruiseki[i] ruiseki i 0 int res = Integer.MAX_VALUE; res Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 1; i <= n; i++) {
            ruiseki[i] = ar[i-1]+ruiseki[i-1];
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            ruiseki[i] = ar[i-1]+ruiseki[i-1];
        } {
            ruiseki[i] = ar[i-1]+ruiseki[i-1];
        } ruiseki[i] = ar[i-1]+ruiseki[i-1] ruiseki[i] ruiseki i ar[i-1]+ruiseki[i-1] ar[i-1] ar i-1 i 1 ruiseki[i-1] ruiseki i-1 i 1 for (int i = 1; i <= n; i++) {
            res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])));
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])));
        } {
            res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])));
        } res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i]))) res Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i]))) Math.min Math res Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])) Math.abs Math ruiseki[i] - (ruiseki[n] - ruiseki[i]) ruiseki[i] ruiseki i (ruiseki[n] - ruiseki[i]) ruiseki[n] ruiseki n ruiseki[i] ruiseki i System.out.println(res) System.out.println System.out System System.out res String[] args args class io{
    public static void br(){
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }

} io public static void br(){
        System.out.println("");
    } br {
        System.out.println("");
    } System.out.println("") System.out.println System.out System System.out "" public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    } YesNo {
        System.out.println(f?"Yes":"No");
    } System.out.println(f?"Yes":"No") System.out.println System.out System System.out f?"Yes":"No" f "Yes" "No" boolean f f public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    } YESNO {
        System.out.println(f?"YES":"NO");
    } System.out.println(f?"YES":"NO") System.out.println System.out System System.out f?"YES":"NO" f "YES" "NO" boolean f f class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


} Algo public static boolean isOdd(int n){
        return n % 2 == 1;
    } isOdd {
        return n % 2 == 1;
    } return n % 2 == 1; n % 2 == 1 n % 2 n 2 1 int n n public static boolean isEven(int n){
        return n % 2 == 0;
    } isEven {
        return n % 2 == 0;
    } return n % 2 == 0; n % 2 == 0 n % 2 n 2 0 int n n public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        int[] ruiseki = new int[n+1];
        for (int i = 0; i <= n; i++) {
            ruiseki[i] = 0;
        }
        int res = Integer.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            ruiseki[i] = ar[i-1]+ruiseki[i-1];
        }

        for (int i = 1; i <= n; i++) {
            res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])));
        }
        System.out.println(res);

    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        int[] ruiseki = new int[n+1];
        for (int i = 0; i <= n; i++) {
            ruiseki[i] = 0;
        }
        int res = Integer.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            ruiseki[i] = ar[i-1]+ruiseki[i-1];
        }

        for (int i = 1; i <= n; i++) {
            res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])));
        }
        System.out.println(res);

    }
} Main
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] ar = new int[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt();
        }
        int[] ruiseki = new int[n+1];
        for (int i = 0; i <= n; i++) {
            ruiseki[i] = 0;
        }
        int res = Integer.MAX_VALUE;
        for (int i = 1; i <= n; i++) {
            ruiseki[i] = ar[i-1]+ruiseki[i-1];
        }

        for (int i = 1; i <= n; i++) {
            res = Math.min(res, Math.abs(ruiseki[i] - (ruiseki[n] - ruiseki[i])));
        }
        System.out.println(res);

    }
}

class io{
    public static void br(){
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f?"Yes":"No");
    }
    public static void YESNO(boolean f) {
        System.out.println(f?"YES":"NO");
    }

}

class Algo{
    public static boolean isOdd(int n){
        return n % 2 == 1;
    }
    public static boolean isEven(int n){
        return n % 2 == 0;
    }


}

