import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int ans = 0;
    int[] w = new int[n];
    int[] sum = new int[n];

    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    }

    for(int i = 0; i < n - 1; i++){
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      }
    }

    System.out.println(ans);
  }
} 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 ans = 0;
    int[] w = new int[n];
    int[] sum = new int[n];

    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    }

    for(int i = 0; i < n - 1; i++){
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      }
    }

    System.out.println(ans);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int ans = 0;
    int[] w = new int[n];
    int[] sum = new int[n];

    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    }

    for(int i = 0; i < n - 1; i++){
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      }
    }

    System.out.println(ans);
  } main {
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int ans = 0;
    int[] w = new int[n];
    int[] sum = new int[n];

    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    }

    for(int i = 0; i < n - 1; i++){
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        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 ans = 0; ans 0 int[] w = new int[n]; w new int[n] n int[] sum = new int[n]; sum new int[n] n for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    } {
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    } w[i] = sc.nextInt() w[i] w i sc.nextInt() sc.nextInt sc if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      } i == 0 i 0 {
        sum[i] = w[i];
      } sum[i] = w[i] sum[i] sum i w[i] w i {
        sum[i] = sum[i - 1] + w[i];
      } sum[i] = sum[i - 1] + w[i] sum[i] sum i sum[i - 1] + w[i] sum[i - 1] sum i - 1 i 1 w[i] w i for(int i = 0; i < n - 1; i++){
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      }
    } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      }
    } {
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      }
    } if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      } (sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1]) (sum[i] <= sum[n - 1] - sum[i]) sum[i] sum i sum[n - 1] - sum[i] sum[n - 1] sum n - 1 n 1 sum[i] sum i (sum[i + 1] >= sum[n - 1] - sum[i + 1]) sum[i + 1] sum i + 1 i 1 sum[n - 1] - sum[i + 1] sum[n - 1] sum n - 1 n 1 sum[i + 1] sum i + 1 i 1 {
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      } ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]) ans Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]) Math.min Math sum[n - 1] - 2 * sum[i] sum[n - 1] sum n - 1 n 1 2 * sum[i] 2 sum[i] sum i 2 * sum[i + 1] - sum[n - 1] 2 * sum[i + 1] 2 sum[i + 1] sum i + 1 i 1 sum[n - 1] sum n - 1 n 1 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 ans = 0;
    int[] w = new int[n];
    int[] sum = new int[n];

    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    }

    for(int i = 0; i < n - 1; i++){
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        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 ans = 0;
    int[] w = new int[n];
    int[] sum = new int[n];

    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    }

    for(int i = 0; i < n - 1; i++){
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      }
    }

    System.out.println(ans);
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    int ans = 0;
    int[] w = new int[n];
    int[] sum = new int[n];

    for(int i = 0; i < n; i++){
      w[i] = sc.nextInt();
      if(i == 0){
        sum[i] = w[i];
      } else {
        sum[i] = sum[i - 1] + w[i];
      }
    }

    for(int i = 0; i < n - 1; i++){
      if((sum[i] <= sum[n - 1] - sum[i]) && (sum[i + 1] >= sum[n - 1] - sum[i + 1])){
        ans = Math.min(sum[n - 1] - 2 * sum[i], 2 * sum[i + 1] - sum[n - 1]);
        break;
      }
    }

    System.out.println(ans);
  }
}
