import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int kazu = stdIn.nextInt();
        int weight[] = new int[kazu];
        int sum = 0;
        int dif = 0;
        int count = 0;
        
        for(int i = 0; i < kazu; i++){
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        }
        
        dif = sum;
        int difsum = 0;
        
        for(int i = 0; i < kazu; i++){
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        }
        
        System.out.println(dif);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int kazu = stdIn.nextInt();
        int weight[] = new int[kazu];
        int sum = 0;
        int dif = 0;
        int count = 0;
        
        for(int i = 0; i < kazu; i++){
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        }
        
        dif = sum;
        int difsum = 0;
        
        for(int i = 0; i < kazu; i++){
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        }
        
        System.out.println(dif);
    }
} Main public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int kazu = stdIn.nextInt();
        int weight[] = new int[kazu];
        int sum = 0;
        int dif = 0;
        int count = 0;
        
        for(int i = 0; i < kazu; i++){
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        }
        
        dif = sum;
        int difsum = 0;
        
        for(int i = 0; i < kazu; i++){
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        }
        
        System.out.println(dif);
    } main {
        Scanner stdIn = new Scanner(System.in);
        int kazu = stdIn.nextInt();
        int weight[] = new int[kazu];
        int sum = 0;
        int dif = 0;
        int count = 0;
        
        for(int i = 0; i < kazu; i++){
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        }
        
        dif = sum;
        int difsum = 0;
        
        for(int i = 0; i < kazu; i++){
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        }
        
        System.out.println(dif);
    } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int kazu = stdIn.nextInt(); kazu stdIn.nextInt() stdIn.nextInt stdIn int weight[] = new int[kazu]; weight new int[kazu] kazu int sum = 0; sum 0 int dif = 0; dif 0 int count = 0; count 0 for(int i = 0; i < kazu; i++){
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        } int i = 0; int i = 0; i 0 i < kazu i kazu i++ i++ i {
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        } {
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        } weight[i] = stdIn.nextInt() weight[i] weight i stdIn.nextInt() stdIn.nextInt stdIn sum += weight[i] sum weight[i] weight i dif = sum dif sum int difsum = 0; difsum 0 for(int i = 0; i < kazu; i++){
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        } int i = 0; int i = 0; i 0 i < kazu i kazu i++ i++ i {
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        } {
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        } difsum += weight[i] difsum weight[i] weight i if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            } Math.abs(sum - difsum - difsum) < dif Math.abs(sum - difsum - difsum) Math.abs Math sum - difsum - difsum sum - difsum - difsum sum difsum difsum dif {
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            } dif = Math.abs(sum - difsum - difsum) dif Math.abs(sum - difsum - difsum) Math.abs Math sum - difsum - difsum sum - difsum - difsum sum difsum difsum count = 0 count 0 {
                count++;
            } count++ count if(count == 3){
                break;
            } count == 3 count 3 {
                break;
            } break; System.out.println(dif) System.out.println System.out System System.out dif String args[] args public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int kazu = stdIn.nextInt();
        int weight[] = new int[kazu];
        int sum = 0;
        int dif = 0;
        int count = 0;
        
        for(int i = 0; i < kazu; i++){
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        }
        
        dif = sum;
        int difsum = 0;
        
        for(int i = 0; i < kazu; i++){
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        }
        
        System.out.println(dif);
    }
} public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int kazu = stdIn.nextInt();
        int weight[] = new int[kazu];
        int sum = 0;
        int dif = 0;
        int count = 0;
        
        for(int i = 0; i < kazu; i++){
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        }
        
        dif = sum;
        int difsum = 0;
        
        for(int i = 0; i < kazu; i++){
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        }
        
        System.out.println(dif);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int kazu = stdIn.nextInt();
        int weight[] = new int[kazu];
        int sum = 0;
        int dif = 0;
        int count = 0;
        
        for(int i = 0; i < kazu; i++){
            weight[i] = stdIn.nextInt();
            sum += weight[i];
        }
        
        dif = sum;
        int difsum = 0;
        
        for(int i = 0; i < kazu; i++){
            difsum += weight[i];
            if(Math.abs(sum - difsum - difsum) < dif){
                dif = Math.abs(sum - difsum - difsum);
                count = 0;
            }else{
                count++;
            }
            
            if(count == 3){
                break;
            }
        }
        
        System.out.println(dif);
    }
}
