import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    	 Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] a = new int[n];
         int all = 0;
         for(int i = 0; i < n; i++) {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         }
         int mae = 0;
         int ushiro = all;
         int ans = 0;
         for(int i = 0; i < n; i++) {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         }
         System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
    	 Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] a = new int[n];
         int all = 0;
         for(int i = 0; i < n; i++) {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         }
         int mae = 0;
         int ushiro = all;
         int ans = 0;
         for(int i = 0; i < n; i++) {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         }
         System.out.println(ans);
    }
} Main public static void main(String[] args){
    	 Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] a = new int[n];
         int all = 0;
         for(int i = 0; i < n; i++) {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         }
         int mae = 0;
         int ushiro = all;
         int ans = 0;
         for(int i = 0; i < n; i++) {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         }
         System.out.println(ans);
    } main {
    	 Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] a = new int[n];
         int all = 0;
         for(int i = 0; i < n; i++) {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         }
         int mae = 0;
         int ushiro = all;
         int ans = 0;
         for(int i = 0; i < n; i++) {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         }
         System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n int all = 0; all 0 for(int i = 0; i < n; i++) {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         } {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc all += a[i] all a[i] a i int mae = 0; mae 0 int ushiro = all; ushiro all int ans = 0; ans 0 for(int i = 0; i < n; i++) {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         } {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         } mae += a[i] mae a[i] a i ushiro -= a[i] ushiro a[i] a i if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 } mae >= ushiro mae ushiro {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 } int ansa = Math.abs(ushiro-mae); ansa Math.abs(ushiro-mae) Math.abs Math ushiro-mae ushiro mae int ansb = Math.abs(ushiro-mae+2*a[i]); ansb Math.abs(ushiro-mae+2*a[i]) Math.abs Math ushiro-mae+2*a[i] ushiro-mae ushiro mae 2*a[i] 2 a[i] a i ans = Math.min(ansa, ansb) ans Math.min(ansa, ansb) Math.min Math ansa ansb break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args){
    	 Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] a = new int[n];
         int all = 0;
         for(int i = 0; i < n; i++) {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         }
         int mae = 0;
         int ushiro = all;
         int ans = 0;
         for(int i = 0; i < n; i++) {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         }
         System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args){
    	 Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] a = new int[n];
         int all = 0;
         for(int i = 0; i < n; i++) {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         }
         int mae = 0;
         int ushiro = all;
         int ans = 0;
         for(int i = 0; i < n; i++) {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         }
         System.out.println(ans);
    }
} Main
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    	 Scanner sc = new Scanner(System.in);
         int n = sc.nextInt();
         int[] a = new int[n];
         int all = 0;
         for(int i = 0; i < n; i++) {
        	 a[i] = sc.nextInt();
        	 all += a[i];
         }
         int mae = 0;
         int ushiro = all;
         int ans = 0;
         for(int i = 0; i < n; i++) {
        	 mae += a[i];
        	 ushiro -= a[i];
        	 if(mae >= ushiro) {
        		 int ansa = Math.abs(ushiro-mae);
        		 int ansb = Math.abs(ushiro-mae+2*a[i]);
        		 ans = Math.min(ansa, ansb);
        		 break;
        	 }
         }
         System.out.println(ans);
    }
}