import java.util.*;

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

		int n = sc.nextInt();
		int weights[] = new int[n];

		int group2 = 0;

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

		int group1 = 0;
		int t = 0;

		while(group1 < group2) {
			group1 += weights[t];
			group2 -= weights[t];
			t++;
		}

		if(Math.abs(group2 - group1) > Math.abs((group2 + weights[t - 1]) - (group1 - weights[t - 1]))) {
			group1 -= weights[t - 1];
			group2 += weights[t - 1];
		}

		System.out.println(Math.abs(group2 - group1));
	}
} import java.util.*; util.* java class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int weights[] = new int[n];

		int group2 = 0;

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

		int group1 = 0;
		int t = 0;

		while(group1 < group2) {
			group1 += weights[t];
			group2 -= weights[t];
			t++;
		}

		if(Math.abs(group2 - group1) > Math.abs((group2 + weights[t - 1]) - (group1 - weights[t - 1]))) {
			group1 -= weights[t - 1];
			group2 += weights[t - 1];
		}

		System.out.println(Math.abs(group2 - group1));
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int weights[] = new int[n];

		int group2 = 0;

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

		int group1 = 0;
		int t = 0;

		while(group1 < group2) {
			group1 += weights[t];
			group2 -= weights[t];
			t++;
		}

		if(Math.abs(group2 - group1) > Math.abs((group2 + weights[t - 1]) - (group1 - weights[t - 1]))) {
			group1 -= weights[t - 1];
			group2 += weights[t - 1];
		}

		System.out.println(Math.abs(group2 - group1));
	} main {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int weights[] = new int[n];

		int group2 = 0;

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

		int group1 = 0;
		int t = 0;

		while(group1 < group2) {
			group1 += weights[t];
			group2 -= weights[t];
			t++;
		}

		if(Math.abs(group2 - group1) > Math.abs((group2 + weights[t - 1]) - (group1 - weights[t - 1]))) {
			group1 -= weights[t - 1];
			group2 += weights[t - 1];
		}

		System.out.println(Math.abs(group2 - group1));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int weights[] = new int[n]; weights new int[n] n int group2 = 0; group2 0 for(int i = 0; i < n; i++) {
			weights[i] = sc.nextInt();
			group2 += weights[i];
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			weights[i] = sc.nextInt();
			group2 += weights[i];
		} {
			weights[i] = sc.nextInt();
			group2 += weights[i];
		} weights[i] = sc.nextInt() weights[i] weights i sc.nextInt() sc.nextInt sc group2 += weights[i] group2 weights[i] weights i int group1 = 0; group1 0 int t = 0; t 0 while(group1 < group2) {
			group1 += weights[t];
			group2 -= weights[t];
			t++;
		} group1 < group2 group1 group2 {
			group1 += weights[t];
			group2 -= weights[t];
			t++;
		} group1 += weights[t] group1 weights[t] weights t group2 -= weights[t] group2 weights[t] weights t t++ t if(Math.abs(group2 - group1) > Math.abs((group2 + weights[t - 1]) - (group1 - weights[t - 1]))) {
			group1 -= weights[t - 1];
			group2 += weights[t - 1];
		} Math.abs(group2 - group1) > Math.abs((group2 + weights[t - 1]) - (group1 - weights[t - 1])) Math.abs(group2 - group1) Math.abs Math group2 - group1 group2 group1 Math.abs((group2 + weights[t - 1]) - (group1 - weights[t - 1])) Math.abs Math (group2 + weights[t - 1]) - (group1 - weights[t - 1]) (group2 + weights[t - 1]) group2 weights[t - 1] weights t - 1 t 1 (group1 - weights[t - 1]) group1 weights[t - 1] weights t - 1 t 1 {
			group1 -= weights[t - 1];
			group2 += weights[t - 1];
		} group1 -= weights[t - 1] group1 weights[t - 1] weights t - 1 t 1 group2 += weights[t - 1] group2 weights[t - 1] weights t - 1 t 1 System.out.println(Math.abs(group2 - group1)) System.out.println System.out System System.out Math.abs(group2 - group1) Math.abs Math group2 - group1 group2 group1 String args[] args
import java.util.*;

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

		int n = sc.nextInt();
		int weights[] = new int[n];

		int group2 = 0;

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

		int group1 = 0;
		int t = 0;

		while(group1 < group2) {
			group1 += weights[t];
			group2 -= weights[t];
			t++;
		}

		if(Math.abs(group2 - group1) > Math.abs((group2 + weights[t - 1]) - (group1 - weights[t - 1]))) {
			group1 -= weights[t - 1];
			group2 += weights[t - 1];
		}

		System.out.println(Math.abs(group2 - group1));
	}
}
