import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		int allSum = 0;
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		}
		
		int nowSum = 0;
		int minSum = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		}
		System.out.println(minSum);
	}
} import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		int allSum = 0;
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		}
		
		int nowSum = 0;
		int minSum = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		}
		System.out.println(minSum);
	}
} Main public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		int allSum = 0;
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		}
		
		int nowSum = 0;
		int minSum = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		}
		System.out.println(minSum);
	} main {
		
		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		int allSum = 0;
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		}
		
		int nowSum = 0;
		int minSum = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		}
		System.out.println(minSum);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) final int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int allSum = 0; allSum 0 List<Integer> list = new ArrayList<>(); list new ArrayList<>() for (int i = 0; i < N; i++) {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		} {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan list.add(n) list.add list n allSum += n allSum n int nowSum = 0; nowSum 0 int minSum = Integer.MAX_VALUE; minSum Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 0; i < N; i++) {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		} {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		} nowSum += list.get(i) nowSum list.get(i) list.get list i minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum))) minSum (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum))) Math.min Math minSum Math.abs(nowSum - (allSum - nowSum)) Math.abs Math nowSum - (allSum - nowSum) nowSum (allSum - nowSum) allSum nowSum System.out.println(minSum) System.out.println System.out System System.out minSum String[] args args public class Main {
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		int allSum = 0;
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		}
		
		int nowSum = 0;
		int minSum = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		}
		System.out.println(minSum);
	}
} public class Main {
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		int allSum = 0;
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		}
		
		int nowSum = 0;
		int minSum = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		}
		System.out.println(minSum);
	}
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		
		Scanner scan = new Scanner(System.in);
		final int N = scan.nextInt();
		int allSum = 0;
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			int n = scan.nextInt();
			list.add(n);
			allSum += n;
		}
		
		int nowSum = 0;
		int minSum = Integer.MAX_VALUE;
		for (int i = 0; i < N; i++) {
			nowSum += list.get(i);
			minSum = (int) Math.min(minSum, Math.abs(nowSum - (allSum - nowSum)));
		}
		System.out.println(minSum);
	}
}