import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n, i, answer;
    int sum = 0;
    int temp_a = 0;
    int temp_b = 0;
    number_n = Integer.parseInt(sc.next());
    int[] weight = new int[number_n];
    for(i = 0; i < number_n; i++) {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    }
    for(i = 0; i < number_n; i++) {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    }
    temp_a = sum - 2 * temp_a;
    temp_b = sum - 2 * temp_b;
    temp_a = Math.abs(temp_a);
    temp_b = Math.abs(temp_b);
    if(temp_b < temp_a) {
      answer = temp_b;
    } else {
      answer = temp_a;
    }
    System.out.println(answer);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n, i, answer;
    int sum = 0;
    int temp_a = 0;
    int temp_b = 0;
    number_n = Integer.parseInt(sc.next());
    int[] weight = new int[number_n];
    for(i = 0; i < number_n; i++) {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    }
    for(i = 0; i < number_n; i++) {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    }
    temp_a = sum - 2 * temp_a;
    temp_b = sum - 2 * temp_b;
    temp_a = Math.abs(temp_a);
    temp_b = Math.abs(temp_b);
    if(temp_b < temp_a) {
      answer = temp_b;
    } else {
      answer = temp_a;
    }
    System.out.println(answer);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n, i, answer;
    int sum = 0;
    int temp_a = 0;
    int temp_b = 0;
    number_n = Integer.parseInt(sc.next());
    int[] weight = new int[number_n];
    for(i = 0; i < number_n; i++) {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    }
    for(i = 0; i < number_n; i++) {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    }
    temp_a = sum - 2 * temp_a;
    temp_b = sum - 2 * temp_b;
    temp_a = Math.abs(temp_a);
    temp_b = Math.abs(temp_b);
    if(temp_b < temp_a) {
      answer = temp_b;
    } else {
      answer = temp_a;
    }
    System.out.println(answer);
  } main {
    Scanner sc = new Scanner(System.in);
    int number_n, i, answer;
    int sum = 0;
    int temp_a = 0;
    int temp_b = 0;
    number_n = Integer.parseInt(sc.next());
    int[] weight = new int[number_n];
    for(i = 0; i < number_n; i++) {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    }
    for(i = 0; i < number_n; i++) {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    }
    temp_a = sum - 2 * temp_a;
    temp_b = sum - 2 * temp_b;
    temp_a = Math.abs(temp_a);
    temp_b = Math.abs(temp_b);
    if(temp_b < temp_a) {
      answer = temp_b;
    } else {
      answer = temp_a;
    }
    System.out.println(answer);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int number_n number_n i i answer; answer int sum = 0; sum 0 int temp_a = 0; temp_a 0 int temp_b = 0; temp_b 0 number_n = Integer.parseInt(sc.next()) number_n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] weight = new int[number_n]; weight new int[number_n] number_n for(i = 0; i < number_n; i++) {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    } i = 0; i = 0 i 0 i < number_n i number_n i++ i++ i {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    } {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    } weight[i] = Integer.parseInt(sc.next()) weight[i] weight i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc sum += weight[i] sum weight[i] weight i for(i = 0; i < number_n; i++) {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    } i = 0; i = 0 i 0 i < number_n i number_n i++ i++ i {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    } {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    } temp_a += weight[i] temp_a weight[i] weight i if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      } sum <= 2 * temp_a sum 2 * temp_a 2 temp_a {
        break;
      } break; {
        temp_b = temp_a;
      } temp_b = temp_a temp_b temp_a temp_a = sum - 2 * temp_a temp_a sum - 2 * temp_a sum 2 * temp_a 2 temp_a temp_b = sum - 2 * temp_b temp_b sum - 2 * temp_b sum 2 * temp_b 2 temp_b temp_a = Math.abs(temp_a) temp_a Math.abs(temp_a) Math.abs Math temp_a temp_b = Math.abs(temp_b) temp_b Math.abs(temp_b) Math.abs Math temp_b if(temp_b < temp_a) {
      answer = temp_b;
    } else {
      answer = temp_a;
    } temp_b < temp_a temp_b temp_a {
      answer = temp_b;
    } answer = temp_b answer temp_b {
      answer = temp_a;
    } answer = temp_a answer temp_a System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n, i, answer;
    int sum = 0;
    int temp_a = 0;
    int temp_b = 0;
    number_n = Integer.parseInt(sc.next());
    int[] weight = new int[number_n];
    for(i = 0; i < number_n; i++) {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    }
    for(i = 0; i < number_n; i++) {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    }
    temp_a = sum - 2 * temp_a;
    temp_b = sum - 2 * temp_b;
    temp_a = Math.abs(temp_a);
    temp_b = Math.abs(temp_b);
    if(temp_b < temp_a) {
      answer = temp_b;
    } else {
      answer = temp_a;
    }
    System.out.println(answer);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n, i, answer;
    int sum = 0;
    int temp_a = 0;
    int temp_b = 0;
    number_n = Integer.parseInt(sc.next());
    int[] weight = new int[number_n];
    for(i = 0; i < number_n; i++) {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    }
    for(i = 0; i < number_n; i++) {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    }
    temp_a = sum - 2 * temp_a;
    temp_b = sum - 2 * temp_b;
    temp_a = Math.abs(temp_a);
    temp_b = Math.abs(temp_b);
    if(temp_b < temp_a) {
      answer = temp_b;
    } else {
      answer = temp_a;
    }
    System.out.println(answer);
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number_n, i, answer;
    int sum = 0;
    int temp_a = 0;
    int temp_b = 0;
    number_n = Integer.parseInt(sc.next());
    int[] weight = new int[number_n];
    for(i = 0; i < number_n; i++) {
      weight[i] = Integer.parseInt(sc.next());
      sum += weight[i];
    }
    for(i = 0; i < number_n; i++) {
      temp_a += weight[i];
      if(sum <= 2 * temp_a) {
        break;
      } else {
        temp_b = temp_a;
      }
    }
    temp_a = sum - 2 * temp_a;
    temp_b = sum - 2 * temp_b;
    temp_a = Math.abs(temp_a);
    temp_b = Math.abs(temp_b);
    if(temp_b < temp_a) {
      answer = temp_b;
    } else {
      answer = temp_a;
    }
    System.out.println(answer);
  }
}
