
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(),sum=0;
		int[] w = new int[n];

		for(int i = 0;i < n; i++) {
			w[i] = in.nextInt();
			sum+= w[i];
		}

		int hrf = sum/2;
		int j = 0,tmp=0;
		int s1 = 0, s2 = sum;
		while(s1 < hrf) {
			tmp = w[j];
			s1 += tmp;
			s2 -= tmp;
			j++;
		}

		int min = s1 - s2;
		s1 -= tmp;
		s2 += tmp;
		min = (min > s2 - s1) ? s2 - s1: min;
		min = (min < 0) ? min * -1: min;
		System.out.println(min);
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args){
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(),sum=0;
		int[] w = new int[n];

		for(int i = 0;i < n; i++) {
			w[i] = in.nextInt();
			sum+= w[i];
		}

		int hrf = sum/2;
		int j = 0,tmp=0;
		int s1 = 0, s2 = sum;
		while(s1 < hrf) {
			tmp = w[j];
			s1 += tmp;
			s2 -= tmp;
			j++;
		}

		int min = s1 - s2;
		s1 -= tmp;
		s2 += tmp;
		min = (min > s2 - s1) ? s2 - s1: min;
		min = (min < 0) ? min * -1: min;
		System.out.println(min);
	}

} Main public static void main(String[] args){
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(),sum=0;
		int[] w = new int[n];

		for(int i = 0;i < n; i++) {
			w[i] = in.nextInt();
			sum+= w[i];
		}

		int hrf = sum/2;
		int j = 0,tmp=0;
		int s1 = 0, s2 = sum;
		while(s1 < hrf) {
			tmp = w[j];
			s1 += tmp;
			s2 -= tmp;
			j++;
		}

		int min = s1 - s2;
		s1 -= tmp;
		s2 += tmp;
		min = (min > s2 - s1) ? s2 - s1: min;
		min = (min < 0) ? min * -1: min;
		System.out.println(min);
	} main {
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(),sum=0;
		int[] w = new int[n];

		for(int i = 0;i < n; i++) {
			w[i] = in.nextInt();
			sum+= w[i];
		}

		int hrf = sum/2;
		int j = 0,tmp=0;
		int s1 = 0, s2 = sum;
		while(s1 < hrf) {
			tmp = w[j];
			s1 += tmp;
			s2 -= tmp;
			j++;
		}

		int min = s1 - s2;
		s1 -= tmp;
		s2 += tmp;
		min = (min > s2 - s1) ? s2 - s1: min;
		min = (min < 0) ? min * -1: min;
		System.out.println(min);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt() n in.nextInt() in.nextInt in sum=0; sum 0 int[] w = new int[n]; w new int[n] n for(int i = 0;i < n; i++) {
			w[i] = in.nextInt();
			sum+= w[i];
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			w[i] = in.nextInt();
			sum+= w[i];
		} {
			w[i] = in.nextInt();
			sum+= w[i];
		} w[i] = in.nextInt() w[i] w i in.nextInt() in.nextInt in sum+= w[i] sum w[i] w i int hrf = sum/2; hrf sum/2 sum 2 int j = 0 j 0 tmp=0; tmp 0 int s1 = 0 s1 0 s2 = sum; s2 sum while(s1 < hrf) {
			tmp = w[j];
			s1 += tmp;
			s2 -= tmp;
			j++;
		} s1 < hrf s1 hrf {
			tmp = w[j];
			s1 += tmp;
			s2 -= tmp;
			j++;
		} tmp = w[j] tmp w[j] w j s1 += tmp s1 tmp s2 -= tmp s2 tmp j++ j int min = s1 - s2; min s1 - s2 s1 s2 s1 -= tmp s1 tmp s2 += tmp s2 tmp min = (min > s2 - s1) ? s2 - s1: min min (min > s2 - s1) ? s2 - s1: min (min > s2 - s1) min s2 - s1 s2 s1 s2 - s1 s2 s1 min min = (min < 0) ? min * -1: min min (min < 0) ? min * -1: min (min < 0) min 0 min * -1 min -1 1 min System.out.println(min) System.out.println System.out System System.out min String[] args args public class Main {

	public static void main(String[] args){
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(),sum=0;
		int[] w = new int[n];

		for(int i = 0;i < n; i++) {
			w[i] = in.nextInt();
			sum+= w[i];
		}

		int hrf = sum/2;
		int j = 0,tmp=0;
		int s1 = 0, s2 = sum;
		while(s1 < hrf) {
			tmp = w[j];
			s1 += tmp;
			s2 -= tmp;
			j++;
		}

		int min = s1 - s2;
		s1 -= tmp;
		s2 += tmp;
		min = (min > s2 - s1) ? s2 - s1: min;
		min = (min < 0) ? min * -1: min;
		System.out.println(min);
	}

} public class Main {

	public static void main(String[] args){
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(),sum=0;
		int[] w = new int[n];

		for(int i = 0;i < n; i++) {
			w[i] = in.nextInt();
			sum+= w[i];
		}

		int hrf = sum/2;
		int j = 0,tmp=0;
		int s1 = 0, s2 = sum;
		while(s1 < hrf) {
			tmp = w[j];
			s1 += tmp;
			s2 -= tmp;
			j++;
		}

		int min = s1 - s2;
		s1 -= tmp;
		s2 += tmp;
		min = (min > s2 - s1) ? s2 - s1: min;
		min = (min < 0) ? min * -1: min;
		System.out.println(min);
	}

} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(),sum=0;
		int[] w = new int[n];

		for(int i = 0;i < n; i++) {
			w[i] = in.nextInt();
			sum+= w[i];
		}

		int hrf = sum/2;
		int j = 0,tmp=0;
		int s1 = 0, s2 = sum;
		while(s1 < hrf) {
			tmp = w[j];
			s1 += tmp;
			s2 -= tmp;
			j++;
		}

		int min = s1 - s2;
		s1 -= tmp;
		s2 += tmp;
		min = (min > s2 - s1) ? s2 - s1: min;
		min = (min < 0) ? min * -1: min;
		System.out.println(min);
	}

}
