import java.util.ArrayList;
import java.util.Scanner;

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

        int N = scanner.nextInt();

        ArrayList<Integer> series = new ArrayList<>();


        ArrayList<Integer> accs = new ArrayList<>();

        int acc = 0;

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            series.add(tmp);
            acc += tmp;
            accs.add(acc);
        }


        int minDiff = Integer.MAX_VALUE;

        for(int tmpAcc: accs){
            int rest = acc - tmpAcc;

            int tmpDiff = Math.abs(rest - tmpAcc);

            if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            }
        }

        System.out.println(minDiff);

    }
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        ArrayList<Integer> series = new ArrayList<>();


        ArrayList<Integer> accs = new ArrayList<>();

        int acc = 0;

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            series.add(tmp);
            acc += tmp;
            accs.add(acc);
        }


        int minDiff = Integer.MAX_VALUE;

        for(int tmpAcc: accs){
            int rest = acc - tmpAcc;

            int tmpDiff = Math.abs(rest - tmpAcc);

            if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            }
        }

        System.out.println(minDiff);

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

        int N = scanner.nextInt();

        ArrayList<Integer> series = new ArrayList<>();


        ArrayList<Integer> accs = new ArrayList<>();

        int acc = 0;

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            series.add(tmp);
            acc += tmp;
            accs.add(acc);
        }


        int minDiff = Integer.MAX_VALUE;

        for(int tmpAcc: accs){
            int rest = acc - tmpAcc;

            int tmpDiff = Math.abs(rest - tmpAcc);

            if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            }
        }

        System.out.println(minDiff);

    } main {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        ArrayList<Integer> series = new ArrayList<>();


        ArrayList<Integer> accs = new ArrayList<>();

        int acc = 0;

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            series.add(tmp);
            acc += tmp;
            accs.add(acc);
        }


        int minDiff = Integer.MAX_VALUE;

        for(int tmpAcc: accs){
            int rest = acc - tmpAcc;

            int tmpDiff = Math.abs(rest - tmpAcc);

            if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            }
        }

        System.out.println(minDiff);

    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner ArrayList<Integer> series = new ArrayList<>(); series new ArrayList<>() ArrayList<Integer> accs = new ArrayList<>(); accs new ArrayList<>() int acc = 0; acc 0 for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            series.add(tmp);
            acc += tmp;
            accs.add(acc);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            int tmp = scanner.nextInt();
            series.add(tmp);
            acc += tmp;
            accs.add(acc);
        } {
            int tmp = scanner.nextInt();
            series.add(tmp);
            acc += tmp;
            accs.add(acc);
        } int tmp = scanner.nextInt(); tmp scanner.nextInt() scanner.nextInt scanner series.add(tmp) series.add series tmp acc += tmp acc tmp accs.add(acc) accs.add accs acc int minDiff = Integer.MAX_VALUE; minDiff Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int tmpAcc: accs){
            int rest = acc - tmpAcc;

            int tmpDiff = Math.abs(rest - tmpAcc);

            if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            }
        } int tmpAcc accs {
            int rest = acc - tmpAcc;

            int tmpDiff = Math.abs(rest - tmpAcc);

            if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            }
        } {
            int rest = acc - tmpAcc;

            int tmpDiff = Math.abs(rest - tmpAcc);

            if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            }
        } int rest = acc - tmpAcc; rest acc - tmpAcc acc tmpAcc int tmpDiff = Math.abs(rest - tmpAcc); tmpDiff Math.abs(rest - tmpAcc) Math.abs Math rest - tmpAcc rest tmpAcc if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            } tmpDiff < minDiff tmpDiff minDiff {
                minDiff = tmpDiff;
            } minDiff = tmpDiff minDiff tmpDiff System.out.println(minDiff) System.out.println System.out System System.out minDiff String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        ArrayList<Integer> series = new ArrayList<>();


        ArrayList<Integer> accs = new ArrayList<>();

        int acc = 0;

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            series.add(tmp);
            acc += tmp;
            accs.add(acc);
        }


        int minDiff = Integer.MAX_VALUE;

        for(int tmpAcc: accs){
            int rest = acc - tmpAcc;

            int tmpDiff = Math.abs(rest - tmpAcc);

            if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            }
        }

        System.out.println(minDiff);

    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        ArrayList<Integer> series = new ArrayList<>();


        ArrayList<Integer> accs = new ArrayList<>();

        int acc = 0;

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            series.add(tmp);
            acc += tmp;
            accs.add(acc);
        }


        int minDiff = Integer.MAX_VALUE;

        for(int tmpAcc: accs){
            int rest = acc - tmpAcc;

            int tmpDiff = Math.abs(rest - tmpAcc);

            if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            }
        }

        System.out.println(minDiff);

    }
} Main
import java.util.ArrayList;
import java.util.Scanner;

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

        int N = scanner.nextInt();

        ArrayList<Integer> series = new ArrayList<>();


        ArrayList<Integer> accs = new ArrayList<>();

        int acc = 0;

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();
            series.add(tmp);
            acc += tmp;
            accs.add(acc);
        }


        int minDiff = Integer.MAX_VALUE;

        for(int tmpAcc: accs){
            int rest = acc - tmpAcc;

            int tmpDiff = Math.abs(rest - tmpAcc);

            if(tmpDiff < minDiff){
                minDiff = tmpDiff;
            }
        }

        System.out.println(minDiff);

    }
}
