import java.util.Scanner;

public class Main {

    private static final Scanner  SC = new Scanner(System.in);
    private static final int ELEMENTS = SC.nextInt();
    private static final int[]  VALUE = load(SC);
    private static int[] load(Scanner sc){
        int[] value = new int[ELEMENTS];
        for (int i = 0; i < ELEMENTS; i++) {
            value[i] = sc.nextInt();
        }
        return value;
    }

    public static void main(String[] args) {
        int sumOfAll = 0;
        for (int i: VALUE){
            sumOfAll += i;
        }

        int turningPoint = 0;
        int partialSum = 0;
        for (int i=0;i<VALUE.length;i++){
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        }

        int resultA = partialSum-sumOfAll;
        int resultB = sumOfAll-partialSum+2*VALUE[turningPoint];

        System.out.println(Math.min(resultA,resultB));
    }
}
 import java.util.Scanner; Scanner java.util public class Main {

    private static final Scanner  SC = new Scanner(System.in);
    private static final int ELEMENTS = SC.nextInt();
    private static final int[]  VALUE = load(SC);
    private static int[] load(Scanner sc){
        int[] value = new int[ELEMENTS];
        for (int i = 0; i < ELEMENTS; i++) {
            value[i] = sc.nextInt();
        }
        return value;
    }

    public static void main(String[] args) {
        int sumOfAll = 0;
        for (int i: VALUE){
            sumOfAll += i;
        }

        int turningPoint = 0;
        int partialSum = 0;
        for (int i=0;i<VALUE.length;i++){
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        }

        int resultA = partialSum-sumOfAll;
        int resultB = sumOfAll-partialSum+2*VALUE[turningPoint];

        System.out.println(Math.min(resultA,resultB));
    }
} Main private static final Scanner  SC = new Scanner(System.in); SC new Scanner(System.in) private static final int ELEMENTS = SC.nextInt(); ELEMENTS SC.nextInt() SC.nextInt SC private static final int[]  VALUE = load(SC); VALUE load(SC) load SC private static int[] load(Scanner sc){
        int[] value = new int[ELEMENTS];
        for (int i = 0; i < ELEMENTS; i++) {
            value[i] = sc.nextInt();
        }
        return value;
    } load {
        int[] value = new int[ELEMENTS];
        for (int i = 0; i < ELEMENTS; i++) {
            value[i] = sc.nextInt();
        }
        return value;
    } int[] value = new int[ELEMENTS]; value new int[ELEMENTS] ELEMENTS for (int i = 0; i < ELEMENTS; i++) {
            value[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < ELEMENTS i ELEMENTS i++ i++ i {
            value[i] = sc.nextInt();
        } {
            value[i] = sc.nextInt();
        } value[i] = sc.nextInt() value[i] value i sc.nextInt() sc.nextInt sc return value; value Scanner sc sc public static void main(String[] args) {
        int sumOfAll = 0;
        for (int i: VALUE){
            sumOfAll += i;
        }

        int turningPoint = 0;
        int partialSum = 0;
        for (int i=0;i<VALUE.length;i++){
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        }

        int resultA = partialSum-sumOfAll;
        int resultB = sumOfAll-partialSum+2*VALUE[turningPoint];

        System.out.println(Math.min(resultA,resultB));
    } main {
        int sumOfAll = 0;
        for (int i: VALUE){
            sumOfAll += i;
        }

        int turningPoint = 0;
        int partialSum = 0;
        for (int i=0;i<VALUE.length;i++){
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        }

        int resultA = partialSum-sumOfAll;
        int resultB = sumOfAll-partialSum+2*VALUE[turningPoint];

        System.out.println(Math.min(resultA,resultB));
    } int sumOfAll = 0; sumOfAll 0 for (int i: VALUE){
            sumOfAll += i;
        } int i VALUE {
            sumOfAll += i;
        } {
            sumOfAll += i;
        } sumOfAll += i sumOfAll i int turningPoint = 0; turningPoint 0 int partialSum = 0; partialSum 0 for (int i=0;i<VALUE.length;i++){
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        } int i=0; int i=0; i 0 i<VALUE.length i VALUE.length VALUE VALUE.length i++ i++ i {
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        } {
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        } partialSum += VALUE[i] partialSum VALUE[i] VALUE i sumOfAll -= VALUE[i] sumOfAll VALUE[i] VALUE i if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            } sumOfAll-partialSum<0 sumOfAll-partialSum sumOfAll partialSum 0 {
                turningPoint = i;
                break;
            } turningPoint = i turningPoint i break; int resultA = partialSum-sumOfAll; resultA partialSum-sumOfAll partialSum sumOfAll int resultB = sumOfAll-partialSum+2*VALUE[turningPoint]; resultB sumOfAll-partialSum+2*VALUE[turningPoint] sumOfAll-partialSum sumOfAll partialSum 2*VALUE[turningPoint] 2 VALUE[turningPoint] VALUE turningPoint System.out.println(Math.min(resultA,resultB)) System.out.println System.out System System.out Math.min(resultA,resultB) Math.min Math resultA resultB String[] args args public class Main {

    private static final Scanner  SC = new Scanner(System.in);
    private static final int ELEMENTS = SC.nextInt();
    private static final int[]  VALUE = load(SC);
    private static int[] load(Scanner sc){
        int[] value = new int[ELEMENTS];
        for (int i = 0; i < ELEMENTS; i++) {
            value[i] = sc.nextInt();
        }
        return value;
    }

    public static void main(String[] args) {
        int sumOfAll = 0;
        for (int i: VALUE){
            sumOfAll += i;
        }

        int turningPoint = 0;
        int partialSum = 0;
        for (int i=0;i<VALUE.length;i++){
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        }

        int resultA = partialSum-sumOfAll;
        int resultB = sumOfAll-partialSum+2*VALUE[turningPoint];

        System.out.println(Math.min(resultA,resultB));
    }
} public class Main {

    private static final Scanner  SC = new Scanner(System.in);
    private static final int ELEMENTS = SC.nextInt();
    private static final int[]  VALUE = load(SC);
    private static int[] load(Scanner sc){
        int[] value = new int[ELEMENTS];
        for (int i = 0; i < ELEMENTS; i++) {
            value[i] = sc.nextInt();
        }
        return value;
    }

    public static void main(String[] args) {
        int sumOfAll = 0;
        for (int i: VALUE){
            sumOfAll += i;
        }

        int turningPoint = 0;
        int partialSum = 0;
        for (int i=0;i<VALUE.length;i++){
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        }

        int resultA = partialSum-sumOfAll;
        int resultB = sumOfAll-partialSum+2*VALUE[turningPoint];

        System.out.println(Math.min(resultA,resultB));
    }
} Main
import java.util.Scanner;

public class Main {

    private static final Scanner  SC = new Scanner(System.in);
    private static final int ELEMENTS = SC.nextInt();
    private static final int[]  VALUE = load(SC);
    private static int[] load(Scanner sc){
        int[] value = new int[ELEMENTS];
        for (int i = 0; i < ELEMENTS; i++) {
            value[i] = sc.nextInt();
        }
        return value;
    }

    public static void main(String[] args) {
        int sumOfAll = 0;
        for (int i: VALUE){
            sumOfAll += i;
        }

        int turningPoint = 0;
        int partialSum = 0;
        for (int i=0;i<VALUE.length;i++){
            partialSum += VALUE[i];
            sumOfAll -= VALUE[i];
            if(sumOfAll-partialSum<0){
                turningPoint = i;
                break;
            }
        }

        int resultA = partialSum-sumOfAll;
        int resultB = sumOfAll-partialSum+2*VALUE[turningPoint];

        System.out.println(Math.min(resultA,resultB));
    }
}

