import java.util.*;
public class Main {
	public static void main(String[] args){
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> W = new ArrayList<>();
	    for (int i = 0; i < N; i++) {
	      W.add(sc.nextInt());
	    }
		sc.close();

		Integer A = 0;
		Integer B = 0;

		while (W.size() != 0) {
			if(A < B){
				A += W.get(0);
				W.remove(0);
			} else {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			}
		}
		
		System.out.println(Math.abs(A-B));
	
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> W = new ArrayList<>();
	    for (int i = 0; i < N; i++) {
	      W.add(sc.nextInt());
	    }
		sc.close();

		Integer A = 0;
		Integer B = 0;

		while (W.size() != 0) {
			if(A < B){
				A += W.get(0);
				W.remove(0);
			} else {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			}
		}
		
		System.out.println(Math.abs(A-B));
	
	}
} Main public static void main(String[] args){
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> W = new ArrayList<>();
	    for (int i = 0; i < N; i++) {
	      W.add(sc.nextInt());
	    }
		sc.close();

		Integer A = 0;
		Integer B = 0;

		while (W.size() != 0) {
			if(A < B){
				A += W.get(0);
				W.remove(0);
			} else {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			}
		}
		
		System.out.println(Math.abs(A-B));
	
	} main {
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> W = new ArrayList<>();
	    for (int i = 0; i < N; i++) {
	      W.add(sc.nextInt());
	    }
		sc.close();

		Integer A = 0;
		Integer B = 0;

		while (W.size() != 0) {
			if(A < B){
				A += W.get(0);
				W.remove(0);
			} else {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			}
		}
		
		System.out.println(Math.abs(A-B));
	
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc ArrayList<Integer> W = new ArrayList<>(); W new ArrayList<>() for (int i = 0; i < N; i++) {
	      W.add(sc.nextInt());
	    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
	      W.add(sc.nextInt());
	    } {
	      W.add(sc.nextInt());
	    } W.add(sc.nextInt()) W.add W sc.nextInt() sc.nextInt sc sc.close() sc.close sc Integer A = 0; A 0 Integer B = 0; B 0 while (W.size() != 0) {
			if(A < B){
				A += W.get(0);
				W.remove(0);
			} else {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			}
		} W.size() != 0 W.size() W.size W 0 {
			if(A < B){
				A += W.get(0);
				W.remove(0);
			} else {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			}
		} if(A < B){
				A += W.get(0);
				W.remove(0);
			} else {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			} A < B A B {
				A += W.get(0);
				W.remove(0);
			} A += W.get(0) A W.get(0) W.get W 0 W.remove(0) W.remove W 0 {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			} B += W.get(W.size() - 1) B W.get(W.size() - 1) W.get W W.size() - 1 W.size() W.size W 1 W.remove(W.size() - 1) W.remove W W.size() - 1 W.size() W.size W 1 System.out.println(Math.abs(A-B)) System.out.println System.out System System.out Math.abs(A-B) Math.abs Math A-B A B String[] args args public class Main {
	public static void main(String[] args){
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> W = new ArrayList<>();
	    for (int i = 0; i < N; i++) {
	      W.add(sc.nextInt());
	    }
		sc.close();

		Integer A = 0;
		Integer B = 0;

		while (W.size() != 0) {
			if(A < B){
				A += W.get(0);
				W.remove(0);
			} else {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			}
		}
		
		System.out.println(Math.abs(A-B));
	
	}
} public class Main {
	public static void main(String[] args){
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> W = new ArrayList<>();
	    for (int i = 0; i < N; i++) {
	      W.add(sc.nextInt());
	    }
		sc.close();

		Integer A = 0;
		Integer B = 0;

		while (W.size() != 0) {
			if(A < B){
				A += W.get(0);
				W.remove(0);
			} else {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			}
		}
		
		System.out.println(Math.abs(A-B));
	
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
	
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		ArrayList<Integer> W = new ArrayList<>();
	    for (int i = 0; i < N; i++) {
	      W.add(sc.nextInt());
	    }
		sc.close();

		Integer A = 0;
		Integer B = 0;

		while (W.size() != 0) {
			if(A < B){
				A += W.get(0);
				W.remove(0);
			} else {
				B += W.get(W.size() - 1);
				W.remove(W.size() - 1);
			}
		}
		
		System.out.println(Math.abs(A-B));
	
	}
}