import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int num = Integer.parseInt(in.nextLine());
    List<Integer> weis = new ArrayList<>();
    while(in.hasNext()) {
      weis.add(Integer.parseInt(in.next()));
    }
    int a = 0;
    int b = 0;
    if ((num & 1) == 1) {
      b += weis.get(num / 2);
    }
    for (int i = 0; i < num / 2; i++) {
      a += weis.get(i);
      b += weis.get(num - 1 - i);
    }
	boolean left = a > b;
    int index = num / 2 - 1;
    int ans;
    if (a > b) {
      while (a > b) {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      }
      ans = (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b;
    } else if (a == b) {
      ans = 0;
    } else {
      while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      }
      ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a;
    }
    System.out.println(ans);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int num = Integer.parseInt(in.nextLine());
    List<Integer> weis = new ArrayList<>();
    while(in.hasNext()) {
      weis.add(Integer.parseInt(in.next()));
    }
    int a = 0;
    int b = 0;
    if ((num & 1) == 1) {
      b += weis.get(num / 2);
    }
    for (int i = 0; i < num / 2; i++) {
      a += weis.get(i);
      b += weis.get(num - 1 - i);
    }
	boolean left = a > b;
    int index = num / 2 - 1;
    int ans;
    if (a > b) {
      while (a > b) {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      }
      ans = (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b;
    } else if (a == b) {
      ans = 0;
    } else {
      while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      }
      ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a;
    }
    System.out.println(ans);
  }
} Main public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int num = Integer.parseInt(in.nextLine());
    List<Integer> weis = new ArrayList<>();
    while(in.hasNext()) {
      weis.add(Integer.parseInt(in.next()));
    }
    int a = 0;
    int b = 0;
    if ((num & 1) == 1) {
      b += weis.get(num / 2);
    }
    for (int i = 0; i < num / 2; i++) {
      a += weis.get(i);
      b += weis.get(num - 1 - i);
    }
	boolean left = a > b;
    int index = num / 2 - 1;
    int ans;
    if (a > b) {
      while (a > b) {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      }
      ans = (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b;
    } else if (a == b) {
      ans = 0;
    } else {
      while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      }
      ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a;
    }
    System.out.println(ans);
  } main {
    Scanner in = new Scanner(System.in);
    int num = Integer.parseInt(in.nextLine());
    List<Integer> weis = new ArrayList<>();
    while(in.hasNext()) {
      weis.add(Integer.parseInt(in.next()));
    }
    int a = 0;
    int b = 0;
    if ((num & 1) == 1) {
      b += weis.get(num / 2);
    }
    for (int i = 0; i < num / 2; i++) {
      a += weis.get(i);
      b += weis.get(num - 1 - i);
    }
	boolean left = a > b;
    int index = num / 2 - 1;
    int ans;
    if (a > b) {
      while (a > b) {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      }
      ans = (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b;
    } else if (a == b) {
      ans = 0;
    } else {
      while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      }
      ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a;
    }
    System.out.println(ans);
  } Scanner in = new Scanner(System.in); in new Scanner(System.in) int num = Integer.parseInt(in.nextLine()); num Integer.parseInt(in.nextLine()) Integer.parseInt Integer in.nextLine() in.nextLine in List<Integer> weis = new ArrayList<>(); weis new ArrayList<>() while(in.hasNext()) {
      weis.add(Integer.parseInt(in.next()));
    } in.hasNext() in.hasNext in {
      weis.add(Integer.parseInt(in.next()));
    } weis.add(Integer.parseInt(in.next())) weis.add weis Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int a = 0; a 0 int b = 0; b 0 if ((num & 1) == 1) {
      b += weis.get(num / 2);
    } (num & 1) == 1 (num & 1) num 1 1 {
      b += weis.get(num / 2);
    } b += weis.get(num / 2) b weis.get(num / 2) weis.get weis num / 2 num 2 for (int i = 0; i < num / 2; i++) {
      a += weis.get(i);
      b += weis.get(num - 1 - i);
    } int i = 0; int i = 0; i 0 i < num / 2 i num / 2 num 2 i++ i++ i {
      a += weis.get(i);
      b += weis.get(num - 1 - i);
    } {
      a += weis.get(i);
      b += weis.get(num - 1 - i);
    } a += weis.get(i) a weis.get(i) weis.get weis i b += weis.get(num - 1 - i) b weis.get(num - 1 - i) weis.get weis num - 1 - i num - 1 - i num 1 i boolean left = a > b; left a > b a b int index = num / 2 - 1; index num / 2 - 1 num / 2 num 2 1 int ans; ans if (a > b) {
      while (a > b) {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      }
      ans = (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b;
    } else if (a == b) {
      ans = 0;
    } else {
      while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      }
      ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a;
    } a > b a b {
      while (a > b) {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      }
      ans = (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b;
    } while (a > b) {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      } a > b a b {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      } index-- index a -= weis.get(index + 1) a weis.get(index + 1) weis.get weis index + 1 index 1 b += weis.get(index + 1) b weis.get(index + 1) weis.get weis index + 1 index 1 ans = (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b ans (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b (b - a) < (a + weis.get(index + 1) * 2 - b) (b - a) b a (a + weis.get(index + 1) * 2 - b) a + weis.get(index + 1) * 2 a weis.get(index + 1) * 2 weis.get(index + 1) weis.get weis index + 1 index 1 2 b b - a b a a + weis.get(index + 1) * 2 - b a + weis.get(index + 1) * 2 a weis.get(index + 1) * 2 weis.get(index + 1) weis.get weis index + 1 index 1 2 b if (a == b) {
      ans = 0;
    } else {
      while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      }
      ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a;
    } a == b a b {
      ans = 0;
    } ans = 0 ans 0 {
      while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      }
      ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a;
    } while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      } a < b a b {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      } index++ index a += weis.get(index) a weis.get(index) weis.get weis index b -= weis.get(index) b weis.get(index) weis.get weis index ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a ans (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a (a - b) < (b + weis.get(index) * 2 - a) (a - b) a b (b + weis.get(index) * 2 - a) b + weis.get(index) * 2 b weis.get(index) * 2 weis.get(index) weis.get weis index 2 a a - b a b b + weis.get(index) * 2 - a b + weis.get(index) * 2 b weis.get(index) * 2 weis.get(index) weis.get weis index 2 a 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 in = new Scanner(System.in);
    int num = Integer.parseInt(in.nextLine());
    List<Integer> weis = new ArrayList<>();
    while(in.hasNext()) {
      weis.add(Integer.parseInt(in.next()));
    }
    int a = 0;
    int b = 0;
    if ((num & 1) == 1) {
      b += weis.get(num / 2);
    }
    for (int i = 0; i < num / 2; i++) {
      a += weis.get(i);
      b += weis.get(num - 1 - i);
    }
	boolean left = a > b;
    int index = num / 2 - 1;
    int ans;
    if (a > b) {
      while (a > b) {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      }
      ans = (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b;
    } else if (a == b) {
      ans = 0;
    } else {
      while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      }
      ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a;
    }
    System.out.println(ans);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int num = Integer.parseInt(in.nextLine());
    List<Integer> weis = new ArrayList<>();
    while(in.hasNext()) {
      weis.add(Integer.parseInt(in.next()));
    }
    int a = 0;
    int b = 0;
    if ((num & 1) == 1) {
      b += weis.get(num / 2);
    }
    for (int i = 0; i < num / 2; i++) {
      a += weis.get(i);
      b += weis.get(num - 1 - i);
    }
	boolean left = a > b;
    int index = num / 2 - 1;
    int ans;
    if (a > b) {
      while (a > b) {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      }
      ans = (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b;
    } else if (a == b) {
      ans = 0;
    } else {
      while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      }
      ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a;
    }
    System.out.println(ans);
  }
} Main
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int num = Integer.parseInt(in.nextLine());
    List<Integer> weis = new ArrayList<>();
    while(in.hasNext()) {
      weis.add(Integer.parseInt(in.next()));
    }
    int a = 0;
    int b = 0;
    if ((num & 1) == 1) {
      b += weis.get(num / 2);
    }
    for (int i = 0; i < num / 2; i++) {
      a += weis.get(i);
      b += weis.get(num - 1 - i);
    }
	boolean left = a > b;
    int index = num / 2 - 1;
    int ans;
    if (a > b) {
      while (a > b) {
        index--;
        a -= weis.get(index + 1);
        b += weis.get(index + 1);
      }
      ans = (b - a) < (a + weis.get(index + 1) * 2 - b) ? b - a : a + weis.get(index + 1) * 2 - b;
    } else if (a == b) {
      ans = 0;
    } else {
      while (a < b) {
        index++;
        a += weis.get(index);
        b -= weis.get(index);
      }
      ans = (a - b) < (b + weis.get(index) * 2 - a) ? a - b : b + weis.get(index) * 2 - a;
    }
    System.out.println(ans);
  }
}