import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int weightNum = sc.nextInt();

        int[] weights = new int[weightNum];
        int total = 0;
        for(int i = 0; i < weightNum; i++){
            weights[i] = sc.nextInt();
            total += weights[i];
        }

        int index = 0;
        int sum = 0;
        while(sum < total / 2){
            sum += weights[index];
            index++;
        }
        int ans = minDiff(index, weights, weightNum);
        ans = Math.min(ans,minDiff(index-1, weights, weightNum));
        System.out.println(ans);
    }

    public static int minDiff(int index, int[] weights, int weightNum){
        int ans = 0;
        for(int i = 0; i < index; i++){
            ans += weights[i];
        }
        for(int i = index; i < weightNum; i++){
            ans -= weights[i];
        }
        return Math.abs(ans);
    }

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

        int[] weights = new int[weightNum];
        int total = 0;
        for(int i = 0; i < weightNum; i++){
            weights[i] = sc.nextInt();
            total += weights[i];
        }

        int index = 0;
        int sum = 0;
        while(sum < total / 2){
            sum += weights[index];
            index++;
        }
        int ans = minDiff(index, weights, weightNum);
        ans = Math.min(ans,minDiff(index-1, weights, weightNum));
        System.out.println(ans);
    }

    public static int minDiff(int index, int[] weights, int weightNum){
        int ans = 0;
        for(int i = 0; i < index; i++){
            ans += weights[i];
        }
        for(int i = index; i < weightNum; i++){
            ans -= weights[i];
        }
        return Math.abs(ans);
    }

} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int weightNum = sc.nextInt();

        int[] weights = new int[weightNum];
        int total = 0;
        for(int i = 0; i < weightNum; i++){
            weights[i] = sc.nextInt();
            total += weights[i];
        }

        int index = 0;
        int sum = 0;
        while(sum < total / 2){
            sum += weights[index];
            index++;
        }
        int ans = minDiff(index, weights, weightNum);
        ans = Math.min(ans,minDiff(index-1, weights, weightNum));
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int weightNum = sc.nextInt();

        int[] weights = new int[weightNum];
        int total = 0;
        for(int i = 0; i < weightNum; i++){
            weights[i] = sc.nextInt();
            total += weights[i];
        }

        int index = 0;
        int sum = 0;
        while(sum < total / 2){
            sum += weights[index];
            index++;
        }
        int ans = minDiff(index, weights, weightNum);
        ans = Math.min(ans,minDiff(index-1, weights, weightNum));
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int weightNum = sc.nextInt(); weightNum sc.nextInt() sc.nextInt sc int[] weights = new int[weightNum]; weights new int[weightNum] weightNum int total = 0; total 0 for(int i = 0; i < weightNum; i++){
            weights[i] = sc.nextInt();
            total += weights[i];
        } int i = 0; int i = 0; i 0 i < weightNum i weightNum i++ i++ i {
            weights[i] = sc.nextInt();
            total += weights[i];
        } {
            weights[i] = sc.nextInt();
            total += weights[i];
        } weights[i] = sc.nextInt() weights[i] weights i sc.nextInt() sc.nextInt sc total += weights[i] total weights[i] weights i int index = 0; index 0 int sum = 0; sum 0 while(sum < total / 2){
            sum += weights[index];
            index++;
        } sum < total / 2 sum total / 2 total 2 {
            sum += weights[index];
            index++;
        } sum += weights[index] sum weights[index] weights index index++ index int ans = minDiff(index, weights, weightNum); ans minDiff(index, weights, weightNum) minDiff index weights weightNum ans = Math.min(ans,minDiff(index-1, weights, weightNum)) ans Math.min(ans,minDiff(index-1, weights, weightNum)) Math.min Math ans minDiff(index-1, weights, weightNum) minDiff index-1 index 1 weights weightNum System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static int minDiff(int index, int[] weights, int weightNum){
        int ans = 0;
        for(int i = 0; i < index; i++){
            ans += weights[i];
        }
        for(int i = index; i < weightNum; i++){
            ans -= weights[i];
        }
        return Math.abs(ans);
    } minDiff {
        int ans = 0;
        for(int i = 0; i < index; i++){
            ans += weights[i];
        }
        for(int i = index; i < weightNum; i++){
            ans -= weights[i];
        }
        return Math.abs(ans);
    } int ans = 0; ans 0 for(int i = 0; i < index; i++){
            ans += weights[i];
        } int i = 0; int i = 0; i 0 i < index i index i++ i++ i {
            ans += weights[i];
        } {
            ans += weights[i];
        } ans += weights[i] ans weights[i] weights i for(int i = index; i < weightNum; i++){
            ans -= weights[i];
        } int i = index; int i = index; i index i < weightNum i weightNum i++ i++ i {
            ans -= weights[i];
        } {
            ans -= weights[i];
        } ans -= weights[i] ans weights[i] weights i return Math.abs(ans); Math.abs(ans) Math.abs Math ans int index index int[] weights weights int weightNum weightNum
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int weightNum = sc.nextInt();

        int[] weights = new int[weightNum];
        int total = 0;
        for(int i = 0; i < weightNum; i++){
            weights[i] = sc.nextInt();
            total += weights[i];
        }

        int index = 0;
        int sum = 0;
        while(sum < total / 2){
            sum += weights[index];
            index++;
        }
        int ans = minDiff(index, weights, weightNum);
        ans = Math.min(ans,minDiff(index-1, weights, weightNum));
        System.out.println(ans);
    }

    public static int minDiff(int index, int[] weights, int weightNum){
        int ans = 0;
        for(int i = 0; i < index; i++){
            ans += weights[i];
        }
        for(int i = index; i < weightNum; i++){
            ans -= weights[i];
        }
        return Math.abs(ans);
    }

}
