import java.util.*;
public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] W = new int[N+1];
    for (int i = 1; i <= N; i++) {
      W[i] = sc.nextInt();
    }

    int[] sumL2R = new int[N+1];
    for (int i = 1; i <= N; i++) {
      sumL2R[i] = sumL2R[i-1] + W[i];
    }
    int[] sumR2L = new int[N+1];
    sumR2L[N] = W[N];
    for (int i = N-1; i >= 1; i--) {
      sumR2L[i] = sumR2L[i+1] + W[i];
    }
    
    int minIndex = 1;
    int minDiff = Integer.MAX_VALUE;
    for (int i = 1; i <= N-1; i++) {
      int diff = Math.abs(sumL2R[i]-sumR2L[i+1]);
      if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      }
    }
    
//    System.out.println(Arrays.toString(sumL2R));
//    System.out.println(Arrays.toString(sumR2L));
//    System.out.println("index: " + minIndex);
//    System.out.println("diff: " + minDiff);
    System.out.println(minDiff);
  }  
} import java.util.*; util.* java public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] W = new int[N+1];
    for (int i = 1; i <= N; i++) {
      W[i] = sc.nextInt();
    }

    int[] sumL2R = new int[N+1];
    for (int i = 1; i <= N; i++) {
      sumL2R[i] = sumL2R[i-1] + W[i];
    }
    int[] sumR2L = new int[N+1];
    sumR2L[N] = W[N];
    for (int i = N-1; i >= 1; i--) {
      sumR2L[i] = sumR2L[i+1] + W[i];
    }
    
    int minIndex = 1;
    int minDiff = Integer.MAX_VALUE;
    for (int i = 1; i <= N-1; i++) {
      int diff = Math.abs(sumL2R[i]-sumR2L[i+1]);
      if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      }
    }
    
//    System.out.println(Arrays.toString(sumL2R));
//    System.out.println(Arrays.toString(sumR2L));
//    System.out.println("index: " + minIndex);
//    System.out.println("diff: " + minDiff);
    System.out.println(minDiff);
  }  
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] W = new int[N+1];
    for (int i = 1; i <= N; i++) {
      W[i] = sc.nextInt();
    }

    int[] sumL2R = new int[N+1];
    for (int i = 1; i <= N; i++) {
      sumL2R[i] = sumL2R[i-1] + W[i];
    }
    int[] sumR2L = new int[N+1];
    sumR2L[N] = W[N];
    for (int i = N-1; i >= 1; i--) {
      sumR2L[i] = sumR2L[i+1] + W[i];
    }
    
    int minIndex = 1;
    int minDiff = Integer.MAX_VALUE;
    for (int i = 1; i <= N-1; i++) {
      int diff = Math.abs(sumL2R[i]-sumR2L[i+1]);
      if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      }
    }
    
//    System.out.println(Arrays.toString(sumL2R));
//    System.out.println(Arrays.toString(sumR2L));
//    System.out.println("index: " + minIndex);
//    System.out.println("diff: " + minDiff);
    System.out.println(minDiff);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] W = new int[N+1];
    for (int i = 1; i <= N; i++) {
      W[i] = sc.nextInt();
    }

    int[] sumL2R = new int[N+1];
    for (int i = 1; i <= N; i++) {
      sumL2R[i] = sumL2R[i-1] + W[i];
    }
    int[] sumR2L = new int[N+1];
    sumR2L[N] = W[N];
    for (int i = N-1; i >= 1; i--) {
      sumR2L[i] = sumR2L[i+1] + W[i];
    }
    
    int minIndex = 1;
    int minDiff = Integer.MAX_VALUE;
    for (int i = 1; i <= N-1; i++) {
      int diff = Math.abs(sumL2R[i]-sumR2L[i+1]);
      if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      }
    }
    
