import java.util.Scanner;

public class Main {
	
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] linea = s.nextLine().split(" ");
		int N=Integer.parseInt(linea[0]);
		int [] A=new int[N];
		String[] linea2 = s.nextLine().split(" ");
		for(int i=0;i<N;i++) {
			A[i]=Integer.parseInt(linea2[i]);
			
		}
		int d=999999999;
		int sum=0;
		for(int j=0;j<N;j++) {
			sum=sum+A[j];
		}
		int sum2=sum;
		int sum1=0;
		for(int k=0;k<N;k++) {
			sum1=sum1+A[k];
			sum2=sum2-A[k];
			if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			}
		}
		System.out.print(d);

}} import java.util.Scanner; Scanner java.util public class Main {
	
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] linea = s.nextLine().split(" ");
		int N=Integer.parseInt(linea[0]);
		int [] A=new int[N];
		String[] linea2 = s.nextLine().split(" ");
		for(int i=0;i<N;i++) {
			A[i]=Integer.parseInt(linea2[i]);
			
		}
		int d=999999999;
		int sum=0;
		for(int j=0;j<N;j++) {
			sum=sum+A[j];
		}
		int sum2=sum;
		int sum1=0;
		for(int k=0;k<N;k++) {
			sum1=sum1+A[k];
			sum2=sum2-A[k];
			if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			}
		}
		System.out.print(d);

}} Main public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] linea = s.nextLine().split(" ");
		int N=Integer.parseInt(linea[0]);
		int [] A=new int[N];
		String[] linea2 = s.nextLine().split(" ");
		for(int i=0;i<N;i++) {
			A[i]=Integer.parseInt(linea2[i]);
			
		}
		int d=999999999;
		int sum=0;
		for(int j=0;j<N;j++) {
			sum=sum+A[j];
		}
		int sum2=sum;
		int sum1=0;
		for(int k=0;k<N;k++) {
			sum1=sum1+A[k];
			sum2=sum2-A[k];
			if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			}
		}
		System.out.print(d);

} main {
		Scanner s = new Scanner(System.in);
		String[] linea = s.nextLine().split(" ");
		int N=Integer.parseInt(linea[0]);
		int [] A=new int[N];
		String[] linea2 = s.nextLine().split(" ");
		for(int i=0;i<N;i++) {
			A[i]=Integer.parseInt(linea2[i]);
			
		}
		int d=999999999;
		int sum=0;
		for(int j=0;j<N;j++) {
			sum=sum+A[j];
		}
		int sum2=sum;
		int sum1=0;
		for(int k=0;k<N;k++) {
			sum1=sum1+A[k];
			sum2=sum2-A[k];
			if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			}
		}
		System.out.print(d);

} Scanner s = new Scanner(System.in); s new Scanner(System.in) String[] linea = s.nextLine().split(" "); linea s.nextLine().split(" ") s.nextLine().split s.nextLine() s.nextLine s " " int N=Integer.parseInt(linea[0]); N Integer.parseInt(linea[0]) Integer.parseInt Integer linea[0] linea 0 int [] A=new int[N]; A new int[N] N String[] linea2 = s.nextLine().split(" "); linea2 s.nextLine().split(" ") s.nextLine().split s.nextLine() s.nextLine s " " for(int i=0;i<N;i++) {
			A[i]=Integer.parseInt(linea2[i]);
			
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			A[i]=Integer.parseInt(linea2[i]);
			
		} {
			A[i]=Integer.parseInt(linea2[i]);
			
		} A[i]=Integer.parseInt(linea2[i]) A[i] A i Integer.parseInt(linea2[i]) Integer.parseInt Integer linea2[i] linea2 i int d=999999999; d 999999999 int sum=0; sum 0 for(int j=0;j<N;j++) {
			sum=sum+A[j];
		} int j=0; int j=0; j 0 j<N j N j++ j++ j {
			sum=sum+A[j];
		} {
			sum=sum+A[j];
		} sum=sum+A[j] sum sum+A[j] sum A[j] A j int sum2=sum; sum2 sum int sum1=0; sum1 0 for(int k=0;k<N;k++) {
			sum1=sum1+A[k];
			sum2=sum2-A[k];
			if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			}
		} int k=0; int k=0; k 0 k<N k N k++ k++ k {
			sum1=sum1+A[k];
			sum2=sum2-A[k];
			if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			}
		} {
			sum1=sum1+A[k];
			sum2=sum2-A[k];
			if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			}
		} sum1=sum1+A[k] sum1 sum1+A[k] sum1 A[k] A k sum2=sum2-A[k] sum2 sum2-A[k] sum2 A[k] A k if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			} Math.abs(sum1-sum2)<d Math.abs(sum1-sum2) Math.abs Math sum1-sum2 sum1 sum2 d {
				d=Math.abs(sum1-sum2);
			} d=Math.abs(sum1-sum2) d Math.abs(sum1-sum2) Math.abs Math sum1-sum2 sum1 sum2 System.out.print(d) System.out.print System.out System System.out d String[] args args public class Main {
	
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] linea = s.nextLine().split(" ");
		int N=Integer.parseInt(linea[0]);
		int [] A=new int[N];
		String[] linea2 = s.nextLine().split(" ");
		for(int i=0;i<N;i++) {
			A[i]=Integer.parseInt(linea2[i]);
			
		}
		int d=999999999;
		int sum=0;
		for(int j=0;j<N;j++) {
			sum=sum+A[j];
		}
		int sum2=sum;
		int sum1=0;
		for(int k=0;k<N;k++) {
			sum1=sum1+A[k];
			sum2=sum2-A[k];
			if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			}
		}
		System.out.print(d);

}} public class Main {
	
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] linea = s.nextLine().split(" ");
		int N=Integer.parseInt(linea[0]);
		int [] A=new int[N];
		String[] linea2 = s.nextLine().split(" ");
		for(int i=0;i<N;i++) {
			A[i]=Integer.parseInt(linea2[i]);
			
		}
		int d=999999999;
		int sum=0;
		for(int j=0;j<N;j++) {
			sum=sum+A[j];
		}
		int sum2=sum;
		int sum1=0;
		for(int k=0;k<N;k++) {
			sum1=sum1+A[k];
			sum2=sum2-A[k];
			if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			}
		}
		System.out.print(d);

}} Main
import java.util.Scanner;

public class Main {
	
	
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String[] linea = s.nextLine().split(" ");
		int N=Integer.parseInt(linea[0]);
		int [] A=new int[N];
		String[] linea2 = s.nextLine().split(" ");
		for(int i=0;i<N;i++) {
			A[i]=Integer.parseInt(linea2[i]);
			
		}
		int d=999999999;
		int sum=0;
		for(int j=0;j<N;j++) {
			sum=sum+A[j];
		}
		int sum2=sum;
		int sum1=0;
		for(int k=0;k<N;k++) {
			sum1=sum1+A[k];
			sum2=sum2-A[k];
			if(Math.abs(sum1-sum2)<d) {
				d=Math.abs(sum1-sum2);
			}
		}
		System.out.print(d);

}}