import 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 sum = 0;
        for(int i = 0; i < N; i++) {
            W[i] = sc.nextInt();
            sum += W[i];
        }
        sc.close();

        System.out.println(Balance(N, W, 0, 0, sum));
    }
    public static int Balance(int N, int[] W, int index, int f_sum, int B_sum) {
        if (f_sum + W[index] >= B_sum - W[index]) {
            int distA = B_sum - f_sum;
            int distB = (f_sum + W[index]) - (B_sum - W[index]);
            if (distA > distB) {
                return distB;
            }
            return distA;
        }
        return Balance(N, W, index + 1, f_sum + W[index], B_sum - W[index]);
    }
} import java.util.*; util.* java 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 sum = 0;
        for(int i = 0; i < N; i++) {
            W[i] = sc.nextInt();
            sum += W[i];
        }
        sc.close();

        System.out.println(Balance(N, W, 0, 0, sum));
    }
    public static int Balance(int N, int[] W, int index, int f_sum, int B_sum) {
        if (f_sum + W[index] >= B_sum - W[index]) {
            int distA = B_sum - f_sum;
            int distB = (f_sum + W[index]) - (B_sum - W[index]);
            if (distA > distB) {
                return distB;
            }
            return distA;
        }
        return Balance(N, W, index + 1, f_sum + W[index], B_sum - W[index]);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] W = new int[N];
        int sum = 0;
        for(int i = 0; i < N; i++) {
            W[i] = sc.nextInt();
            sum += W[i];
        }
        sc.close();

        System.out.println(Balance(N, W, 0, 0, sum));
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] W = new int[N];
        int sum = 0;
        for(int i = 0; i < N; i++) {
            W[i] = sc.nextInt();
            sum += W[i];
        }
        sc.close();

        System.out.println(Balance(N, W, 0, 0, sum));
    } 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 sum = 0; sum 0 for(int i = 0; i < N; i++) {
            W[i] = sc.nextInt();
            sum += W[i];
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            W[i] = sc.nextInt();
            sum += W[i];
        } {
            W[i] = sc.nextInt();
            sum += W[i];
        } W[i] = sc.nextInt() W[i] W i sc.nextInt() sc.nextInt sc sum += W[i] sum W[i] W i sc.close() sc.close sc System.out.println(Balance(N, W, 0, 0, sum)) System.out.println System.out System System.out Balance(N, W, 0, 0, sum) Balance N W 0 0 sum String[] args args public static int Balance(int N, int[] W, int index, int f_sum, int B_sum) {
        if (f_sum + W[index] >= B_sum - W[index]) {
            int distA = B_sum - f_sum;
            int distB = (f_sum + W[index]) - (B_sum - W[index]);
            if (distA > distB) {
                return distB;
            }
            return distA;
        }
        return Balance(N, W, index + 1, f_sum + W[index], B_sum - W[index]);
    } Balance {
        if (f_sum + W[index] >= B_sum - W[index]) {
            int distA = B_sum - f_sum;
            int distB = (f_sum + W[index]) - (B_sum - W[index]);
            if (distA > distB) {
                return distB;
            }
            return distA;
        }
        return Balance(N, W, index + 1, f_sum + W[index], B_sum - W[index]);
    } if (f_sum + W[index] >= B_sum - W[index]) {
            int distA = B_sum - f_sum;
            int distB = (f_sum + W[index]) - (B_sum - W[index]);
            if (distA > distB) {
                return distB;
            }
            return distA;
        } f_sum + W[index] >= B_sum - W[index] f_sum + W[index] f_sum W[index] W index B_sum - W[index] B_sum W[index] W index {
            int distA = B_sum - f_sum;
            int distB = (f_sum + W[index]) - (B_sum - W[index]);
            if (distA > distB) {
                return distB;
            }
            return distA;
        } int distA = B_sum - f_sum; distA B_sum - f_sum B_sum f_sum int distB = (f_sum + W[index]) - (B_sum - W[index]); distB (f_sum + W[index]) - (B_sum - W[index]) (f_sum + W[index]) f_sum W[index] W index (B_sum - W[index]) B_sum W[index] W index if (distA > distB) {
                return distB;
            } distA > distB distA distB {
                return distB;
            } return distB; distB return distA; distA return Balance(N, W, index + 1, f_sum + W[index], B_sum - W[index]); Balance(N, W, index + 1, f_sum + W[index], B_sum - W[index]) Balance N W index + 1 index 1 f_sum + W[index] f_sum W[index] W index B_sum - W[index] B_sum W[index] W index int N N int[] W W int index index int f_sum f_sum int B_sum B_sum 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 sum = 0;
        for(int i = 0; i < N; i++) {
            W[i] = sc.nextInt();
            sum += W[i];
        }
        sc.close();

        System.out.println(Balance(N, W, 0, 0, sum));
    }
    public static int Balance(int N, int[] W, int index, int f_sum, int B_sum) {
        if (f_sum + W[index] >= B_sum - W[index]) {
            int distA = B_sum - f_sum;
            int distB = (f_sum + W[index]) - (B_sum - W[index]);
            if (distA > distB) {
                return distB;
            }
            return distA;
        }
        return Balance(N, W, index + 1, f_sum + W[index], B_sum - W[index]);
    }
} 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 sum = 0;
        for(int i = 0; i < N; i++) {
            W[i] = sc.nextInt();
            sum += W[i];
        }
        sc.close();

        System.out.println(Balance(N, W, 0, 0, sum));
    }
    public static int Balance(int N, int[] W, int index, int f_sum, int B_sum) {
        if (f_sum + W[index] >= B_sum - W[index]) {
            int distA = B_sum - f_sum;
            int distB = (f_sum + W[index]) - (B_sum - W[index]);
            if (distA > distB) {
                return distB;
            }
            return distA;
        }
        return Balance(N, W, index + 1, f_sum + W[index], B_sum - W[index]);
    }
} Main
import 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 sum = 0;
        for(int i = 0; i < N; i++) {
            W[i] = sc.nextInt();
            sum += W[i];
        }
        sc.close();

        System.out.println(Balance(N, W, 0, 0, sum));
    }
    public static int Balance(int N, int[] W, int index, int f_sum, int B_sum) {
        if (f_sum + W[index] >= B_sum - W[index]) {
            int distA = B_sum - f_sum;
            int distB = (f_sum + W[index]) - (B_sum - W[index]);
            if (distA > distB) {
                return distB;
            }
            return distA;
        }
        return Balance(N, W, index + 1, f_sum + W[index], B_sum - W[index]);
    }
}
