import java.util.*;

public class Main {

    public static List<List<Integer>> switchList;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        int[] s = new int[N + 1];
        s[0] = 0;
        for (int i = 1; i < N + 1; i++) {
            s[i] = a[i - 1] + s[i - 1];
        }

        int min = Integer.MAX_VALUE;
        for (int i = 1; i < N + 1; i++) {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        }

        System.out.println(min);
    }

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

    public static List<List<Integer>> switchList;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        int[] s = new int[N + 1];
        s[0] = 0;
        for (int i = 1; i < N + 1; i++) {
            s[i] = a[i - 1] + s[i - 1];
        }

        int min = Integer.MAX_VALUE;
        for (int i = 1; i < N + 1; i++) {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        }

        System.out.println(min);
    }

} Main public static List<List<Integer>> switchList; switchList public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        int[] s = new int[N + 1];
        s[0] = 0;
        for (int i = 1; i < N + 1; i++) {
            s[i] = a[i - 1] + s[i - 1];
        }

        int min = Integer.MAX_VALUE;
        for (int i = 1; i < N + 1; i++) {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        }

        System.out.println(min);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        int[] s = new int[N + 1];
        s[0] = 0;
        for (int i = 1; i < N + 1; i++) {
            s[i] = a[i - 1] + s[i - 1];
        }

        int min = Integer.MAX_VALUE;
        for (int i = 1; i < N + 1; i++) {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        }

        System.out.println(min);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] a = new int[N]; a new int[N] N for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int[] s = new int[N + 1]; s new int[N + 1] N + 1 N 1 s[0] = 0 s[0] s 0 0 for (int i = 1; i < N + 1; i++) {
            s[i] = a[i - 1] + s[i - 1];
        } int i = 1; int i = 1; i 1 i < N + 1 i N + 1 N 1 i++ i++ i {
            s[i] = a[i - 1] + s[i - 1];
        } {
            s[i] = a[i - 1] + s[i - 1];
        } s[i] = a[i - 1] + s[i - 1] s[i] s i a[i - 1] + s[i - 1] a[i - 1] a i - 1 i 1 s[i - 1] s i - 1 i 1 int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 1; i < N + 1; i++) {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        } int i = 1; int i = 1; i 1 i < N + 1 i N + 1 N 1 i++ i++ i {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        } {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        } int S1 = s[i]; S1 s[i] s i int S2 = s[s.length - 1] - s[i]; S2 s[s.length - 1] - s[i] s[s.length - 1] s s.length - 1 s.length s s.length 1 s[i] s i int diff = Math.abs(S1 - S2); diff Math.abs(S1 - S2) Math.abs Math S1 - S2 S1 S2 min = diff <= min ? diff : min min diff <= min ? diff : min diff <= min diff min diff min System.out.println(min) System.out.println System.out System System.out min String[] args args public class Main {

    public static List<List<Integer>> switchList;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        int[] s = new int[N + 1];
        s[0] = 0;
        for (int i = 1; i < N + 1; i++) {
            s[i] = a[i - 1] + s[i - 1];
        }

        int min = Integer.MAX_VALUE;
        for (int i = 1; i < N + 1; i++) {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        }

        System.out.println(min);
    }

} public class Main {

    public static List<List<Integer>> switchList;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        int[] s = new int[N + 1];
        s[0] = 0;
        for (int i = 1; i < N + 1; i++) {
            s[i] = a[i - 1] + s[i - 1];
        }

        int min = Integer.MAX_VALUE;
        for (int i = 1; i < N + 1; i++) {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        }

        System.out.println(min);
    }

} Main
import java.util.*;

public class Main {

    public static List<List<Integer>> switchList;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();
        int[] s = new int[N + 1];
        s[0] = 0;
        for (int i = 1; i < N + 1; i++) {
            s[i] = a[i - 1] + s[i - 1];
        }

        int min = Integer.MAX_VALUE;
        for (int i = 1; i < N + 1; i++) {
            int S1 = s[i];
            int S2 = s[s.length - 1] - s[i];
            int diff = Math.abs(S1 - S2);
            min = diff <= min ? diff : min;
        }

        System.out.println(min);
    }

}
