/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fucking interest
*******************************
Higher, higher, even higher, to the point you won’t even be able to see me
https://www.a2oj.com/Ladder16.html
*******************************
NEVER DO 300IQ CONTESTS EVER
300IQ AS WRITER = EXTRA NONO
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         int res = 0;
         for(int x: arr)
            res += x;
         int left = 0;
         int right = res;
         for(int i=0; i < N; i++)
         {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         }
         System.out.println(res);
      }
   } import java.util.*; util.* java import java.io.*; io.* java import java.math.*; math.* java public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         int res = 0;
         for(int x: arr)
            res += x;
         int left = 0;
         int right = res;
         for(int i=0; i < N; i++)
         {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         }
         System.out.println(res);
      }
   } Main public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         int res = 0;
         for(int x: arr)
            res += x;
         int left = 0;
         int right = res;
         for(int i=0; i < N; i++)
         {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         }
         System.out.println(res);
      } main {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         int res = 0;
         for(int x: arr)
            res += x;
         int left = 0;
         int right = res;
         for(int i=0; i < N; i++)
         {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         }
         System.out.println(res);
      } BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); infile new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st = new StringTokenizer(infile.readLine()); st new StringTokenizer(infile.readLine()) int N = Integer.parseInt(st.nextToken()); N Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int[] arr = new int[N]; arr new int[N] N st = new StringTokenizer(infile.readLine()) st new StringTokenizer(infile.readLine()) for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken()); int i=0; int i=0; i 0 i < N i N i++ i++ i arr[i] = Integer.parseInt(st.nextToken()); arr[i] = Integer.parseInt(st.nextToken()) arr[i] arr i Integer.parseInt(st.nextToken()) Integer.parseInt Integer st.nextToken() st.nextToken st int res = 0; res 0 for(int x: arr)
            res += x; int x arr res += x; res += x res x int left = 0; left 0 int right = res; right res for(int i=0; i < N; i++)
         {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         } int i=0; int i=0; i 0 i < N i N i++ i++ i {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         } {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         } left += arr[i] left arr[i] arr i right -= arr[i] right arr[i] arr i res = Math.min(res, Math.abs(left-right)) res Math.min(res, Math.abs(left-right)) Math.min Math res Math.abs(left-right) Math.abs Math left-right left right System.out.println(res) System.out.println System.out System System.out res String omkar[] omkar public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         int res = 0;
         for(int x: arr)
            res += x;
         int left = 0;
         int right = res;
         for(int i=0; i < N; i++)
         {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         }
         System.out.println(res);
      }
   } public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         int res = 0;
         for(int x: arr)
            res += x;
         int left = 0;
         int right = res;
         for(int i=0; i < N; i++)
         {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         }
         System.out.println(res);
      }
   } Main
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fucking interest
*******************************
Higher, higher, even higher, to the point you won’t even be able to see me
https://www.a2oj.com/Ladder16.html
*******************************
NEVER DO 300IQ CONTESTS EVER
300IQ AS WRITER = EXTRA NONO
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int[] arr = new int[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = Integer.parseInt(st.nextToken());
         int res = 0;
         for(int x: arr)
            res += x;
         int left = 0;
         int right = res;
         for(int i=0; i < N; i++)
         {
            left += arr[i];
            right -= arr[i];
            res = Math.min(res, Math.abs(left-right));
         }
         System.out.println(res);
      }
   }