import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        }
        int temp = 0;
        int ans = sum;
        for (int i = 0; i < n; i++) {
            temp += ary[i];
            ans = Math.min(ans, Math.abs(sum - temp - temp));
        }
        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        }
        int temp = 0;
        int ans = sum;
        for (int i = 0; i < n; i++) {
            temp += ary[i];
            ans = Math.min(ans, Math.abs(sum - temp - temp));
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        }
        int temp = 0;
        int ans = sum;
        for (int i = 0; i < n; i++) {
            temp += ary[i];
            ans = Math.min(ans, Math.abs(sum - temp - temp));
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        }
        int temp = 0;
        int ans = sum;
        for (int i = 0; i < n; i++) {
            temp += ary[i];
            ans = Math.min(ans, Math.abs(sum - temp - temp));
        }
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] ary = new int[n]; ary new int[n] n int sum = 0; sum 0 for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        } {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        } int a = Integer.parseInt(sc.next()); a Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc ary[i] = a ary[i] ary i a sum += a sum a int temp = 0; temp 0 int ans = sum; ans sum for (int i = 0; i < n; i++) {
            temp += ary[i];
            ans = Math.min(ans, Math.abs(sum - temp - temp));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            temp += ary[i];
            ans = Math.min(ans, Math.abs(sum - temp - temp));
        } {
            temp += ary[i];
            ans = Math.min(ans, Math.abs(sum - temp - temp));
        } temp += ary[i] temp ary[i] ary i ans = Math.min(ans, Math.abs(sum - temp - temp)) ans Math.min(ans, Math.abs(sum - temp - temp)) Math.min Math ans Math.abs(sum - temp - temp) Math.abs Math sum - temp - temp sum - temp - temp sum temp temp System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        }
        int temp = 0;
        int ans = sum;
        for (int i = 0; i < n; i++) {
            temp += ary[i];
            ans = Math.min(ans, Math.abs(sum - temp - temp));
        }
        System.out.println(ans);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        }
        int temp = 0;
        int ans = sum;
        for (int i = 0; i < n; i++) {
            temp += ary[i];
            ans = Math.min(ans, Math.abs(sum - temp - temp));
        }
        System.out.println(ans);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] ary = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc.next());
            ary[i] = a;
            sum += a;
        }
        int temp = 0;
        int ans = sum;
        for (int i = 0; i < n; i++) {
            temp += ary[i];
            ans = Math.min(ans, Math.abs(sum - temp - temp));
        }
        System.out.println(ans);
    }
}