//    System.out.println(Arrays.toString(sumL2R));
//    System.out.println(Arrays.toString(sumR2L));
//    System.out.println("index: " + minIndex);
//    System.out.println("diff: " + minDiff);
    System.out.println(minDiff);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] W = new int[N+1]; W new int[N+1] N+1 N 1 for (int i = 1; i <= N; i++) {
      W[i] = sc.nextInt();
    } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
      W[i] = sc.nextInt();
    } {
      W[i] = sc.nextInt();
    } W[i] = sc.nextInt() W[i] W i sc.nextInt() sc.nextInt sc int[] sumL2R = new int[N+1]; sumL2R new int[N+1] N+1 N 1 for (int i = 1; i <= N; i++) {
      sumL2R[i] = sumL2R[i-1] + W[i];
    } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
      sumL2R[i] = sumL2R[i-1] + W[i];
    } {
      sumL2R[i] = sumL2R[i-1] + W[i];
    } sumL2R[i] = sumL2R[i-1] + W[i] sumL2R[i] sumL2R i sumL2R[i-1] + W[i] sumL2R[i-1] sumL2R i-1 i 1 W[i] W i int[] sumR2L = new int[N+1]; sumR2L new int[N+1] N+1 N 1 sumR2L[N] = W[N] sumR2L[N] sumR2L N W[N] W N for (int i = N-1; i >= 1; i--) {
      sumR2L[i] = sumR2L[i+1] + W[i];
    } int i = N-1; int i = N-1; i N-1 N 1 i >= 1 i 1 i-- i-- i {
      sumR2L[i] = sumR2L[i+1] + W[i];
    } {
      sumR2L[i] = sumR2L[i+1] + W[i];
    } sumR2L[i] = sumR2L[i+1] + W[i] sumR2L[i] sumR2L i sumR2L[i+1] + W[i] sumR2L[i+1] sumR2L i+1 i 1 W[i] W i int minIndex = 1; minIndex 1 int minDiff = Integer.MAX_VALUE; minDiff Integer.MAX_VALUE Integer Integer.MAX_VALUE for (int i = 1; i <= N-1; i++) {
      int diff = Math.abs(sumL2R[i]-sumR2L[i+1]);
      if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      }
    } int i = 1; int i = 1; i 1 i <= N-1 i N-1 N 1 i++ i++ i {
      int diff = Math.abs(sumL2R[i]-sumR2L[i+1]);
      if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      }
    } {
      int diff = Math.abs(sumL2R[i]-sumR2L[i+1]);
      if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      }
    } int diff = Math.abs(sumL2R[i]-sumR2L[i+1]); diff Math.abs(sumL2R[i]-sumR2L[i+1]) Math.abs Math sumL2R[i]-sumR2L[i+1] sumL2R[i] sumL2R i sumR2L[i+1] sumR2L i+1 i 1 if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      } diff < minDiff diff minDiff {
        minIndex = i;
        minDiff = diff;
      } minIndex = i minIndex i minDiff = diff minDiff diff System.out.println(minDiff) System.out.println System.out System System.out minDiff String[] args args public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] W = new int[N+1];
    for (int i = 1; i <= N; i++) {
      W[i] = sc.nextInt();
    }

    int[] sumL2R = new int[N+1];
    for (int i = 1; i <= N; i++) {
      sumL2R[i] = sumL2R[i-1] + W[i];
    }
    int[] sumR2L = new int[N+1];
    sumR2L[N] = W[N];
    for (int i = N-1; i >= 1; i--) {
      sumR2L[i] = sumR2L[i+1] + W[i];
    }
    
    int minIndex = 1;
    int minDiff = Integer.MAX_VALUE;
    for (int i = 1; i <= N-1; i++) {
      int diff = Math.abs(sumL2R[i]-sumR2L[i+1]);
      if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      }
    }
    
//    System.out.println(Arrays.toString(sumL2R));
//    System.out.println(Arrays.toString(sumR2L));
//    System.out.println("index: " + minIndex);
//    System.out.println("diff: " + minDiff);
    System.out.println(minDiff);
  }  
} public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] W = new int[N+1];
    for (int i = 1; i <= N; i++) {
      W[i] = sc.nextInt();
    }

    int[] sumL2R = new int[N+1];
    for (int i = 1; i <= N; i++) {
      sumL2R[i] = sumL2R[i-1] + W[i];
    }
    int[] sumR2L = new int[N+1];
    sumR2L[N] = W[N];
    for (int i = N-1; i >= 1; i--) {
      sumR2L[i] = sumR2L[i+1] + W[i];
    }
    
    int minIndex = 1;
    int minDiff = Integer.MAX_VALUE;
    for (int i = 1; i <= N-1; i++) {
      int diff = Math.abs(sumL2R[i]-sumR2L[i+1]);
      if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      }
    }
    
//    System.out.println(Arrays.toString(sumL2R));
//    System.out.println(Arrays.toString(sumR2L));
//    System.out.println("index: " + minIndex);
//    System.out.println("diff: " + minDiff);
    System.out.println(minDiff);
  }  
} Main
import java.util.*;
public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] W = new int[N+1];
    for (int i = 1; i <= N; i++) {
      W[i] = sc.nextInt();
    }

    int[] sumL2R = new int[N+1];
    for (int i = 1; i <= N; i++) {
      sumL2R[i] = sumL2R[i-1] + W[i];
    }
    int[] sumR2L = new int[N+1];
    sumR2L[N] = W[N];
    for (int i = N-1; i >= 1; i--) {
      sumR2L[i] = sumR2L[i+1] + W[i];
    }
    
    int minIndex = 1;
    int minDiff = Integer.MAX_VALUE;
    for (int i = 1; i <= N-1; i++) {
      int diff = Math.abs(sumL2R[i]-sumR2L[i+1]);
      if (diff < minDiff) {
        minIndex = i;
        minDiff = diff;
      }
    }
    
//    System.out.println(Arrays.toString(sumL2R));
//    System.out.println(Arrays.toString(sumR2L));
//    System.out.println("index: " + minIndex);
//    System.out.println("diff: " + minDiff);
    System.out.println(minDiff);
  }  
}