import java.io.*; 
import java.util.Scanner;
import java.lang.Math;

public class Main {
  
	public static void main(String[] args){
      	Scanner in = new Scanner(System.in);
		int N = in.nextInt();
      	int[] weigths = new int[N];
      
      	for(int i=0;i<N;i++){
        	weigths[i]= in.nextInt();
        }
        
      	if(N>1) System.out.println(balance(weigths, N));
      	else System.out.println(weigths[0]);
	}
  	
    public static int balance(int[] weigths, int n){
      	int S1 = weigths[0];
      	int S2 = weigths[weigths.length-1];
      	int indexL = 1;
      	int indexR = weigths.length-2;
      	int counter = n-2;
      	while(counter>0){
        	if(S1<=S2){
              S1+=weigths[indexL];
              indexL++;
              counter--;
            }else{
              S2+=weigths[indexR];
              indexR--;
              counter--;
            }
        }
      	int ret = S1-S2;
      	return Math.abs(ret);
    }
} import java.io.*; io.* java import java.util.Scanner; Scanner java.util import java.lang.Math; Math java.lang public class Main {
  
	public static void main(String[] args){
      	Scanner in = new Scanner(System.in);
		int N = in.nextInt();
      	int[] weigths = new int[N];
      
      	for(int i=0;i<N;i++){
        	weigths[i]= in.nextInt();
        }
        
      	if(N>1) System.out.println(balance(weigths, N));
      	else System.out.println(weigths[0]);
	}
  	
    public static int balance(int[] weigths, int n){
      	int S1 = weigths[0];
      	int S2 = weigths[weigths.length-1];
      	int indexL = 1;
      	int indexR = weigths.length-2;
      	int counter = n-2;
      	while(counter>0){
        	if(S1<=S2){
              S1+=weigths[indexL];
              indexL++;
              counter--;
            }else{
              S2+=weigths[indexR];
              indexR--;
              counter--;
            }
        }
      	int ret = S1-S2;
      	return Math.abs(ret);
    }
} Main public static void main(String[] args){
      	Scanner in = new Scanner(System.in);
		int N = in.nextInt();
      	int[] weigths = new int[N];
      
      	for(int i=0;i<N;i++){
        	weigths[i]= in.nextInt();
        }
        
      	if(N>1) System.out.println(balance(weigths, N));
      	else System.out.println(weigths[0]);
	} main {
      	Scanner in = new Scanner(System.in);
		int N = in.nextInt();
      	int[] weigths = new int[N];
      
      	for(int i=0;i<N;i++){
        	weigths[i]= in.nextInt();
        }
        
      	if(N>1) System.out.println(balance(weigths, N));
      	else System.out.println(weigths[0]);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in int[] weigths = new int[N]; weigths new int[N] N for(int i=0;i<N;i++){
        	weigths[i]= in.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
        	weigths[i]= in.nextInt();
        } {
        	weigths[i]= in.nextInt();
        } weigths[i]= in.nextInt() weigths[i] weigths i in.nextInt() in.nextInt in if(N>1) System.out.println(balance(weigths, N));
      	else System.out.println(weigths[0]); N>1 N 1 System.out.println(balance(weigths, N)) System.out.println System.out System System.out balance(weigths, N) balance weigths N System.out.println(weigths[0]) System.out.println System.out System System.out weigths[0] weigths 0 String[] args args public static int balance(int[] weigths, int n){
      	int S1 = weigths[0];
      	int S2 = weigths[weigths.length-1];
      	int indexL = 1;
      	int indexR = weigths.length-2;
      	int counter = n-2;
      	while(counter>0){
        	if(S1<=S2){
              S1+=weigths[indexL];
              indexL++;
              counter--;
            }else{
              S2+=weigths[indexR];
              indexR--;
              counter--;
            }
        }
      	int ret = S1-S2;
      	return Math.abs(ret);
    } balance {
      	int S1 = weigths[0];
      	int S2 = weigths[weigths.length-1];
      	int indexL = 1;
      	int indexR = weigths.length-2;
      	int counter = n-2;
      	while(counter>0){
        	if(S1<=S2){
              S1+=weigths[indexL];
              indexL++;
              counter--;
            }else{
              S2+=weigths[indexR];
              indexR--;
              counter--;
            }
        }
      	int ret = S1-S2;
      	return Math.abs(ret);
    } int S1 = weigths[0]; S1 weigths[0] weigths 0 int S2 = weigths[weigths.length-1]; S2 weigths[weigths.length-1] weigths weigths.length-1 weigths.length weigths weigths.length 1 int indexL = 1; indexL 1 int indexR = weigths.length-2; indexR weigths.length-2 weigths.length weigths weigths.length 2 int counter = n-2; counter n-2 n 2 while(counter>0){
        	if(S1<=S2){
              S1+=weigths[indexL];
              indexL++;
              counter--;
            }else{
              S2+=weigths[indexR];
              indexR--;
              counter--;
            }
        } counter>0 counter 0 {
        	if(S1<=S2){
              S1+=weigths[indexL];
              indexL++;
              counter--;
            }else{
              S2+=weigths[indexR];
              indexR--;
              counter--;
            }
        } if(S1<=S2){
              S1+=weigths[indexL];
              indexL++;
              counter--;
            }else{
              S2+=weigths[indexR];
              indexR--;
              counter--;
            } S1<=S2 S1 S2 {
              S1+=weigths[indexL];
              indexL++;
              counter--;
            } S1+=weigths[indexL] S1 weigths[indexL] weigths indexL indexL++ indexL counter-- counter {
              S2+=weigths[indexR];
              indexR--;
              counter--;
            } S2+=weigths[indexR] S2 weigths[indexR] weigths indexR indexR-- indexR counter-- counter int ret = S1-S2; ret S1-S2 S1 S2 return Math.abs(ret); Math.abs(ret) Math.abs Math ret int[] weigths weigths int n n public class Main {
  
	public static void main(String[] args){
      	Scanner in = new Scanner(System.in);
		int N = in.nextInt();
      	int[] weigths = new int[N];
      
      	for(int i=0;i<N;i++){
        	weigths[i]= in.nextInt();
        }
        
      	if(N>1) System.out.println(balance(weigths, N));
      	else System.out.println(weigths[0]);
	}
  	
    public static int balance(int[] weigths, int n){
      	int S1 = weigths[0];
      	int S2 = weigths[weigths.length-1];
      	int indexL = 1;
      	int indexR = weigths.length-2;
      	int counter = n-2;
      	while(counter>0){
        	if(S1<=S2){
              S1+=weigths[indexL];
              indexL++;
              counter--;
            }else{
              S2+=weigths[indexR];
              indexR--;
              counter--;
            }
        }
      	int ret = S1-S2;
      	return Math.abs(ret);
    }
} public class Main {
  
	public static void main(String[] args){
      	Scanner in = new Scanner(System.in);
		int N = in.nextInt();
      	int[] weigths = new int[N];
      
      	for(int i=0;i<N;i++){
        	weigths[i]= in.nextInt();
        }
        
      	if(N>1) System.out.println(balance(weigths, N));
      	else System.out.println(weigths[0]);
	}
  	
    public static int balance(int[] weigths, int n){
      	int S1 = weigths[0];
      	int S2 = weigths[weigths.length-1];
      	int indexL = 1;
      	int indexR = weigths.length-2;
      	int counter = n-2;
      	while(counter>0){
        	if(S1<=S2){
              S1+=weigths[indexL];
              indexL++;
              counter--;
            }else{
              S2+=weigths[indexR];
              indexR--;
              counter--;
            }
        }
      	int ret = S1-S2;
      	return Math.abs(ret);
    }
} Main
import java.io.*; 
import java.util.Scanner;
import java.lang.Math;

public class Main {
  
	public static void main(String[] args){
      	Scanner in = new Scanner(System.in);
		int N = in.nextInt();
      	int[] weigths = new int[N];
      
      	for(int i=0;i<N;i++){
        	weigths[i]= in.nextInt();
        }
        
      	if(N>1) System.out.println(balance(weigths, N));
      	else System.out.println(weigths[0]);
	}
  	
    public static int balance(int[] weigths, int n){
      	int S1 = weigths[0];
      	int S2 = weigths[weigths.length-1];
      	int indexL = 1;
      	int indexR = weigths.length-2;
      	int counter = n-2;
      	while(counter>0){
        	if(S1<=S2){
              S1+=weigths[indexL];
              indexL++;
              counter--;
            }else{
              S2+=weigths[indexR];
              indexR--;
              counter--;
            }
        }
      	int ret = S1-S2;
      	return Math.abs(ret);
    }
}
