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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int count = Integer.parseInt(sc.next());
		ArrayList<Integer> integers = new ArrayList<Integer>(count);
		for (int i = 0; i < count; i++) {
			integers.add(Integer.parseInt(sc.next()));
		}
		int left = 0;
		int right = 0;
		for (int i = 0; i < count; i++) {
			if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			}
		}

		if(right>=left) {
			System.out.println(right-left);
		}else {
			System.out.println(left-right);
		}
		sc.close();
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int count = Integer.parseInt(sc.next());
		ArrayList<Integer> integers = new ArrayList<Integer>(count);
		for (int i = 0; i < count; i++) {
			integers.add(Integer.parseInt(sc.next()));
		}
		int left = 0;
		int right = 0;
		for (int i = 0; i < count; i++) {
			if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			}
		}

		if(right>=left) {
			System.out.println(right-left);
		}else {
			System.out.println(left-right);
		}
		sc.close();
	}
} Main public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int count = Integer.parseInt(sc.next());
		ArrayList<Integer> integers = new ArrayList<Integer>(count);
		for (int i = 0; i < count; i++) {
			integers.add(Integer.parseInt(sc.next()));
		}
		int left = 0;
		int right = 0;
		for (int i = 0; i < count; i++) {
			if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			}
		}

		if(right>=left) {
			System.out.println(right-left);
		}else {
			System.out.println(left-right);
		}
		sc.close();
	} main {

		Scanner sc = new Scanner(System.in);
		int count = Integer.parseInt(sc.next());
		ArrayList<Integer> integers = new ArrayList<Integer>(count);
		for (int i = 0; i < count; i++) {
			integers.add(Integer.parseInt(sc.next()));
		}
		int left = 0;
		int right = 0;
		for (int i = 0; i < count; i++) {
			if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			}
		}

		if(right>=left) {
			System.out.println(right-left);
		}else {
			System.out.println(left-right);
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int count = Integer.parseInt(sc.next()); count Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc ArrayList<Integer> integers = new ArrayList<Integer>(count); integers new ArrayList<Integer>(count) for (int i = 0; i < count; i++) {
			integers.add(Integer.parseInt(sc.next()));
		} int i = 0; int i = 0; i 0 i < count i count i++ i++ i {
			integers.add(Integer.parseInt(sc.next()));
		} {
			integers.add(Integer.parseInt(sc.next()));
		} integers.add(Integer.parseInt(sc.next())) integers.add integers Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int left = 0; left 0 int right = 0; right 0 for (int i = 0; i < count; i++) {
			if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			}
		} int i = 0; int i = 0; i 0 i < count i count i++ i++ i {
			if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			}
		} {
			if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			}
		} if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			} right <= left right left {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} int size = integers.size() - 1; size integers.size() - 1 integers.size() integers.size integers 1 right += integers.get(size) right integers.get(size) integers.get integers size integers.remove(size) integers.remove integers size {
				left += integers.get(0);
				integers.remove(0);
			} left += integers.get(0) left integers.get(0) integers.get integers 0 integers.remove(0) integers.remove integers 0 if(right>=left) {
			System.out.println(right-left);
		}else {
			System.out.println(left-right);
		} right>=left right left {
			System.out.println(right-left);
		} System.out.println(right-left) System.out.println System.out System System.out right-left right left {
			System.out.println(left-right);
		} System.out.println(left-right) System.out.println System.out System System.out left-right left right sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int count = Integer.parseInt(sc.next());
		ArrayList<Integer> integers = new ArrayList<Integer>(count);
		for (int i = 0; i < count; i++) {
			integers.add(Integer.parseInt(sc.next()));
		}
		int left = 0;
		int right = 0;
		for (int i = 0; i < count; i++) {
			if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			}
		}

		if(right>=left) {
			System.out.println(right-left);
		}else {
			System.out.println(left-right);
		}
		sc.close();
	}
} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int count = Integer.parseInt(sc.next());
		ArrayList<Integer> integers = new ArrayList<Integer>(count);
		for (int i = 0; i < count; i++) {
			integers.add(Integer.parseInt(sc.next()));
		}
		int left = 0;
		int right = 0;
		for (int i = 0; i < count; i++) {
			if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			}
		}

		if(right>=left) {
			System.out.println(right-left);
		}else {
			System.out.println(left-right);
		}
		sc.close();
	}
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int count = Integer.parseInt(sc.next());
		ArrayList<Integer> integers = new ArrayList<Integer>(count);
		for (int i = 0; i < count; i++) {
			integers.add(Integer.parseInt(sc.next()));
		}
		int left = 0;
		int right = 0;
		for (int i = 0; i < count; i++) {
			if (right <= left) {
				int size = integers.size() - 1;
				right += integers.get(size);
				integers.remove(size);
			} else {
				left += integers.get(0);
				integers.remove(0);
			}
		}

		if(right>=left) {
			System.out.println(right-left);
		}else {
			System.out.println(left-right);
		}
		sc.close();
	}
}
