import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int vol = sc.nextInt();
		int sum = 0;
		int index = 0;
		int[] array = new int[vol];
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			sum += n;
			array[index] = n;
			index += 1;
		}

		int sum1 = 0;
		int sum2 = 0;
		index = 0;

		while (sum1 < sum / 2) {
			sum1 += array[index];
			index += 1;
		}

		sum2 = sum1 - array[index - 1];
		int result = Math.min(Math.abs(sum - 2 * sum1),Math.abs(sum - 2 * sum2));

		System.out.println(result);

	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int vol = sc.nextInt();
		int sum = 0;
		int index = 0;
		int[] array = new int[vol];
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			sum += n;
			array[index] = n;
			index += 1;
		}

		int sum1 = 0;
		int sum2 = 0;
		index = 0;

		while (sum1 < sum / 2) {
			sum1 += array[index];
			index += 1;
		}

		sum2 = sum1 - array[index - 1];
		int result = Math.min(Math.abs(sum - 2 * sum1),Math.abs(sum - 2 * sum2));

		System.out.println(result);

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int vol = sc.nextInt();
		int sum = 0;
		int index = 0;
		int[] array = new int[vol];
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			sum += n;
			array[index] = n;
			index += 1;
		}

		int sum1 = 0;
		int sum2 = 0;
		index = 0;

		while (sum1 < sum / 2) {
			sum1 += array[index];
			index += 1;
		}

		sum2 = sum1 - array[index - 1];
		int result = Math.min(Math.abs(sum - 2 * sum1),Math.abs(sum - 2 * sum2));

		System.out.println(result);

	} main {
		Scanner sc = new Scanner(System.in);
		int vol = sc.nextInt();
		int sum = 0;
		int index = 0;
		int[] array = new int[vol];
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			sum += n;
			array[index] = n;
			index += 1;
		}

		int sum1 = 0;
		int sum2 = 0;
		index = 0;

		while (sum1 < sum / 2) {
			sum1 += array[index];
			index += 1;
		}

		sum2 = sum1 - array[index - 1];
		int result = Math.min(Math.abs(sum - 2 * sum1),Math.abs(sum - 2 * sum2));

		System.out.println(result);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int vol = sc.nextInt(); vol sc.nextInt() sc.nextInt sc int sum = 0; sum 0 int index = 0; index 0 int[] array = new int[vol]; array new int[vol] vol while (sc.hasNextInt()) {
			int n = sc.nextInt();
			sum += n;
			array[index] = n;
			index += 1;
		} sc.hasNextInt() sc.hasNextInt sc {
			int n = sc.nextInt();
			sum += n;
			array[index] = n;
			index += 1;
		} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc sum += n sum n array[index] = n array[index] array index n index += 1 index 1 int sum1 = 0; sum1 0 int sum2 = 0; sum2 0 index = 0 index 0 while (sum1 < sum / 2) {
			sum1 += array[index];
			index += 1;
		} sum1 < sum / 2 sum1 sum / 2 sum 2 {
			sum1 += array[index];
			index += 1;
		} sum1 += array[index] sum1 array[index] array index index += 1 index 1 sum2 = sum1 - array[index - 1] sum2 sum1 - array[index - 1] sum1 array[index - 1] array index - 1 index 1 int result = Math.min(Math.abs(sum - 2 * sum1),Math.abs(sum - 2 * sum2)); result Math.min(Math.abs(sum - 2 * sum1),Math.abs(sum - 2 * sum2)) Math.min Math Math.abs(sum - 2 * sum1) Math.abs Math sum - 2 * sum1 sum 2 * sum1 2 sum1 Math.abs(sum - 2 * sum2) Math.abs Math sum - 2 * sum2 sum 2 * sum2 2 sum2 System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int vol = sc.nextInt();
		int sum = 0;
		int index = 0;
		int[] array = new int[vol];
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			sum += n;
			array[index] = n;
			index += 1;
		}

		int sum1 = 0;
		int sum2 = 0;
		index = 0;

		while (sum1 < sum / 2) {
			sum1 += array[index];
			index += 1;
		}

		sum2 = sum1 - array[index - 1];
		int result = Math.min(Math.abs(sum - 2 * sum1),Math.abs(sum - 2 * sum2));

		System.out.println(result);

	}

} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int vol = sc.nextInt();
		int sum = 0;
		int index = 0;
		int[] array = new int[vol];
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			sum += n;
			array[index] = n;
			index += 1;
		}

		int sum1 = 0;
		int sum2 = 0;
		index = 0;

		while (sum1 < sum / 2) {
			sum1 += array[index];
			index += 1;
		}

		sum2 = sum1 - array[index - 1];
		int result = Math.min(Math.abs(sum - 2 * sum1),Math.abs(sum - 2 * sum2));

		System.out.println(result);

	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int vol = sc.nextInt();
		int sum = 0;
		int index = 0;
		int[] array = new int[vol];
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			sum += n;
			array[index] = n;
			index += 1;
		}

		int sum1 = 0;
		int sum2 = 0;
		index = 0;

		while (sum1 < sum / 2) {
			sum1 += array[index];
			index += 1;
		}

		sum2 = sum1 - array[index - 1];
		int result = Math.min(Math.abs(sum - 2 * sum1),Math.abs(sum - 2 * sum2));

		System.out.println(result);

	}

}
