import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int data[] = new int[n];

        for (int i = 0; i < n; i++) {
            data[i] = sc.nextInt();
        }

        int s1 = 0;
        int s2 = 0;

        int index = 0;
        int i = 0;
        int j = n - 1;

        while (index < n) {
            if (s1 < s2) {
                s1 += data[i];
                i++;
            } else {
                s2 += data[j];
                j--;
            }
            index++;
        }

        if (s1 >= s2) {
            System.out.println(s1 - s2);
        } else {
            System.out.println(s2 - s1);
        }
	}
} 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 data[] = new int[n];

        for (int i = 0; i < n; i++) {
            data[i] = sc.nextInt();
        }

        int s1 = 0;
        int s2 = 0;

        int index = 0;
        int i = 0;
        int j = n - 1;

        while (index < n) {
            if (s1 < s2) {
                s1 += data[i];
                i++;
            } else {
                s2 += data[j];
                j--;
            }
            index++;
        }

        if (s1 >= s2) {
            System.out.println(s1 - s2);
        } else {
            System.out.println(s2 - s1);
        }
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int data[] = new int[n];

        for (int i = 0; i < n; i++) {
            data[i] = sc.nextInt();
        }

        int s1 = 0;
        int s2 = 0;

        int index = 0;
        int i = 0;
        int j = n - 1;

        while (index < n) {
            if (s1 < s2) {
                s1 += data[i];
                i++;
            } else {
                s2 += data[j];
                j--;
            }
            index++;
        }

        if (s1 >= s2) {
            System.out.println(s1 - s2);
        } else {
            System.out.println(s2 - s1);
        }
	} main {
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int data[] = new int[n];

        for (int i = 0; i < n; i++) {
            data[i] = sc.nextInt();
        }

        int s1 = 0;
        int s2 = 0;

        int index = 0;
        int i = 0;
        int j = n - 1;

        while (index < n) {
            if (s1 < s2) {
                s1 += data[i];
                i++;
            } else {
                s2 += data[j];
                j--;
            }
            index++;
        }

        if (s1 >= s2) {
            System.out.println(s1 - s2);
        } else {
            System.out.println(s2 - s1);
        }
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int data[] = new int[n]; data new int[n] n for (int i = 0; i < n; i++) {
            data[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            data[i] = sc.nextInt();
        } {
            data[i] = sc.nextInt();
        } data[i] = sc.nextInt() data[i] data i sc.nextInt() sc.nextInt sc int s1 = 0; s1 0 int s2 = 0; s2 0 int index = 0; index 0 int i = 0; i 0 int j = n - 1; j n - 1 n 1 while (index < n) {
            if (s1 < s2) {
                s1 += data[i];
                i++;
            } else {
                s2 += data[j];
                j--;
            }
            index++;
        } index < n index n {
            if (s1 < s2) {
                s1 += data[i];
                i++;
            } else {
                s2 += data[j];
                j--;
            }
            index++;
        } if (s1 < s2) {
                s1 += data[i];
                i++;
            } else {
                s2 += data[j];
                j--;
            } s1 < s2 s1 s2 {
                s1 += data[i];
                i++;
            } s1 += data[i] s1 data[i] data i i++ i {
                s2 += data[j];
                j--;
            } s2 += data[j] s2 data[j] data j j-- j index++ index if (s1 >= s2) {
            System.out.println(s1 - s2);
        } else {
            System.out.println(s2 - s1);
        } s1 >= s2 s1 s2 {
            System.out.println(s1 - s2);
        } System.out.println(s1 - s2) System.out.println System.out System System.out s1 - s2 s1 s2 {
            System.out.println(s2 - s1);
        } System.out.println(s2 - s1) System.out.println System.out System System.out s2 - s1 s2 s1 String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int data[] = new int[n];

        for (int i = 0; i < n; i++) {
            data[i] = sc.nextInt();
        }

        int s1 = 0;
        int s2 = 0;

        int index = 0;
        int i = 0;
        int j = n - 1;

        while (index < n) {
            if (s1 < s2) {
                s1 += data[i];
                i++;
            } else {
                s2 += data[j];
                j--;
            }
            index++;
        }

        if (s1 >= s2) {
            System.out.println(s1 - s2);
        } else {
            System.out.println(s2 - s1);
        }
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int data[] = new int[n];

        for (int i = 0; i < n; i++) {
            data[i] = sc.nextInt();
        }

        int s1 = 0;
        int s2 = 0;

        int index = 0;
        int i = 0;
        int j = n - 1;

        while (index < n) {
            if (s1 < s2) {
                s1 += data[i];
                i++;
            } else {
                s2 += data[j];
                j--;
            }
            index++;
        }

        if (s1 >= s2) {
            System.out.println(s1 - s2);
        } else {
            System.out.println(s2 - s1);
        }
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int data[] = new int[n];

        for (int i = 0; i < n; i++) {
            data[i] = sc.nextInt();
        }

        int s1 = 0;
        int s2 = 0;

        int index = 0;
        int i = 0;
        int j = n - 1;

        while (index < n) {
            if (s1 < s2) {
                s1 += data[i];
                i++;
            } else {
                s2 += data[j];
                j--;
            }
            index++;
        }

        if (s1 >= s2) {
            System.out.println(s1 - s2);
        } else {
            System.out.println(s2 - s1);
        }
	}
}