Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to ai. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.

The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all ai is 360.

Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya.

NoteIn first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.Picture explaning fourth sample:Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.

import java.util.Scanner;

public class A {

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

        int n = in.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = in.nextInt();

        int ans = 360;

        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = i; j < n; j++) {
                ans = Math.min(ans, Math.abs(360 - 2*sum));
                sum += a[j];
            }
        }

        System.out.println(ans);

        /*
        int sum = 0;
        for (int j = 0, i = 0; j < n; j++) {
            sum += a[j];
            while (sum > 180) {
                ans = Math.min(ans, Math.abs(360 - 2*sum));
                sum -= a[i++];
            }
            ans = Math.min(ans, Math.abs(360 - 2*sum));
        }

        System.out.println(ans);
        */
    }

}

import static java.lang.Double.parseDouble;
import static java.lang.Integer.max;
import static java.lang.Integer.min;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.abs;
import static java.lang.System.exit;
import static java.lang.System.setOut;

import java.io.*;
import java.util.*;

public class A {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    static int[] shift(int a[]) {
        int n = a.length;
        int tmp[] = new int[n];
        tmp[0] = a[n-1];

        for(int i=1;i<n;i++) tmp[i] = a[i-1];
        return tmp;
    }

    static void solve() throws Exception {
        int n = nextInt(), sum = 0;
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = nextInt();
            sum += a[i];
        }
        int cnt = 0, ans = sum;
        while(cnt ++ < 400) {
            int tmp = 0;
            for(int i = 0; i < n; i++) {
                tmp += a[i];
                ans = min(ans, abs(sum - 2 * tmp));
            }
            a = shift(a);
        }
        out.print(ans);
    }

    private static long gcd(long a, long b) {
        while (b > 0) {
            long temp = b;
            b = a % b;
            a = temp;
        }
        return a;
    }

    private static long lcm(long a, long b) {
        return a * (b / gcd(a, b));
    }

    static int nextInt() throws IOException {
        return parseInt(next());
    }

    static long nextLong() throws IOException {
        return parseLong(next());
    }

    static double nextDouble() throws IOException {
        return parseDouble(next());
    }

    static String next() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    public static void main(String[] args) throws Exception {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(new OutputStreamWriter(System.out));
            solve();
            //long lEndTime = System.currentTimeMillis();
            //System.out.println("Elapsed time in seconds: " + (double)(lEndTime - lStartTime) / 1000.0);
            in.close();
            out.close();
        } catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

import java.io.*;
import java.util.*;
import java.math.*;
//public
class Main{
    //static variable
    static final int mod = (int) 1e9 + 7;
    static final double eps = 1e-6;
    static final double pi = Math.PI;
    static final long inf = Long.MAX_VALUE / 2;

    // .......static class
  static class Pair{
      int key,value;
      Pair(int key,int value){
        this.key=key;
        this.value=value;
      }
      int Key(){
        return key;
      }
      int Value(){
        return value;
      }
  }
  static class mycomparator implements Comparator<Pair>{
     @Override
     public int compare(Pair o1,Pair o2){
      Integer key1=o1.Key(),key2=o2.Key();
          return key1.compareTo(key2);
     }
  }

//.............staic class end.

    BufferedReader br;
    PrintWriter out;
    public static void main(String[] args) {
    new Main().main1();

  }
  void main1()
  {
    try{

        br=new BufferedReader(new InputStreamReader(System.in));
        out=new PrintWriter(System.out);
        int t=1;
       // t=ii();
      while(t-->0){

        //........solution start

      int n=ii();
      int[] a=iint();
      int acc[]=new int[n];
      acc[0]=a[0];
          for(int i=1;i<n;i++)
            acc[i]=a[i]+acc[i-1];
      int ts=acc[n-1];
      int min=360;
      ts=Math.min(360,ts);
      for (int i=0;i<n;i++ ) {
        int sum=0;
           for (int j=i;j<n-1;j++ ) {
             sum+=a[j];
              min=Math.min(min,Math.abs(ts-2*sum));

           }
      }
      System.out.println(min);

        //..........solution end.

     }
     out.flush();
     out.close();
    }
    catch(Exception e){
        e.printStackTrace();}
  }

  // ...............required method.

  //................end.

   //..............input method start.
    int getmax(int a[]){
      int n=a.length;
      int max=a[0];
      for (int i=1;i<n ;i++ ) {
        max=Math.max(a[i],max);
      }
      return max;
    }
     int getmin(int a[]){
      int n=a.length;
      int min=a[0];
      for (int i=1;i<n ;i++ ) {
        min=Math.min(a[i],min);
      }
      return min;
    }

    int[] iint() throws IOException{
      String line[]=br.readLine().split(" ");
      int[] a=new int[line.length];
      for (int i=0;i<line.length ;i++ ) {
        a[i]=Integer.parseInt(line[i]);
      }
      return a;
    }
    long[] ilong() throws IOException{
      String line[]=br.readLine().split(" ");
      long[] a=new long[line.length];
      for (int i=0;i<line.length ;i++ ) {
        a[i]=Long.parseLong(line[i]);
      }
      return a;
    }
    double[] idouble() throws IOException{
      String line[]=br.readLine().split(" ");
      double[] a=new double[line.length];
      for (int i=0;i<line.length ;i++ ) {
        a[i]=Long.parseLong(line[i]);
      }
      return a;
    }
    long li() throws IOException{

      return Long.parseLong(br.readLine());
    }
    int ii() throws IOException{

      return Integer.parseInt(br.readLine());
    }
    double di() throws IOException{
      return Double.parseDouble(br.readLine());
    }
    char ci() throws IOException{
      return (char)br.read();
    }
    String si() throws IOException{
       return br.readLine();
    }
    String[] isa(int n) throws IOException{
        String at =si();
        return at.split(" ");
    }

    double[][] idm(int n, int m) throws IOException{
        double a[][] = new double[n][m];
        for (int i = 0; i < n; i++) {
          double[] temp=idouble();
          for (int j = 0; j < m; j++) a[i][j] = temp[j];
        }
        return a;
    }

    int[][] iim(int n, int m) throws IOException{
        int a[][] = new int[n][m];
        for (int i = 0; i < n; i++) {
          int[] temp=iint();
          for (int j = 0; j < m; j++) a[i][j] =temp[j];
        }
        return a;
    }
    long[][] ilm(int n, int m) throws IOException{
       long a[][] = new long[n][m];
        for (int i = 0; i < n; i++) {
          long[] temp=ilong();
          for (int j = 0; j < m; j++) a[i][j] =temp[j];
        }
        return a;
    }
    //..............input methods end;

}

//package codeforces;

import java.io.*;
import java.util.*;

/**
 * @author safat
 * @since 11/26/17.
 */

public class A895 {

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);

        int n = in.readInt();
        int numbers[] = in.readIntArray(n);
        int cumSum[] = new int[n + 1];

        int sum = numbers[0];
        cumSum[1] = numbers[0];

        for (int i = 2; i <= numbers.length; i++) {
            sum += numbers[i - 1];
            cumSum[i] = sum;
        }

        int minGap = Integer.MAX_VALUE;

        for (int i = 0; i <= numbers.length; i++) {
            for (int j = i + 1; j <= numbers.length; j++) {
                int left = cumSum[j] - cumSum[i];
                minGap = Math.min(minGap, Math.abs(360 - 2 * left));
            }
        }

        System.out.println(minGap);
    }

    public static String join(int[] numbers) {
        if (numbers == null || numbers.length == 0) {
            return null;
        }

        StringBuilder result = new StringBuilder();

        for (int n : numbers) {
            result.append(n).append(", ");
        }

        return result.substring(0, result.length() - 1);
    }

    static class InputReader {
        private final InputStream stream;
        private final byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int read() {
            try {
                if (curChar >= numChars) {
                    curChar = 0;
                    numChars = stream.read(buf);
                    if (numChars <= 0)
                        return -1;
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return buf[curChar++];
        }

        public int readInt() {
            return (int) readLong();
        }

        public long readLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
                if (c == -1) throw new RuntimeException();
            }
            boolean negative = false;
            if (c == '-') {
                negative = true;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') throw new InputMismatchException();
                res *= 10;
                res += (c - '0');
                c = read();
            } while (!isSpaceChar(c));
            return negative ? (-res) : (res);
        }

        public int[] readIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) arr[i] = readInt();
            return arr;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APizzaSeparation solver = new APizzaSeparation();
        solver.solve(1, in, out);
        out.close();
    }

    static class APizzaSeparation {
        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int arr[] = new int[2 * n];
            long ans = 360;
            for (int i = 0; i < n; i++) arr[i] = arr[i + n] = in.scanInt();

            for (int i = 0; i < 2 * n; i++) {
                int sum = 0;
                for (int j = i; j < n + i; j++) {
                    if (j < 2 * n) {
                        sum += arr[j];
                        ans = Math.min(ans, Math.abs((360 - sum) - sum));
                    }
                }
            }

            out.println(ans);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int []a=new int [n];
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		int ans=360;
		int s=0;
		int start=0;
		for(int i=0;i<n;i++)
		{
			if(a[i]>180)
			{
				ans=Math.min(ans, a[i]-360+a[i]);
			}
			else
			{
				s+=a[i];
				ans=Math.min(ans,Math.abs(s-(360-s)));
				while(s>180)
				{
					s-=a[start++];
					ans=Math.min(ans,Math.abs(s-(360-s)));
				}

			}

		}

		System.out.println(ans);

	}
	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

		public String next() throws IOException
		{
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {return Integer.parseInt(next());}

		public long nextLong() throws IOException {return Long.parseLong(next());}

		public String nextLine() throws IOException {return br.readLine();}

		public double nextDouble() throws IOException
		{
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if(x.charAt(0) == '-')
			{
				neg = true;
				start++;
			}
			for(int i = start; i < x.length(); i++)
				if(x.charAt(i) == '.')
				{
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				}
				else
				{
					sb.append(x.charAt(i));
					if(dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg?-1:1);
		}

		public boolean ready() throws IOException {return br.ready();}

	}
}

import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
	static int mod = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		ArrayList<Integer> al = new ArrayList<>();
		for(int i=0;i<n;i++){
			al.add(sc.nextInt());
		}
		int min = Integer.MAX_VALUE;
		if(n==1){
			System.out.println(al.get(0));
			return;
		}
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=0;j<n;j++){
				int val = (i+j)%n;
				sum+=al.get(val);
				int f = 360-(sum)-sum;
				if(f>=0)
				min = Math.min(min, f);
			}
		}
		System.out.println(min);
	}

	public static class pair{
		int l;
		int r;
	}

	public static class comp implements Comparator<pair>{
		public int compare(pair o1, pair o2){
			if(o1.l!=o2.l)
			return Long.valueOf(o1.l).compareTo(Long.valueOf(o2.l));
			return o1.r-o2.r;
		}
	}

	public static long sum(long a, long d, long n){

		long total = ((n)*((2*a)+(n-1)*d))/2;
		return total;
	}

	public static class trie{
		char ch;
		HashMap<Character,trie> hm = new HashMap<>();
		int count;
		boolean isterminal;
	}

	public static int partition(int [] arr, int s, int e){

		int index=s;
		int pivot = arr[e];
		for(int i=s;i<=e-1;i++){
			if(arr[i]<=pivot){
				arr = swap(arr, index, i);
				index++;
			}
		}
		swap(arr,index,e);
		print(arr);
		return index;
	}

	public static int[] swap(int[] arr, int low, int high){
		int temp = arr[low];
		arr[low]=arr[high];
		arr[high]=temp;
		return arr;
	}

	public static long gcd(long a, long b){
		if(a==0)
			return b;

		return gcd(b%a,a);
	}

	public static void print(int[] arr){
		for(int i=0;i<arr.length;i++)
			System.out.print(arr[i]+" ");
		System.out.println();
	}

	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}

}

/**
 * @author prakhar28
 *
 */
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main{

	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[200005]; // line length+1
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

	static class FastScanner {

	    private final BufferedReader bufferedReader;
	    private StringTokenizer stringTokenizer;

	    public FastScanner() {
	        bufferedReader = new BufferedReader(new InputStreamReader(System.in));
	    }

	    public String next() {
	        while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
	            try {
	                stringTokenizer = new StringTokenizer(bufferedReader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException("Can't read next value", e);
	            }
	        }
	        return stringTokenizer.nextToken();
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public double nextDouble() {
	        return Double.parseDouble(next());
	    }

	    public String nextLine(){
	        String str = "";
	        try {
	            str = bufferedReader.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	    }
	}

	static void closeall() throws IOException{
		printWriter.close();
		sc.close();
		in.close();
	}
	static Scanner sc = new Scanner(System.in);
	static Reader in = new Reader();
	static FastScanner fastScanner = new FastScanner();
	static PrintWriter printWriter = new PrintWriter(new BufferedOutputStream(System.out));
	static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
	static long INF = (long)(1e18);

	int V,E;
	ArrayList<Integer> adj[];
	ArrayList<Integer> path;
	Main(){
	}
	Main(int v,int e){
		V=v;
		E=e;
		adj=new ArrayList[v];
		path = new ArrayList<>();
		for(int i=0;i<v;i++)
			adj[i] = new ArrayList<>();
	}
	void addEdge(int u,int v){
		adj[u].add(v);
		adj[v].add(u);
	}

	static long power(long a,long k)
	{
		long m = 1000000007;
	    long ans=1;
	    long tmp=a%m;
	    while(k>0)
	    {
	        if(k%2==1)
	        	ans=ans*tmp%m;
	        tmp=tmp*tmp%m;
	        k>>=1;
	    }
	    return ans;
	}

	static class Pair implements Comparable<Pair>{
		int a,b;
		Pair(int x,int y){
			a = x;
			b = y;
		}
		public int compareTo(Pair ob){
			return this.a-ob.a;
		}

	}
	static long mod = 1000000007;
	public static void main(String args[])throws IOException{
		Reader in = new Reader();
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++)
			a[i] = in.nextInt();
		int ans = 500;
		for(int i=0;i<n;i++) {
			int s = 0;
			for(int j=i;j<n;j++) {
				s=s+a[j];
				ans = (int)Math.min(ans, 2*Math.abs(180-s));
			}
		}
		printWriter.println(ans);
		closeall();
	}
}

import java.util.*;

public class Main
{

    public static void main(String[] args)
    {
       Scanner sc=new Scanner(System.in);
       StringBuilder sb=new StringBuilder();
       int n=sc.nextInt();
       int a[]=new int[n];
       for( int i=0;i<n;i++)
       {
           a[i]=sc.nextInt();
       }
       int diff=Integer.MAX_VALUE;
      for( int i=0;i<n;i++)
      {
          for( int j=i;j<n;j++)
          {
              int sum=0;
              for( int k=i;k<=j;k++)
              {
                  sum+=a[k];
              }
              diff=Math.min(diff, Math.abs(360-2*sum));
          }
      }
        System.out.println(diff);

	}

}
class Pair{
    int size;
    int l;
    int r;
    Pair( int size, int l, int r)
    {
        this.size=size;
        this.l=l;
        this.r=r;
    }
}
class myComparator implements Comparator<Pair>
{
    public int compare( Pair a, Pair b)
    {
     if(a.size==b.size)
     {
         return Integer.compare(a.l,b.l);
     }else
     return Integer.compare(b.size,a.size);
    }
}

import java.util.*;

public class pizzasep {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] slice = new int[n];
		if (n == 1) {
			System.out.println(360);
			System.exit(0);
		}
		int min = Integer.MAX_VALUE;
		slice[0] = scan.nextInt();
		for (int i = 1; i < n; i++) {
			slice[i] = scan.nextInt() + slice[i - 1];
		}

		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				int diff = Math.abs(2 * (slice[j] - slice[i]) - 360);
				if (diff < min) {
					min = diff;
				}
			}
		}
		System.out.println(min);
	}
}

import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    static final long MOD = (long)1e9+7;
    static FastReader in;
    public static void main(String[] args){
        in = new FastReader();
        int N = ni();
        int[] a = new int[N+1];
        for(int i = 1; i<=N; i++)a[i] = ni();
        int[] sum = new int[2*N+1];
        for(int i = 1; i<=2*N; i++){
            sum[i] = sum[i-1]+a[(i>N)?i-N:i];
        }
        int ans = Integer.MAX_VALUE;
        for(int i = 1; i<=N; i++){
            for(int j = 0; j<N; j++){
                int seg = sum[j+i]-sum[i];
                ans = Math.min(Math.abs(360 - 2*seg), ans);
            }
        }
        pn(ans);
    }

    static void p(Object o){
        System.out.print(o);
    }

    static void pn(Object o){
        System.out.println(o);
    }

    static String n(){
        return in.next();
    }

    static String nln(){
        return in.nextLine();
    }

    static int ni(){
        return Integer.parseInt(in.next());
    }

    static int[] ia(int N){
        int[] a = new int[N];
        for(int i = 0; i<N; i++)a[i] = ni();
        return a;
    }

    static long[] la(int N){
        long[] a = new long[N];
        for(int i = 0; i<N; i++)a[i] = nl();
        return a;
    }

    static long nl(){
        return Long.parseLong(in.next());
    }

    static double nd(){
        return Double.parseDouble(in.next());
    }

    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }
            return str;
        }
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String argv[]) {

        Scanner scanner = new Scanner( System.in);
        Integer n = scanner.nextInt();
        final int[] sum1 = {0,0};

        int a[] =new int[360];
        for(int i=0;i<n;i++){
            a[i]=scanner.nextInt();
        }

        int min=Integer.MAX_VALUE;

        for(int i=0;i<n;i++){
            int sum=0;
            for(int j=i;j<n;j++){
                 sum+=a[j];
                if(Math.abs((360-sum)-sum)<min){
                    min=Math.abs((360-sum)-sum);
                }
            }
            for(int j=0;j<i;j++){
                sum+=a[j];
                if(Math.abs((360-sum)-sum)<min){
                    min=Math.abs((360-sum)-sum);
                }
            }

        }
        System.out.println(min);
    }
}

import java.util.*;
import java.io.*;
public class Main{
	static int i,j,k,l,temp,count;
	public static void main(String[] args) throws IOException{
		/*
		.
		.
		.
		.
		.
		.
		*/
		int n=ni();
		int arr[]=nia(n);
		int min=3620;
		int count=0;
		for(i=0;i<n;i++){
			count=0;
			for(j=i;j<n;j++){
				if(i!=j)
					count += arr[j];
				min=Math.min(min,Math.abs(360-2*count));
			}
		}
		sop(min);
		/*
		.
		.
		.
		.
		.
		.
		.
		*/
	}
	static int gcd(int a,int b){
		if(a==0)
			return b;
		return gcd(b%a,a);
	}
	static int arr[]=new int[100002];
	static int front=0;
	static int rear=-1;
	static void offer(int data){
		arr[front]=data;
		front++;
	}
	static int peek(){
		return arr[rear+1];
	}
	static boolean isEmpty(){
		if(rear+1==front){
			return true;
		}
		else
			return false;
	}
	static int poll(){
		rear++;
		return arr[rear];
	}
	/*
	fuctions
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	.
	abcdefghijklmnopqrstuvwxyz
	.
	.
	.
	.
	.
	.
	*/
	static int modulo(int j,int m){
		if(j<0)
			return m+j;
		  if(j>=m)
			return j-m;

			return j;
	}
	static final int mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static final boolean debug=true;
	static Reader in=new Reader();
	static StringBuilder ans=new StringBuilder();
	static long powm(long a,long b,long m){
		long an=1;
		long c=a;
		while(b>0){
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static Random rn=new Random();
	static void sop(Object a){System.out.println(a);}
	static int ni(){return in.nextInt();}
	static int[] nia(int n){int a[]=new int[n];for(int i=0;i<n;i++)a[i]=ni();return a;}
	static long nl(){return in.nextLong();}
	static long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}
	static String ns(){return in.next();}
	static String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}
	static double nd(){return in.nextDouble();}
	static double[] nda(int n){double a[]=new double[n];for(int i=0;i<n;i++)a[i]=nd();return a;}
	static class Reader{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public Reader(){
			reader=new BufferedReader(new InputStreamReader(System.in),32768);
			tokenizer=null;
		}
		public String next(){
			while(tokenizer==null || !tokenizer.hasMoreTokens()){
				try{
					tokenizer=new StringTokenizer(reader.readLine());
				}
				catch(IOException e){
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt(){
			return Integer.parseInt(next());
		}
		public long nextLong(){
			return Long.parseLong(next());
		}
		public double nextDouble(){
			return Double.parseDouble(next());
		}
	}
}

import java.util.*;
import java.io.*;
public class Test {
        String INPUT = "4\n" +
                "170 30 150 10";

        void solve()
        {
                int n = i();
                int[] a = ia(n);
                int ans = Integer.MAX_VALUE;
                int sum = 0;
                for(int i=0 ; i<n ; i++)
                {
                        int[] x = rotate(a,i);
                        int ans1 = Integer.MAX_VALUE;
                        sum = 0;
                        for (int j = 0; j < n; j++) {
                                sum+=x[j];
                                ans1 = Math.min(ans1,Math.abs(2*sum-360));
                        }
                        ans = Math.min(ans1,ans);
                }
                out.println(ans);

        }
        int[] rotate(int[] a,int time)
        {
                int[] n = new int[a.length];
                int ind = 0;
                for (int i = 0; i < a.length; i++) {
                        n[ind++] = a[(i+time)%a.length];
                }
                return n;
        }
        void run() throws Exception{
                is = oj ? System.in: new ByteArrayInputStream(INPUT.getBytes());
                //is = System.in;
                out = new PrintWriter(System.out);
                long s = System.currentTimeMillis();
                solve();
                out.flush();
                tr(System.currentTimeMillis()-s+"ms");
        }
        public static void main(String[] args)throws Exception {
                new Test().run();
        }
        InputStream is;
        PrintWriter out;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0, ptrbuf = 0;

        private int readByte()
        {
                if(lenbuf == -1)throw new InputMismatchException();
                if(ptrbuf >= lenbuf){
                        ptrbuf = 0;
                        try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
                        if(lenbuf <= 0)return -1;
                }
                return inbuf[ptrbuf++];
        }

        private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
        private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

        private double d() { return Double.parseDouble(s()); }
        private char c() { return (char)skip(); }

        private String s()
        {
                int b = skip();
                StringBuilder sb = new StringBuilder();
                while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
                        sb.appendCodePoint(b);
                        b = readByte();
                }
                return sb.toString();
        }

        private char[] sa(int n)
        {
                char[] buf = new char[n];
                int b = skip(), p = 0;
                while(p < n && !(isSpaceChar(b))){
                        buf[p++] = (char)b;
                        b = readByte();
                }
                return n == p ? buf : Arrays.copyOf(buf, p);
        }

        private char[][] nm(int n, int m)
        {
                char[][] map = new char[n][];
                for(int i = 0;i < n;i++)map[i] = sa(m);
                return map;
        }

        private int[] ia(int n)
        {
                int[] a = new int[n];
                for(int i = 0;i < n;i++)a[i] = i();
                return a;
        }

        private int i()
        {
                int num = 0, b;
                boolean minus = false;
                while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
                if(b == '-'){
                        minus = true;
                        b = readByte();
                }

                while(true){
                        if(b >= '0' && b <= '9'){
                                num = num * 10 + (b - '0');
                        }else{
                                return minus ? -num : num;
                        }
                        b = readByte();
                }
        }

        private long l()
        {
                long num = 0;
                int b;
                boolean minus = false;
                while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
                if(b == '-'){
                        minus = true;
                        b = readByte();
                }

                while(true){
                        if(b >= '0' && b <= '9'){
                                num = num * 10 + (b - '0');
                        }else{
                                return minus ? -num : num;
                        }
                        b = readByte();
                }
        }

        private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }

}

import java.util.*;

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

        int n = sc.nextInt();
        sc.nextLine();

        int[] numbers = new int[n];
        for(int i = 0; i < n; i++) {
            numbers[i] = sc.nextInt();
        }
        solve(numbers);
    }

    private static void solve(int[] numbers) {
        int diff = 180;
        OUT: for (int i = 0; i < numbers.length; i++) {
            int sector = 0;
            for (int j = (i + 1)%numbers.length; j != i; j = (j + 1) % numbers.length) {
                sector += numbers[j];
                int newDiff = Math.abs(180 - sector);
                if (newDiff < diff) {
                    diff = newDiff;
                    if (diff == 0) break OUT;
                }
            }
        }

        System.out.println(diff * 2);
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] pizza = new int[400];
        for(int i = 0;i < n;i++) {
            pizza[i] = sc.nextInt();
        }

        int ans = 360;
        for(int i = 0;i < n;i++) {
            int temp = 0,j = i;
            while (temp < 180) {
                temp += pizza[(j % n)];
                j++;
                ans = Math.min(ans,Math.abs(180 - temp));
            }
            ans = Math.min(ans,Math.abs(temp - 180));
        }

        System.out.println(ans * 2);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class PizzaSepr {
	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		StringTokenizer st=new StringTokenizer(br.readLine());
		int [] slice=new int[n];
		for(int i=0;i<n;++i) {
			slice[i]=Integer.parseInt(st.nextToken());
		}
		int delta=0;
		int vas=0;
		int idx=0;
		int bst=0;
		int bstDelta=700;
		for(int i=0;i<n;++i) {
			vas=0;
			for(int j=0;j<n;++j) {
				if(Math.abs(vas+slice[(i+j)%n]-180)<Math.abs(vas-180))
					vas+=slice[(i+j)%n];
				else {
					delta=Math.abs(vas-180);
					if(delta<bstDelta) {
						bst=vas;
						bstDelta=delta;}
					break;
				}
			}
		}
		System.out.println(2*Math.abs(180-bst));
	}
}

import java.util.Scanner;

public class Main {

    static int n, sol, auxs;
    static int pizza[];

    public static void main(String args[]) {
        Scanner l = new Scanner(System.in);
        n = l.nextInt();
        pizza = new int[n];
        for (int i = 0; i < n; i++) {
            pizza[i] = l.nextInt();
        }
        sol = 360;
        for (int i = 0; i < n; i++) {
            auxs = 0;
            for (int k = 0; i + k <= n; k++) {
                sol = Math.min(sol, Math.abs(360 - auxs * 2));
                if (i + k < n) {
                    auxs += pizza[i + k];
                }
            }
        }
        System.out.println(sol);
    }
}

import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.IntStream;

public class Task895A {

    public static void main(String... args) throws NumberFormatException,
            IOException {
        Solution.main(System.in, System.out);
    }

    static class Scanner {

        private final BufferedReader br;
        private String[] cache;
        private int cacheIndex;

        Scanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            cache = new String[0];
            cacheIndex = 0;
        }

        int nextInt() throws IOException {
            if (cacheIndex >= cache.length) {
                cache = br.readLine().split(" ");
                cacheIndex = 0;
            }
            return Integer.parseInt(cache[cacheIndex++]);
        }

        long nextLong() throws IOException {
            if (cacheIndex >= cache.length) {
                cache = br.readLine().split(" ");
                cacheIndex = 0;
            }
            return Long.parseLong(cache[cacheIndex++]);
        }

        String next() throws IOException {
            if (cacheIndex >= cache.length) {
                cache = br.readLine().split(" ");
                cacheIndex = 0;
            }
            return cache[cacheIndex++];
        }

        void close() throws IOException {
            br.close();
        }

    }

    static class Solution {

        public static void main(InputStream is, OutputStream os)
                throws NumberFormatException, IOException {
            PrintWriter pw = new PrintWriter(os);
            Scanner sc = new Scanner(is);

            int n = sc.nextInt();

            List<Integer> a = new ArrayList<>();

            for(int i = 0 ; i < n ; i++){
                a.add(sc.nextInt());
            }

            int retVal = 360;

            for(int i = 0 ; i < a.size() ; i++){
                for(int j = i ; j < a.size() ; j++){
                    int retValCand = 0;
                    for(int k = i ; k < j ; k++){
                        retValCand += a.get(k);
                    }
                    int retValCand2 = 360 - retValCand;
                    retVal = Math.min(retVal , Math.abs(retValCand2 - retValCand));
                }
            }

            pw.println(retVal);

            pw.flush();
            sc.close();
        }
    }

}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author dannyyang
 */
public class PizzaSeparation {

    /**
     * @param args the command line arguments
     */
    static int N;
    static int answer=360;
    static int a[];
    public static void move(int position, int sum, boolean taking){
        if(position==N){
            answer=Math.min(answer, Math.abs((180-sum)*2));
            return;

        }
        if(!taking){
        move(position+1,sum,false);
        move(position+1,sum+a[position],true);
        }
        else{
            answer=Math.min(answer, Math.abs((180-sum)*2));
            move(position+1,sum+a[position],true);
        }

    }
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        N=input.nextInt();
        a=new int[N];
        for(int i=0;i<N;i++){
            a[i]=input.nextInt();
        }
        move(0,0,false);
        System.out.println(answer);

    }

}

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    private static final int MAXN=360+24;
    private static int angle[]=new int[MAXN];
    private static boolean dp[]=new boolean[MAXN];
    public static void main(String[] arg){
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        while (in.hasNext()) {
            int n;
            n=in.nextInt();
            for(int i=0;i<n;i++){
                angle[i]=in.nextInt();
            }
            int result=360;
            for(int i=0;i<n;i++){
                int sum=0;
                for(int j=i;j<n;j++){
                    sum+=angle[j];
                    result=Math.min(result,Math.abs(360-2*sum));
                }
            }
            out.println(Math.abs(result));
            out.flush();
        }
        in.close(); out.close();
    }
}

import java.io.*;
import java.util.*;

public class A895 {

    public static int n;
    public static int max = 0;
    public static void main(String[] args) throws IOException{

      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));

      n = sc.nextInt();
      int[] pieces = new int[n];

      for(int i = 0; i < n; i++){
          pieces[i]=sc.nextInt();
      }
      int temp = 0;
      int max = 0;

      for(int i = 0; i < n; i++){
          for(int j = 0; j < n; j++){
              int k = (i+j)%n;
              if(temp + pieces[k] > 180){
                  max = Math.max(temp,max);
                  break;
              } else if(temp + pieces[k] == 180){
                  out.println(0);
                  out.close();
                  return;
              } else {
                  temp += pieces[k];
              }
          }
          temp = 0;
      }

      out.println(2*(180-max));
      out.close();

    }

    /*public static void recurse(int val, int m, int[] pieces){
        if(val == 180){
            max = 180;
            return;
        }
        max = Math.max(max,val);
        if (m < n) {
            recurse(val,m+1,pieces);
            if(val + pieces[m] <= 180)
                recurse(val+pieces[m], m+1, pieces);
        }
    }*/

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
    }
}

import java.util.*;
import java.lang.*;
import java.io.*;

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

		int N = in.nextInt();
		int[] arr = new int[N];
		for(int i=0; i<N; i++) arr[i] = in.nextInt();

		int minDiff = 360;
		for(int i=0; i<N-1; i++) {
			int sum = 0;
			for(int j=i; j<N; j++) {
				sum += arr[j];
				int diff = Math.abs(sum-(360-sum));
				if(diff < minDiff) minDiff = diff;
			}
		}
		System.out.println(minDiff);
	}
}

import java.util.Scanner;

public class main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] angles = new int[n];
        for (int i = 0; i < n; i++) {
            angles[i] = scan.nextInt();
        }

        int min = 360;
        int v, p;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v = p = 0;
                for (int k = 0; k < j; k++) {
                    v += angles[(i + k) % n];
                }
                for (int k = j; k < n; k++) {
                    p += angles[(i + k) % n];
                }
                int dif =Math.abs(v-p);
                min = Math.min(min,dif);
            }
        }

        System.out.println(min);
    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class contest {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int []a=new int [n];

		for(int i=0;i<n;i++)a[i]=sc.nextInt();

		int lo=0;int hi=0;
		int max =0;int count=0;
		int countt= 1000;
		while(countt>0) {
			if(hi==n)hi=0;
			if(lo==n)lo=0;
			count+=a[hi];
			if(count>180) {
				count-=a[hi];
				max= Math.max(max, count);
				hi--;count-=a[lo];
				lo++;
			}
			hi++;
			countt--;
		}
		max=Math.max(max, count);
		System.out.println(360-2*max);

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

import java.io.*;
import java.lang.*;
public class CF895A {
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] a = new int[n];
        int sum = 0;
        int diff;
        int min = Integer.MAX_VALUE;
        for(int i=0;i<n;i++) {
            sum = Integer.parseInt(s[i]);
            if(i>0){
                a[i] = a[i-1] + sum;
            }else{
                a[i] = sum;
            }
            /**/
        }

        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++){
                sum = Math.abs(a[j] - a[i]);
                diff = Math.abs((360-sum)-sum);
                if(diff < min){
                    min = diff;
                }
            }
        }
        System.out.println(min);
    }
}

//A
//Pizza
import java.io.*;
import java.util.*;

public class B
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] pizza = new int[n];
    int min = Integer.MAX_VALUE;
    for(int i = 0 ; i < n  ; i++)
       pizza[i] = sc.nextInt();

    for(int i = 0 ; i < n ; i++)
    {
      int curSum = pizza[i];
      min = Math.min(Math.abs(curSum - (360 - curSum)), min);
      for(int j = i + 1 ; j < n ; j++)
      {
          curSum += pizza[j];
          min = Math.min(Math.abs(curSum - (360 - curSum)), min);
      }
    }
    System.out.println(min);
  }
}

import java.util.*;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {
	public static void main(String args[]){
		FastScanner in = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}

		int min = 9999999;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n+1; j++){
				//sum from i to j
			//	System.out.println(i+" "+j);
				int sum1 = 0;
				for(int k = i; k < j; k++){
					//System.out.println("   "+k+"   "+a[k]);
					sum1 += a[k];
				}
				//System.out.println("s: "+sum1);
				min = Math.min(min, Math.abs(360 - 2 * sum1));
				//System.out.println();
			}

		}
		System.out.println(min);

	}

	static class FastScanner{
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(String s) {
			try{
				br = new BufferedReader(new FileReader(s));
			}
			catch(FileNotFoundException e) {
				e.printStackTrace();
			}
		}
		public FastScanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String nextToken()	{
			while(st == null ||!st.hasMoreElements()){
				try {
				st = new StringTokenizer(br.readLine());}
				catch(IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}
		long nextLong() {
			return Long.parseLong(nextToken());
		}
		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
		String next() {
			return nextToken();
		}

	}

}

import java.util.*;
public class A{
       public static void main(String args[]){
              Scanner sc = new Scanner(System.in);
              int n = sc.nextInt();
              int a[] = new int[n*2];
              for(int i = 0; i < n; i++){
                     a[i] = sc.nextInt();
                     a[i + n] = a[i];
              }

              int min = Integer.MAX_VALUE;
              for(int i = 0; i < n; i++){
                     int sum = 0;
                     for(int j = i; j < 2*n; j++){
                            sum += a[j];
                            if(sum > 360)break;
                            int sum2 = 360 - sum;
                            min = Math.min(min, Math.abs(sum2 - sum));
                     }
              }
              System.out.println(min);
       }
}

//package March16;

import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{
	public static void main(String[] args) throws java.lang.Exception{
		InputStream inputstream = System.in;
		OutputStream outputstream = System.out;
		InputReader in = new InputReader(inputstream);
		PrintWriter out = new PrintWriter(outputstream);
		Call one = new Call();
		one.solve(in,out);
		out.close();
	}
	static class Call {
		public void solve(InputReader in,PrintWriter out) {
			int n = in.nextInt();
			int a[] = new int[n];
			for(int i=0;i<n;i++) {
				a[i]=in.nextInt();
			}
			int res = 360;
			for(int i=0;i<n-1;i++) {
				int sum = 0;
				for(int j=i;j<n;j++) {
					sum+=a[j];
					res=Math.min(res, Math.abs(sum-(360-sum)));
				}
			}
			out.println(res);
		}
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader (stream),32768);
			tokenizer = null;
		}
		public String next() {
				while(tokenizer == null || !tokenizer.hasMoreElements()) {
					try {
						tokenizer = new StringTokenizer(reader.readLine());
					}
					catch(IOException e) {
						throw new RuntimeException(e);
					}
				}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}

import java.util.Scanner;

public class main2 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		 int n = in.nextInt();
		    int[] tab = new int[n];
		    for(int i = 0 ; i < n ; i++) {
		      tab[i] = in.nextInt();
		    }
		    int sum = 0 ;
		    int diff = 360;
		    for(int i = 0 ; i < n ; i++) {
		      sum = 0;
		      for(int j = i ; j < i + n ; j++){
		        //System.out.println(j + " ");
		        sum += tab[j%n];
		       // System.out.println(sum + " ");
		        if(Math.abs(360 - 2 * sum) < diff)
		          diff = Math.abs(360 - 2 * sum);
		      }
		    }
		    System.out.println(diff);

	}
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author yashk
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int a[] = in.nextIntArray(n);

            int ans = 360;
            for (int i = 0; i < n - 1; i++) {
                int x = a[i];
                int y = 360 - x;
                ans = Math.min(ans, Math.abs(x - y));
                for (int j = i + 1; j != i; j = (j + 1) % n) {
                    x += a[j];
                    y = 360 - x;
                    ans = Math.min(ans, Math.abs(x - y));
                }
            }
            out.print(ans);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(int i) {
            writer.print(i);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

// package codeforces.A;

import java.util.Scanner;

public class cf895A
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] inputs = new int[n];

        for (int i = 0; i < n; i++)
        {
            inputs[i] = in.nextInt();
        }

        int minDegree = 361;
        for (int i = 0; i < n; i++)
        {
            int sum = inputs[i];
            for (int j = i - 1; sum < 180; j--)
            {
                if (j < 0)
                {
                    j = n-1;
                }
                sum += inputs[j];
            }
            minDegree = Math.min(sum, minDegree);
            sum = inputs[i];
            for (int j = i + 1; sum < 180; j++)
            {
                if (j >= n)
                    j = 0;

                sum += inputs[j];
            }
            minDegree = Math.min(sum, minDegree);
        }

        System.out.print(2*minDegree - 360);
    }
}

import java.util.Scanner;

/**
 * Created by egorz on 12/3/2017.
 */
public class A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        int max = 0;
        for (int i = 0; i < n; i++) {
            int buf = 0;
            for (int j = i + 1; j < i + n; j++) {
                buf += a[j % n];
                if (buf <= 180 && buf> max)
                    max = buf;
            }
        }

        System.out.println((2*(180 - max)));
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inclass in = new inclass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APizzaSeparation solver = new APizzaSeparation();
        solver.solve(1, in, out);
        out.close();
    }

    static class APizzaSeparation {
        public void solve(int testNumber, inclass in, PrintWriter out) {
            int n = in.nextInt();
            int arr[] = in.nextIntArray(n);
            int cum[] = new int[n];
            cum[0] = arr[0];
            for (int i = 1; i < n; i++) {
                cum[i] = cum[i - 1] + arr[i];
            }
            int diff = 360;
        /*
        for (int i = 0; i < n; i++) {
            diff=Math.min(diff,arr[i]);
        }*/
            int sum1 = 0, sum2 = 0;
            for (int i = 0; i < n; i++) {
                sum1 += arr[i];
                sum2 = cum[n - 1] - cum[i];
                if (sum1 != 0 && sum2 != 0)
                    diff = Math.min(diff, Math.abs(sum2 - sum1));
            }
            sum1 = 0;
            for (int j = 0; j < n; j++) {
                sum1 += arr[j];
                int t = sum1;
                for (int i = n - 1; i >= j + 1; i--) {
                    sum2 = cum[i - 1] - cum[j];
                    t += arr[i];
                    if (sum1 != 0 && sum2 != 0)
                        diff = Math.min(diff, Math.abs(sum2 - t));
                }
            }
            out.println(diff);
        }

    }

    static class inclass {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private inclass.SpaceCharFilter filter;

        public inclass(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}

import java.util.Scanner;

public class Main {

    static int n, sol, auxs;
    static int pizza[];

    public static void main(String args[]) {
        Scanner l = new Scanner(System.in);
        n = l.nextInt();
        pizza = new int[n];
        for (int i = 0; i < n; i++) {
            pizza[i] = l.nextInt();
        }
        sol = 360;
        for (int i = 0; i < n; i++) {
            auxs = 0;
            for (int k = 0; i + k <= n; k++) {
                sol = Math.min(sol, Math.abs(360 - auxs * 2));
                if (i + k < n) {
                    auxs += pizza[i + k];
                }
            }
        }
        System.out.println(sol);
    }
}

import java.util.Scanner;

public class A {

	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[] a=new int[n];
		for (int i=0; i<n; i++)
			a[i]=s.nextInt();
		int min=Integer.MAX_VALUE;

		for (int i=0; i<n; i++) {
			for (int j=i; j<n; j++) {
				int s1=0, s2=0;
				for (int k=0; k<i; k++)
					s1+=a[k];
				for (int k=i; k<=j; k++)
					s2+=a[k];
				for (int k=j+1; k<n; k++)
					s1+=a[k];
				min=Math.min(min, Math.abs(s1-s2));
			}
		}
		System.out.println(min);

	}

}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author dannyyang
 */
public class PizzaSeparation {

    /**
     * @param args the command line arguments
     */
    static int N;
    static int answer=360;
    static int a[];
    public static void move(int position, int sum, boolean taking){
        if(position==N){
            answer=Math.min(answer, Math.abs((180-sum)*2));
            return;

        }
        if(!taking){
        move(position+1,sum,false);
        move(position+1,sum+a[position],true);
        }
        else{
            answer=Math.min(answer, Math.abs((180-sum)*2));
            move(position+1,sum+a[position],true);
        }

    }
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        N=input.nextInt();
        a=new int[N];
        for(int i=0;i<N;i++){
            a[i]=input.nextInt();
        }
        move(0,0,false);
        System.out.println(answer);

    }

}

import java.util.Arrays;
import java.util.Scanner;

public class TestJava {

	public static void main(String args[]) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int ar[] = new int[n];
			int sum = 0;
			for (int i = 0; i < n; i++) {
				ar[i] = sc.nextInt();
			}

			System.out.println(getMin(n, ar));

		}
	}

	private static int getMin(int n, int[] ar) {
		int lis =  Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			int sum = 0;
			for (int j = i; j < i + n; j++) {
				int tmp = j % n;
				sum += ar[tmp];
				lis = Math.min(lis, 2 * Math.abs(sum - 180));
			}
		}
		return lis;
	}
}

import java.lang.*;
import java.util.Scanner;
public class Main {
  public static int result(int array[], int n) {
//    int n = array.length();
//    int n = 6;
    int i = 0, j = 0, add = 0, sub = 0, dif =0, ans = 360;
    if (n == 1) return 360;
//    else (n == 2) return Math.abs(array[0] - array[1]);
    else {
      while(i < n) {
        add += array[i++];
        if (add - sub == 180) return 0;
        dif = Math.abs(360 - 2 * (add - sub));
        if (dif < ans) ans = dif;
//        System.out.println(ans);
        while(j < i && add - sub > 180) {
          sub += array[j++];
          if (add - sub == 180) return 0;
          dif = Math.abs(360 - 2 * (add - sub));
          if (dif < ans) ans = dif;
//          System.out.println(ans);
        }
      }
    }
    return ans;
  }

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int array[] = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = sc.nextInt();
    }
    System.out.println(result(array, n));
  }
}

import java.util.*;
import java.lang.*;
import java.io.*;

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

		int N = in.nextInt();
		int[] arr = new int[N];
		for(int i=0; i<N; i++) arr[i] = in.nextInt();

		int minDiff = 360;
		for(int i=0; i<N-1; i++) {
			int sum = 0;
			for(int j=i; j<N; j++) {
				sum += arr[j];
				int diff = Math.abs(sum-(360-sum));
				if(diff < minDiff) minDiff = diff;
			}
		}
		System.out.println(minDiff);
	}
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class ActivityTestController {

    public static void main (String[] args){

            Scanner sc1 = new Scanner(System.in);
            int str1 = sc1.nextInt();

            List<Integer> str2 = new ArrayList<>();
            for (int size=0;size<str1;size++){
                str2.add(sc1.nextInt());
            }
            Integer i = 0;

            List<Integer> output = new ArrayList<>();
            for (;i<str2.size();i++){
                Integer b1 = 0;
                Integer l = i;
                for (Integer k=0 ;k< str2.size();k++){
                    if (l>=str2.size())
                        l=l-str2.size();
                    b1 += str2.get(l);
                    if (b1>=180)
                        break;
                    l++;
                }
                output.add(Math.abs((360-b1)-b1));
            }
            output = output.stream().sorted().collect(Collectors.toList());
            System.out.print(output.get(0));

        }
}

import java.util.Arrays;
import java.util.Scanner;

public class A_448 {

	public static int[][] memo;

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = scn.nextInt();
		}
		int res = 360;
		for(int i = 0; i < n; i++) {
			for(int j = 1; j < n; j++) {
				int a = 0, b = 360;
				for(int k = i; k < i+j;k++) {
					a += arr[k%n];
					b -= arr[k%n];
				}
				res = Math.min(res, Math.abs(a-b));
//				System.out.println(a+" "+b+" i"+i+"  "+ Math.abs(a-b));
			}
		}

		System.out.println(res);
	}

}

import java.util.Scanner;

public class TaskA {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int s = 360;
		int sum;
		for(int i = 0; i < n; i++) {
			sum = 0;
			for(int j = i; j < n+i; j++) {
				if(Math.abs(180-sum) < Math.abs(180-sum-a[j%n])) break;
				sum += a[j%n];
				s = Math.min(s, Math.abs(2*sum-360));
			}
		}
		System.out.println(s);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class ProblemA {
	static Scanner sc = new Scanner(System.in);
	static PrintWriter pw = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();

		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				int sum = 0, x = i;
				while (true) {
					if (x == n)
						x = 0;
					sum += a[x];
					if (x == j)
						break;
					x++;
				}
				ans = Math.min(ans, Math.abs(sum - (360 - sum)));
			}
		}
		pw.println(ans);
		pw.flush();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		public Scanner(InputStream s) {
			// TODO Auto-generated constructor stub
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public Long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/* Name of the class has to be "Main" only if the class is public. */
public class bbg
{
	public static int result;

public static ArrayList<Integer> [] graph;

public static int[]cats;

public static int vizitat[];
public static int x;
//public static HashMap<String, Integer> map2;

	public static void main (String[] args) throws java.lang.Exception
{

Scanner input=new Scanner(System.in);

HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>();

HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<String, Integer> curatare= new HashMap<String, Integer>();
HashMap<String, Integer> combinari= new HashMap<String, Integer>();

	  int n=input.nextInt();
	 int v[]=new int[2*n];

	  int a;

	  for(int i=0;i<n;i++)  {v[i]=input.nextInt();
	  	v[i+n]=v[i];

				}

				int min=361;

				for(int i=0;i<n;i++){

					for(int j=0;j<n;j++){

							int sum=0;

							for(int x=i;x<i+j;x++) sum+=v[x];

								min=Math.min(min,Math.abs(360-2*sum));

					}

				}

System.out.println(min);

	 }

		}

//package codeforces_div2_448;

import java.io.*;
import java.util.*;
import java.math.*;

/**
 *
 * @author Tushar 26 Nov, 2017
 */
public class B {
    public static void main(String args[])
    {

        //File file= new File("COMPLETE_FILE_PATH");
        //InputStream is = new FileInputStream(file);

        //InputReader in = new InputReader(is);
        InputReader in = new InputReader(System.in);
        PrintWriter out= new PrintWriter(System.out);

        int t=1;
        Task solver=new Task();
        //long start = System.nanoTime();
        solver.solve(t,in,out);
        //long stop = System.nanoTime();
        //System.out.println("Execution time: " + ((stop - start) / 1e+6) + "ms.");

        out.flush();
        out.close();

    }

    static class Task {
        long mod = 1000000007;

        public void solve(int testNumber, InputReader in,PrintWriter out){
            int n= in.nextInt();
            int[] arr= new int[n];

            int sum=0;
            for(int i=0;i<n;i++){
                arr[i]=in.nextInt();
                sum+=arr[i];
            }

            if(sum!=360){
                int first=0;
                int diff=Integer.MAX_VALUE;
                for(int i=0;i<n;i++){
                    first+=arr[i];
                    if(Math.abs(sum-2*first)<diff)    diff=Math.abs(sum-2*first);
//                    out.print(diff+" ");
                }
                out.println(diff);
            }
            else{
                int diff= Integer.MAX_VALUE;
                for(int i=0;i<n;i++){
                    diff= Math.min(diff,find(arr,i,sum));
                }
                out.println(diff);
            }

        }

        int find(int[] arr,int index,int total){
            int minDiff= 360;
            int i=(index+1)%arr.length;
            int first=arr[index];
            while(i!=index){
                if(Math.abs(360-2*first)<minDiff)    minDiff=Math.abs(360-2*first);
                first+=arr[i];
                i=(i+1)%arr.length;
            }
            return minDiff;
        }

        int LOG2(long item){
            int count=0;
            while(item>1){
                item>>=1;count++;
            }
            return count;
        }

        long power(long x, long n) {
            if (n <= 0) {
                return 1;
            }
            long y = power(x, n / 2);

            if ((n & 1) == 1) {
                return (((y * y) % mod) * x) % mod;
            }

            return (y * y) % mod;
        }

        long gcd(long a, long b) {
            a = Math.abs(a);
            b = Math.abs(b);
            return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).longValue();
        }
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String next() {
            return readString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

}

import java.util.Scanner;

public class Pizza {
    public static void main(String[] args) {
        int l, r;
        int bl, br;
        int t, bt;
        int n;
        int[] Pi;
        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        Pi = new int[n];
        for (int i = 0; i < n; i++) {
            Pi[i] = in.nextInt();
        }
        in.close();
        l = 0;
        r = 0;
        bl = 0;
        br = 0;
        t = 2 * Pi[0] - 360;
        bt = Math.abs(t);
        first:
        for (int g = 0; g < 2 * n; g++) {
            if (t < 0) {
                r++;
                r = r % n;
                t += 2 * Pi[r];
                if (Math.abs(t) < bt) {
                    bt = Math.abs(t);
                    bl = l;
                    br = r;
                }
            } else if (t > 0) {
                t -= 2 * Pi[l];
                l++;
                l = l % n;
                if (Math.abs(t) < bt) {
                    bt = Math.abs(t);
                    bl = l;
                    br = r;
                }
            } else {
                bl = l;
                br = r;
                break first;
            }
        }
        bl++;
        br++;
        //System.out.println(bl + " " + br);
        int sum = 0;
        for (int i = bl - 1; i < br; i++) {
            sum += Pi[i];
        }
        int sum1 = 360 - sum;
        System.out.println(Math.abs(sum - sum1));
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] angs = new int[n * 2];
            for (int i = 0; i < n; ++i) {
                angs[i] = in.nextInt();
                angs[n + i] = angs[i];
            }
            int[] su = new int[n * 2 + 1];
            for (int i = 1; i <= 2 * n; ++i) {
                su[i] = su[i - 1] + angs[i - 1];
            }
            int ans = 360;
            for (int i = 1; i < 2 * n + 1; ++i) {
                for (int j = i; j < 2 * n + 1; ++j) {
                    int c = su[j] - su[i - 1];
                    ans = Math.min(ans, Math.abs(360 - 2 * c));
                }
            }
            out.println(ans);
        }

    }
}

import java.util.*;

public class Main
{

    public static void main(String[] args)
    {
       Scanner sc=new Scanner(System.in);
       StringBuilder sb=new StringBuilder();
       int n=sc.nextInt();
       int a[]=new int[n];
       for( int i=0;i<n;i++)
       {
           a[i]=sc.nextInt();
       }
       int diff=Integer.MAX_VALUE;
      for( int i=0;i<n;i++)
      {
          for( int j=i;j<n;j++)
          {
              int sum=0;
              for( int k=i;k<=j;k++)
              {
                  sum+=a[k];
              }
              diff=Math.min(diff, Math.abs(360-2*sum));
          }
      }
        System.out.println(diff);

	}

}
class Pair{
    int size;
    int l;
    int r;
    Pair( int size, int l, int r)
    {
        this.size=size;
        this.l=l;
        this.r=r;
    }
}
class myComparator implements Comparator<Pair>
{
    public int compare( Pair a, Pair b)
    {
     if(a.size==b.size)
     {
         return Integer.compare(a.l,b.l);
     }else
     return Integer.compare(b.size,a.size);
    }
}

import java.util.*;
public class pizza{

    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];

        for(int i = 0;i < n;i++)
            arr[i] = s.nextInt();

        //continuous sectors
        int mindiff = 100000;
//             mindiff = arr[i]
        for(int i = 0;i < n ;i++){
            int sum = 0;
            for(int j = i;j < n;j++){
                sum += ( arr[j] );
                int diff = 2*Math.abs(180 - sum);
                if(diff < mindiff)
                    mindiff = diff;

            }
        }

        System.out.println(Math.abs(mindiff));

    }
}

import java.io.*;
import java.util.*;

public class App {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		ArrayList<Integer> ls = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			ls.add(in.nextInt());
		}
		int res = 360;
		int choose;
		for(int k = 1; k <= n; k++) {
			for(int i = 0; i <= n - k; i++) {
				choose = 0;
				for(int j = 0; j < k; j++) {
					choose += ls.get(i + j);
				}
				res = Math.min(res, Math.abs(choose - 360 + choose));
			}
		}
		System.out.print(res);
	}
}

import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

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

		int N = input.nextInt();

		int[] weights = new int[N];
		for (int i = 0; i < N; i++)
			weights[i] = input.nextInt();

		int min = 360;

		for (int i = 0; i < N; i++) {
			int sum = 0;
			for (int j = i; j < N; j++) {
				sum += weights[j];
				min = Math.min(min, Math.abs(360 - 2 * sum));
			}
		}

		System.out.println(min);
	}

	// Matt Fontaine's Fast IO
	static class FastScanner {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public FastScanner(InputStream stream) {
			this.stream = stream;
		}

		int read() {
			if (numChars == -1)
				throw new InputMismatchException();
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (numChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		boolean isEndline(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String next() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		String nextLine() {
			int c = read();
			while (isEndline(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndline(c));
			return res.toString();
		}
	}
}

import java.util.Scanner;

public class main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] angles = new int[n];
        for (int i = 0; i < n; i++) {
            angles[i] = scan.nextInt();
        }

        int min = 360;
        int v, p;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                v = p = 0;
                for (int k = 0; k < j; k++) {
                    v += angles[(i + k) % n];
                }
                for (int k = j; k < n; k++) {
                    p += angles[(i + k) % n];
                }
                int dif =Math.abs(v-p);
                min = Math.min(min,dif);
            }
        }

        System.out.println(min);
    }

}

import java.io.*;
import java.util.*;

public class A895 {

    public static int n;
    public static int max = 0;
    public static void main(String[] args) throws IOException{

      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));

      n = sc.nextInt();
      int[] pieces = new int[n];

      for(int i = 0; i < n; i++){
          pieces[i]=sc.nextInt();
      }
      int temp = 0;
      int max = 0;

      for(int i = 0; i < n; i++){
          for(int j = 0; j < n; j++){
              int k = (i+j)%n;
              if(temp + pieces[k] > 180){
                  max = Math.max(temp,max);
                  break;
              } else if(temp + pieces[k] == 180){
                  out.println(0);
                  out.close();
                  return;
              } else {
                  temp += pieces[k];
              }
          }
          temp = 0;
      }

      out.println(2*(180-max));
      out.close();

    }

    /*public static void recurse(int val, int m, int[] pieces){
        if(val == 180){
            max = 180;
            return;
        }
        max = Math.max(max,val);
        if (m < n) {
            recurse(val,m+1,pieces);
            if(val + pieces[m] <= 180)
                recurse(val+pieces[m], m+1, pieces);
        }
    }*/

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
    }
}

import java.io.*;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = readInt();
        int answer = 360;
        int[] a = readIntArray(n);
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                int c = 0;
                for (int h = i; h <=j; h++) {
                  c+=a[h];
                }
                answer = minInt(answer,Math.abs(180-c)*2);
            }
        }
        out.print(answer);
    }

    class SegmentTree {
        int[] t;

        SegmentTree(int[] a, int n) {
            t = new int[4 * n];
            build(a, 1, 1, n);
        }

        void build(int[] a, int v, int tl, int tr) {
            if (tl == tr) {
                t[v] = a[tl];
                return;
            }

            int tm = (tl + tr) / 2;
            build(a, 2 * v, tl, tm);
            build(a, 2 * v + 1, tm + 1, tr);
            t[v] = Math.min(t[2 * v], t[2 * v + 1]);
        }

        void update(int v, int tl, int tr, int pos, int value) {
            if (tl == tr) {
                t[v] = value;
                return;
            }
            int tm = (tl + tr) / 2;
            if (pos <= tm) {
                update(2 * v, tl, tm, pos, value);
            } else {
                update(2 * v + 1, tm + 1, tr, pos, value);
            }

            t[v] = Math.min(t[2 * v], t[2 * v + 1]);
        }

        int getMin(int v, int tl, int tr, int l, int r) {
            if (l > r) {
                return INF;
            }
            if (tl == l && tr == r) {
                return t[v];
            }

            int tm = (tl + tr) / 2;

            int min1 = getMin(2 * v, tl, tm, l, Math.min(tm, r));
            int min2 = getMin(2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r);

            return Math.min(min1, min2);
        }
    }

    int checkBit(int mask, int bit) {
        return (mask >> bit) & 1;
    }

    public static void main(String[] args) throws IOException {

        new Main().run();
    }

    boolean isLower(char a) {
        return ((int) a) >= 97 ? true : false;
    }

    int INF = Integer.MAX_VALUE / 10;

    int[][] STEPS = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;
    Random rnd = new Random();
    static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    Main() throws FileNotFoundException {

        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }

        tok = new StringTokenizer("");
    }

    long checkBit(long mask, int bit) {
        return (mask >> bit) & 1;
    }

    void run() throws IOException {
        solve();
        out.close();
    }

    char varChar;
    int varInt, varInt1, varInt2;
    long varLong;

    void swapInt(int a, int b) {
        varInt = a;
        a = b;
        b = varInt;
    }

    void swapChar(char a, char b) {
        varChar = a;
        a = b;
        b = varChar;
    }

    void swapLong(long a, long b) {
        varLong = a;
        a = b;
        b = varLong;
    }

    void reverseCharArray(char[] arr) {
        for (int i = 0; i < arr.length; i++) swapChar(arr[i], arr[arr.length - i - 1]);
    }

    int sqrt(double m) {
        varInt1 = 0;
        varInt2 = Integer.MAX_VALUE;
        int i = 1000;
        while (varInt2 >= varInt2) {
            i = (varInt2 + varInt1) / 2;
            if ((long) i * i > m) {
                varInt2 = i - 1;
            } else {
                varInt1 = i + 1;
                varInt = varInt1 - 1;
            }
        }
        return varInt;
    }

    int countPow(int m, int n) {
        varInt = 0;
        while (m % n == 0 && m > 0) {
            varInt++;
            m /= n;
        }
        return varInt;
    }

    long binPow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b % 2 == 1) {
            return a * binPow(a, b - 1);
        } else {
            varLong = binPow(a, b / 2);
            return varLong * varLong;
        }

    }

    int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long pow(long x, long k) {
        varLong = 1;
        for (int i = 0; i < k; ++i) {
            varLong *= x;
        }
        return varLong;
    }

    class Fenwik {
        private long[] t;
        private int length;

        Fenwik(int[] a) {
            this.length = a.length + 100;
            this.t = new long[length];
            for (int i = 0; i < a.length; ++i) {
                this.inc(i, a[i]);
            }
        }

        void inc(int i, int delta) {
            for (; i < this.length; i = i | (i + 1)) {
                this.t[i] += delta;
            }
        }

        long getSum(int r) {
            long sum = 0;

            for (; r >= 0; r = (r & (r + 1)) - 1) {
                sum += this.t[r];
            }

            return sum;
        }
    }

    // ////////////////////////////////////////////////////////////////////

    String delimiter = " ";

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine)
                return null;

            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken(delimiter);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int b) {
        int a[] = new int[b];
        for (int i = 0; i < b; i++) {
            try {
                a[i] = readInt();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a;
    }

    int[] readSortedIntArray(int size) throws IOException {
        Integer[] array = new Integer[size];

        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    int[] sortedIntArray(int size, int[] array) throws IOException {
        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    int minInt(int... values) {
        int min = Integer.MAX_VALUE;
        for (int value : values) {
            min = Math.min(min, value);
        }
        return min;
    }

    int maxInt(int... values) {
        int max = Integer.MIN_VALUE;
        for (int value : values) {
            max = Math.max(max, value);
        }
        return max;
    }

    long minLong(long... values) {
        long min = Long.MAX_VALUE;
        for (long value : values) {
            min = Math.min(min, value);
        }
        return min;
    }

    long maxLong(long... values) {
        long max = Long.MIN_VALUE;
        for (long value : values) {
            max = Math.max(max, value);
        }
        return max;
    }

    boolean checkIndex(int index, int size) {
        return (0 <= index && index < size);
    }

    int abs(int a) {
        return Math.abs(a);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.io.BufferedOutputStream;
import java.util.StringTokenizer;
import java.io.Closeable;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.Flushable;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	static class TaskAdapter implements Runnable {
		@Override
		public void run() {
			InputStream inputStream = System.in;
			OutputStream outputStream = System.out;
			Input in = new Input(inputStream);
			Output out = new Output(outputStream);
			APizzaSeparation solver = new APizzaSeparation();
			solver.solve(1, in, out);
			out.close();
		}
	}

	public static void main(String[] args) throws Exception {
		Thread thread = new Thread(null, new TaskAdapter(), "", 1<<29);
		thread.start();
		thread.join();
	}
	static class APizzaSeparation {
		public APizzaSeparation() {
		}

		public void solve(int testNumber, Input in, Output pw) {
			int n = in.nextInt();
			int[] arr = new int[n];
			for(int i = 0; i<n; i++) {
				arr[i] = in.nextInt();
			}
			int ans = 360;
			for(int i = 0; i<n; i++) {
				for(int j = i; j<n; j++) {
					int sum1 = 0, sum2 = 0;
					for(int k = 0; k<i; k++) {
						sum1 += arr[k];
					}
					for(int k = i; k<=j; k++) {
						sum2 += arr[k];
					}
					for(int k = j+1; k<n; k++) {
						sum1 += arr[k];
					}
					ans = Math.min(ans, Math.abs(sum2-sum1));
				}
			}
			pw.println(ans);
		}

	}

	static class Output implements Closeable, Flushable {
		public StringBuilder sb;
		public OutputStream os;
		public int BUFFER_SIZE;
		public boolean autoFlush;
		public String LineSeparator;

		public Output(OutputStream os) {
			this(os, 1<<16);
		}

		public Output(OutputStream os, int bs) {
			BUFFER_SIZE = bs;
			sb = new StringBuilder(BUFFER_SIZE);
			this.os = new BufferedOutputStream(os, 1<<17);
			autoFlush = false;
			LineSeparator = System.lineSeparator();
		}

		public void println(int i) {
			println(String.valueOf(i));
		}

		public void println(String s) {
			sb.append(s);
			println();
			if(autoFlush) {
				flush();
			}else if(sb.length()>BUFFER_SIZE >> 1) {
				flushToBuffer();
			}
		}

		public void println() {
			sb.append(LineSeparator);
		}

		private void flushToBuffer() {
			try {
				os.write(sb.toString().getBytes());
			}catch(IOException e) {
				e.printStackTrace();
			}
			sb = new StringBuilder(BUFFER_SIZE);
		}

		public void flush() {
			try {
				flushToBuffer();
				os.flush();
			}catch(IOException e) {
				e.printStackTrace();
			}
		}

		public void close() {
			flush();
			try {
				os.close();
			}catch(IOException e) {
				e.printStackTrace();
			}
		}

	}

	static class Input {
		BufferedReader br;
		StringTokenizer st;

		public Input(InputStream is) {
			this(is, 1<<20);
		}

		public Input(InputStream is, int bs) {
			br = new BufferedReader(new InputStreamReader(is), bs);
			st = null;
		}

		public boolean hasNext() {
			try {
				while(st==null||!st.hasMoreTokens()) {
					String s = br.readLine();
					if(s==null) {
						return false;
					}
					st = new StringTokenizer(s);
				}
				return true;
			}catch(Exception e) {
				return false;
			}
		}

		public String next() {
			if(!hasNext()) {
				throw new InputMismatchException();
			}
			return st.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

	}
}

import java.util.*;
import java.io.*;

public class ProbA implements Runnable{

	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;

	private static void soln(){
		int n = nextInt();
		int[] b = nextIntArray(n);
		int[] pre = new int[n+1];
		int[] pos = new int[n+1];
		pre[0] = 0;
		pos[n] = 0;
		for (int i=1; i<=n; i++) {
			pre[i] = pre[i-1]+b[i-1];
		}
		for (int i=n-1; i>=0; i--) {
			pos[i] = pos[i+1]+b[i];
		}

//		pArray(pos);

		int ans = 360;
		for (int i=1; i<=n; i++) {
			for (int j=n; j>=i+1; j--) {
				int temp = pre[i] + pos[j];
				int temp1 = 360 - temp;
				int temp2 = temp>temp1?temp- temp1 : temp1 - temp;
				ans = (ans>temp2) ? temp2 : ans;
//				pw.println(ans);
			}

		}
		pw.println(ans);

	}

	public void run (){
		soln();
	}

	public static void main(String[] args) throws InterruptedException{
		InputReader(System.in);
		pw = new PrintWriter(System.out);
		Thread t = new Thread(null, new ProbA(), "ProbA", 1<<28);
		t.start();
		t.join();
		pw.close();
	}

	// To Get Input
	// Some Buffer Methods

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

	private static boolean isWhitespace(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n) {
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n) {
		long[] arr = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr){
		for (int i=0; i<arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.stream.Stream;

/**
 * Success is not final, failure is not fatal. The courage to continue is what counts.
 * @author bodmas
 */
public class ProblemA {

    private int solve(int[] a) {
        int[][] sum = new int[a.length + 1][a.length + 1];
        int min = Integer.MAX_VALUE;
        for (int i = 1; i <= a.length; i++) {
            sum[i][i] = a[i - 1];
            min = Math.min(min, Math.abs(360 - 2 * sum[i][i]));
            for (int j = 1; j < i; j++) {
                sum[j][i] = sum[j][i - 1] + sum[i][i];
                min = Math.min(min, Math.abs(360 - 2 * sum[j][i]));
            }
        }
        return min;
    }

    public static void main(String[] args) throws IOException {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {
            in.readLine();
            int[] a = Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            out.println(new ProblemA().solve(a));
        }
    }
}

import java.util.*;
import java.io.*;
import java.lang.Math.*;

public class MainA
{

	static int mod = (int) 1e9 + 7;
	static int prime[]=new int[100000+1];
	public static void main(String[] args) throws java.lang.Exception
	{
		InputReader in = new InputReader(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=in.nextInt();
		int a[]=new int[n];
		int b[]=new int[2*n];
		//ArrayList<Integer> arr=new ArrayList<Integer>();
		for(int i=0;i<n;i++)b[i]=a[i]=in.nextInt();
		for(int i=0;i<n;i++)b[n+i]=a[i];
		int min=Integer.MAX_VALUE;
		for(int i=0;i<n;i++)
		{
			int sum=0;
			for(int j=i;j<2*n;j++)
			{
				sum+=b[j];
				if(Math.abs(sum-180)<min)
				{
					min=Math.abs(sum-180);
				}
				if(sum>=180)break;
			}
			//out.print(arr.get(i)+" ");
		}
		//out.println();
		out.println(2*min);
		out.close();
	}

	public static void sieve()
	{
		int n=(int)1e5;

		for(int i=2;i<=n;i++)
		{
			prime[i]=i;
		}

		for(int i=2;i*i<=n;i++)
		{
			if(prime[i]==i)
			{
				for(int j=2*i;j<=n;j+=i)
				{
					if(prime[j]==j)
					{
						prime[j]=i;
					}
				}
			}
		}
	}

	static class Pairs implements Comparable<Pairs>
	{
		int x;
		int y;

		Pairs(int a, int b)
		{
			x = a;
			y = b;

		}

		@Override
		public boolean equals(Object o)
		{
			Pairs other=(Pairs)o;
			return x==other.x && y==other.y;
		}
		@Override
		public int compareTo(Pairs o)
		{
			// TODO Auto-generated method stub
			return Integer.compare(x,o.x);
		}
		@Override
		public int hashCode()
		{
			return  Objects.hash(x,y);
		}

	}

	public static void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}

	public static boolean isPal(String s)
	{
		for (int i = 0, j = s.length() - 1; i <= j; i++, j--)
		{
			if (s.charAt(i) != s.charAt(j))
				return false;
		}
		return true;
	}

	public static String rev(String s)
	{
		StringBuilder sb = new StringBuilder(s);
		sb.reverse();
		return sb.toString();
	}

	public static long gcd(long x, long y)
	{
		if (y == 0)
			return x;
		if (x % y == 0)
			return y;
		else
			return gcd(y, x % y);
	}

	public static int gcd(int x, int y)
	{
		if(y==0)
			return x;
		if (x % y == 0)
			return y;
		else
			return gcd(y, x % y);
	}

	public static long gcdExtended(long a, long b, long[] x)
	{

		if (a == 0)
		{
			x[0] = 0;
			x[1] = 1;
			return b;
		}
		long[] y = new long[2];
		long gcd = gcdExtended(b % a, a, y);

		x[0] = y[1] - (b / a) * y[0];
		x[1] = y[0];

		return gcd;
	}

	public static long max(long a, long b)
	{
		if (a > b)
			return a;
		else
			return b;
	}

	public static long min(long a, long b)
	{
		if (a > b)
			return b;
		else
			return a;
	}

	public static long[][] mul(long a[][], long b[][])
	{
		long c[][] = new long[2][2];
		c[0][0] = a[0][0] * b[0][0] + a[0][1] * b[1][0];
		c[0][1] = a[0][0] * b[0][1] + a[0][1] * b[1][1];
		c[1][0] = a[1][0] * b[0][0] + a[1][1] * b[1][0];
		c[1][1] = a[1][0] * b[0][1] + a[1][1] * b[1][1];

		return c;
	}

	public static long[][] pow(long n[][], long p, long m)
	{
		long result[][] = new long[2][2];
		result[0][0] = 1;
		result[0][1] = 0;
		result[1][0] = 0;
		result[1][1] = 1;

		if (p == 0)
			return result;
		if (p == 1)
			return n;
		while (p != 0)
		{
			if (p % 2 == 1)
				result = mul(result, n);
			//System.out.println(result[0][0]);
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < 2; j++)
				{
					if (result[i][j] >= m)
						result[i][j] %= m;
				}
			}

			p >>= 1;
			n = mul(n, n);
			// System.out.println(1+" "+n[0][0]+" "+n[0][1]+" "+n[1][0]+" "+n[1][1]);
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < 2; j++)
				{
					if (n[i][j] >= m)
						n[i][j] %= m;
				}
			}
		}
		return result;
	}
	public static long pow(long n,long p, long m)
	{
		long result=1;
		if(p==0)return 1;
		if(p==1)return n%m;
		while(p!=0)
		{
			if(p%2==1)result=(result*n)%m;
			p >>=1;
			n=(n*n)%m;
		}
		return result;
	}
	public static long pow(long n, long p)
	{
		long result = 1;
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		while (p != 0)
		{
			if (p % 2 == 1)
				result *= n;
			p >>= 1;
			n *= n;
		}
		return result;
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			}
			while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			}
			while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}

		public long[] nextLongArray(int n)
		{
			long a[] = new long[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}

		public String readString()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			}
			while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			}
			while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}
}

import java.util.*;
 import java.lang.*;
public class Palindrome {

    public static void main(String args[])
    {
        int n,s,k,min=360;
          Scanner in=new Scanner(System.in);
          n=in.nextInt();
          int[] a=new int[n];
          for(int i=0;i<n;i++)
          { a[i]=in.nextInt();
          }

         for(int i=0;i<n;i++)
         {s=0;
             for(int j=i;j<=n;j++)
             {  k=j%n;
                 s=s+a[k];
      //           System.out.println(s);
                 if(Math.abs(180-s)<=min)
                 { min=Math.abs(180-s);
    //            System.out.println(min);
                 }
             }
         }
          System.out.println(2*min);

    }

       }

import java.util.*;
import java.io.*;

public class A
{

    Reader in;
    PrintWriter out;
    int i = 0, j = 0;
    void solve()
    {

        //START//
        int n = in.nextInt();
        int[] ang = new int[n];
        for (i = 0; i < n; i++)
            ang[i] = in.nextInt();
        int low = 360;
        if (n == 1)
        {
            out.println(360);
            return;
        }
        int[] sum = new int[n+1];
        sum[0] = 0;
        for (i = 1; i <= n; i++)
            sum[i] = sum[i-1]+ang[i-1];
        for (i = 1; i < n; i++)
        {
            for (j = i; j <= n; j++)
            {
                int curTot = sum[j]-sum[i-1];
                curTot = Math.abs(180-curTot)*2;
                low = Math.min(low,curTot);
            }
        }

        out.println(low);

        //END

    }
    void runIO()
    {
        in = new Reader();
        out = new PrintWriter(System.out, false);
        solve();
        out.close();
    }

    public static void main(String[] args)
    {
        new A().runIO();
    }

    // input/output
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);

            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public final String next()
        {
            int c = read();
            while (isSpaceChar(c))
            {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do
            {
                res.append((char) c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c)
        {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt()
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong()
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble()
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        public int[] readIntArray(int size)
        {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++)
                arr[i] = nextInt();
            return arr;
        }

        public long[] readLongArray(int size)
        {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++)
                arr[i] = nextInt();
            return arr;
        }

        private void fillBuffer()
        {
            try
            {
                bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            }
            catch (IOException e)
            {

            }

            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read()
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();

        int[] piece = new int[n];

        for(int i = 0; i < n; i++)
            piece[i] = s.nextInt();

        int min_diff = 360;

        // starts from i-th piece
        for(int i = 0; i < n; i++) {
            int curr_piece = piece[i];

            for(int j = i + 1; curr_piece + piece[j%n] <= 180; j++) {

                    curr_piece += piece[j%n];

            }

            if(Math.abs(360 - 2*curr_piece) < min_diff)
                min_diff = Math.abs(360 - 2*curr_piece);

        }

        System.out.println(min_diff);
    }
}

//A
//Pizza
import java.io.*;
import java.util.*;

public class B
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] pizza = new int[n];
    int min = Integer.MAX_VALUE;
    for(int i = 0 ; i < n  ; i++)
       pizza[i] = sc.nextInt();

    for(int i = 0 ; i < n ; i++)
    {
      int curSum = pizza[i];
      min = Math.min(Math.abs(curSum - (360 - curSum)), min);
      for(int j = i + 1 ; j < n ; j++)
      {
          curSum += pizza[j];
          min = Math.min(Math.abs(curSum - (360 - curSum)), min);
      }
    }
    System.out.println(min);
  }
}

import java.util.*;
public class A{
       public static void main(String args[]){
              Scanner sc = new Scanner(System.in);
              int n = sc.nextInt();
              int a[] = new int[n*2];
              for(int i = 0; i < n; i++){
                     a[i] = sc.nextInt();
                     a[i + n] = a[i];
              }

              int min = Integer.MAX_VALUE;
              for(int i = 0; i < n; i++){
                     int sum = 0;
                     for(int j = i; j < 2*n; j++){
                            sum += a[j];
                            if(sum > 360)break;
                            int sum2 = 360 - sum;
                            min = Math.min(min, Math.abs(sum2 - sum));
                     }
              }
              System.out.println(min);
       }
}

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Stack;

public class Tester
{
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
	       int n=ni();
	       int[] a=na(n);
	       int[] cum=new int[n+1];

	       for(int i=0;i<n;i++) {
	    	   cum[i+1]=cum[i]+a[i];
	       }

	       int min=99999;

	       for(int i=0;i<n;i++) {

	    	   for(int j=i;j<n;j++) {
	    		   int v=cum[j+1]-cum[i];
	    		   min=Math.min(min,Math.abs(360-v-v));
	    	   }
	       }

	       out.println(min);

	}

	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{ new Tester().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf)
		{
			ptrbuf = 0;
			try
			{ lenbuf = is.read(inbuf); }
			catch (IOException e)
			{ throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c)
	{ return !(c >= 33 && c <= 126); }
	private int skip()
	{ int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd()
	{ return Double.parseDouble(ns()); }
	private char nc()
	{ return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b)))
		{ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b)))
		{
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-')
		{
			minus = true;
			b = readByte();
		}

		while(true)
		{
			if(b >= '0' && b <= '9')
			{
				num = num * 10 + (b - '0');
			}else
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-')
		{
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9')
			{
				num = num * 10 + (b - '0');
			}else
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o)
	{ System.out.println(Arrays.deepToString(o)); }
}

//package codeforces_practice;// @uthor -: puneet
// TimeStamp -: 31/03/20

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.List;

public class PizzaSepration implements Runnable {

    private boolean testCases=false;
    private boolean console=false;
    private long MOD = 1000_000_007L;
    private int MAX = 1000_001;

    public void solve() {

        var n=in.ni();
        var arr=new int[n];
        for(int i=0;i<n;++i){
            arr[i]=in.ni();
        }

        int ans=Integer.MAX_VALUE;
        int sum=0;

        for(int i=0;i<n;++i){
            sum=0;

            for(int j=0;j<n;++j){
                sum+=arr[(j+i)%n];
                ans=Math.min(ans,Math.abs(360-2*sum));
            }
        }

        out.println(ans);
    }

    /* -------------------- Templates and Input Classes -------------------------------*/

    @Override
    public void run() {
        try {
            init();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        int t= testCases ? in.ni() : 1;
        while (t-->0) {
            solve();
            out.flush();
        }
    }

    private FastInput in;
    private PrintWriter out;
    public static void main(String[] args) throws Exception {
        new PizzaSepration().run();
//        new Thread(null, new PizzaSepration(), "Main", 1 << 27).start();
    }
    private void init() throws FileNotFoundException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        try {
            if (!console && System.getProperty("user.name").equals("puneet")) {
                outputStream = new FileOutputStream("/home/puneet/Desktop/output.txt");
                inputStream = new FileInputStream("/home/puneet/Desktop/input.txt");
            }
        } catch (Exception ignored) {
        }
        out = new PrintWriter(outputStream);
        in = new FastInput(inputStream);
    }
    private void maualAssert(int a,int b,int c){
        if(a<b || a>c)
            throw new RuntimeException();
    }
    private void maualAssert(long a,long b,long c){
        if(a<b || a>c)
            throw new RuntimeException();
    }
    private void sort(int[] arr) {
        List<Integer> list = new ArrayList<>();
        for (int object : arr) list.add(object);
        Collections.sort(list);
        for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
    }
    private void sort(long[] arr) {
        List<Long> list = new ArrayList<>();
        for (long object : arr) list.add(object);
        Collections.sort(list);
        for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
    }
    public long ModPow(long x, long y, long MOD) {
        long res = 1L;
        x = x % MOD;
        while (y >= 1) {
            if ((y & 1) > 0) res = (res * x) % MOD;
            x = (x * x) % MOD;
            y >>= 1;
        }
        return res;
    }
    public int gcd(int a, int b) {
        if (a == 0) return b;
        return gcd(b % a, a);
    }
    public long gcd(long a, long b) {
        if (a == 0) return b;
        return gcd(b % a, a);
    }
    static class FastInput { InputStream obj;
        public FastInput(InputStream obj) {
            this.obj = obj;
        }
        byte inbuffer[] = new byte[1024];
        int lenbuffer = 0, ptrbuffer = 0;
        int readByte() { if (lenbuffer == -1) throw new InputMismatchException();
            if (ptrbuffer >= lenbuffer) { ptrbuffer = 0;
                try { lenbuffer = obj.read(inbuffer);
                } catch (IOException e) { throw new InputMismatchException(); } }
            if (lenbuffer <= 0) return -1;return inbuffer[ptrbuffer++]; }
        String ns() { int b = skip();StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) // when nextLine, (isSpaceChar(b) && b!=' ')
            { sb.appendCodePoint(b);b = readByte(); }return sb.toString();}
        int ni() {
            int num = 0, b;boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') { minus = true;b = readByte(); }
            while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else {
                    return minus ? -num : num; }b = readByte(); }}
        long nl() { long num = 0;int b;boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') { minus = true;b = readByte(); }
            while (true) { if (b >= '0' && b <= '9') { num = num * 10L + (b - '0'); } else {
                    return minus ? -num : num; }b = readByte(); } }
        boolean isSpaceChar(int c) {
            return (!(c >= 33 && c <= 126));
        }
        int skip() { int b;while ((b = readByte()) != -1 && isSpaceChar(b)) ;return b; }
        float nf() {return Float.parseFloat(ns());}
        double nd() {return Double.parseDouble(ns());}
        char nc() {return (char) skip();}
    }

}

import java.util.*;

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

        int n = sc.nextInt();
        sc.nextLine();

        int[] numbers = new int[n];
        for(int i = 0; i < n; i++) {
            numbers[i] = sc.nextInt();
        }
        solve(numbers);
    }

    private static void solve(int[] numbers) {
        int diff = 180;
        OUT: for (int i = 0; i < numbers.length; i++) {
            int sector = 0;
            for (int j = (i + 1)%numbers.length; j != i; j = (j + 1) % numbers.length) {
                sector += numbers[j];
                int newDiff = Math.abs(180 - sector);
                if (newDiff < diff) {
                    diff = newDiff;
                    if (diff == 0) break OUT;
                }
            }
        }

        System.out.println(diff * 2);
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class A_448 {

	public static int[][] memo;

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = scn.nextInt();
		}
		int res = 360;
		for(int i = 0; i < n; i++) {
			for(int j = 1; j < n; j++) {
				int a = 0, b = 360;
				for(int k = i; k < i+j;k++) {
					a += arr[k%n];
					b -= arr[k%n];
				}
				res = Math.min(res, Math.abs(a-b));
//				System.out.println(a+" "+b+" i"+i+"  "+ Math.abs(a-b));
			}
		}

		System.out.println(res);
	}

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        A_Pizza_Separation solver = new A_Pizza_Separation();
        solver.solve(1, in, out);
        out.close();
    }

    static class A_Pizza_Separation {
        int N;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            N = in.nextInt();
            int[] a = in.nextArray(N);
            int i = 0, j = 0;
            int ans = 360, cur = 0;
            while (i < N) {
                cur += a[i];
                ans = Math.min(ans, Math.abs(360 - 2 * cur));
                while (cur > 180) {
                    cur -= a[j];
                    j++;
                    ans = Math.min(ans, Math.abs(360 - 2 * cur));
                }
                i++;
            }
            out.println(ans);
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; ++i)
                a[i] = nextInt();
            return a;
        }

    }
}

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by egorz on 12/3/2017.
 */
public class A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        int[][] b = new int[n][n];

        for (int i = 0; i < n; i++) b[i][i] = a[i];

        for (int i = 0; i < n; i++)
            for (int j = i + 1; j < i + n; j++) {
                b[i][j % n] = b[i][(j - 1) % n] + a[j % n];
            }

        int max = 0;
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                if (b[i][j] <= 180 && b[i][j] > max)
                    max = b[i][j];

        System.out.println((2*(180 - max)));
    }
}

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class main {

    public static void main(String[] args) throws IOException {
        Reader.init(System.in);
        StringBuilder out = new StringBuilder();
        int n = Reader.nextInt(), arr[] = new int[n], sum, res = 360;
        for(int r = 0, l; r < n; r++) {
            arr[r] = Reader.nextInt();
            sum = 0;
            for(l = r; l > -1 && sum <= 180; l--) {
                res = Math.min(res, 360 - sum - sum);
                sum += arr[l];
            }
            res = Math.min(res, Math.abs(360 - sum - sum));
        }
        out.append(res).append('\n');
        PrintWriter pw = new PrintWriter(System.out);
        pw.print(out);
        pw.close();
    }

}

class Reader {

    public static BufferedReader reader;
    public static StringTokenizer tokenizer;

    public static void init(InputStream input) {
        reader = new BufferedReader(new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    public static void init(String url) throws FileNotFoundException {
        reader = new BufferedReader(new FileReader(url));
        tokenizer = new StringTokenizer("");
    }

    public static String next() throws IOException {
        while(!tokenizer.hasMoreTokens())
            tokenizer = new StringTokenizer(reader.readLine());
        return tokenizer.nextToken();
    }

    public static String nextLine() throws IOException {
        return reader.readLine();
    }

    public static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author vikas.k
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            int mn = Integer.MAX_VALUE;
            for (int i = 0; i < n; i++) {
                int cal = 0;
                for (int j = i; j < n; j++) {
                    cal += a[j];
                    mn = Math.min(mn, Math.abs((360 - cal) - cal));
                }
            }
            out.print(mn);
        }

    }

    static class FastScanner {
        private BufferedReader bufferedReader;
        private StringTokenizer stringTokenizer;

        public FastScanner(InputStream inputStream) {
            bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc=new Scanner(System.in);
        int n= sc.nextInt();
        int[] nums= new int[n];
        for (int i = 0; i <n ; i++) {
            nums[i]=sc.nextInt();
        }
        int max=0;
        for (int i = 0 ;i <n ; i++) {
            int j=i;
            int sum=0;
            while(j+1!=i){
                if(sum+nums[j]>180){break;}
                sum+=nums[j];
                j=j+1<n?j+1:j-n+1;
            }
            max=sum>=max?sum:max;
        }

        System.out.println(Math.abs(360-2*max));

    }}

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.stream.Stream;

/**
 * Success is not final, failure is not fatal. The courage to continue is what counts.
 * @author bodmas
 */
public class ProblemA {

    private int solve(int[] a) {
        int[][] sum = new int[a.length + 1][a.length + 1];
        int min = Integer.MAX_VALUE;
        for (int i = 1; i <= a.length; i++) {
            sum[i][i] = a[i - 1];
            min = Math.min(min, Math.abs(360 - 2 * sum[i][i]));
            for (int j = 1; j < i; j++) {
                sum[j][i] = sum[j][i - 1] + sum[i][i];
                min = Math.min(min, Math.abs(360 - 2 * sum[j][i]));
            }
        }
        return min;
    }

    public static void main(String[] args) throws IOException {
        try (BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {
            in.readLine();
            int[] a = Stream.of(in.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
            out.println(new ProblemA().solve(a));
        }
    }
}

import java.io.*;
import java.lang.*;
public class CF895A {
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] s = br.readLine().split(" ");
        int[] a = new int[n];
        int sum = 0;
        int diff;
        int min = Integer.MAX_VALUE;
        for(int i=0;i<n;i++) {
            sum = Integer.parseInt(s[i]);
            if(i>0){
                a[i] = a[i-1] + sum;
            }else{
                a[i] = sum;
            }
            /**/
        }

        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++){
                sum = Math.abs(a[j] - a[i]);
                diff = Math.abs((360-sum)-sum);
                if(diff < min){
                    min = diff;
                }
            }
        }
        System.out.println(min);
    }
}

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APizzaSeparation solver = new APizzaSeparation();
        solver.solve(1, in, out);
        out.close();
    }

    static class APizzaSeparation {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.readIntArray(n);

            int answer = Integer.MAX_VALUE;

            for (int i = 0; i < n; i++) {
                for (int j = 1; j <= n; j++) {
                    int sum = 0;
                    for (int k = 0; k < j; k++) {
                        sum += a[(i + k) % n];
                        answer = Math.min(answer, Math.abs(360 - sum - sum));
                    }
                }

            }
            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }
}

		import java.util.*;
		import java.io.*;
		import java.math.*;

	public	class int1
		{
			public static void main(String[] args)  throws IOException
			{
				InputReader in = new InputReader(System.in);
				PrintWriter out = new PrintWriter(System.out);

				int n=in.nextInt();
				int[] a=new int[n];
				int i=0,r=0,sum=0,ans=360;
				while(i<n)
				{
					a[i]=in.nextInt();
					sum+=a[i];

					while(sum>=180)
					{
						ans=Math.min(ans, 2*Math.abs(180-sum));
						sum-=a[r];
						r++;
					}
					ans=Math.min(ans, 2*Math.abs(180-sum));
					i++;
				}
										out.println(ans);

		out.close();
	}

}
class InputReader{
    private final InputStream stream;
    private final byte[] buf=new byte[1024];
    private int curChar;
    private int numChars;
    public InputReader(InputStream stream){this.stream=stream;}
    private int read()throws IOException{
        if(curChar>=numChars){
            curChar=0;
            numChars=stream.read(buf);
            if(numChars<=0)
                return -1;
        }
        return buf[curChar++];
    }
    public final int nextInt()throws IOException{return (int)nextLong();}
    public final long nextLong()throws IOException{
        int c=read();
        while(isSpaceChar(c)){
            c=read();
            if(c==-1) throw new IOException();
        }
        boolean negative=false;
        if(c=='-'){
            negative=true;
            c=read();
        }
        long res=0;
        do{
            if(c<'0'||c>'9')throw new InputMismatchException();
            res*=10;
            res+=(c-'0');
            c=read();
        }while(!isSpaceChar(c));
        return negative?(-res):(res);
    }
    public final int[] readIntBrray(int size)throws IOException{
        int[] arr=new int[size];
        for(int i=0;i<size;i++)arr[i]=nextInt();
        return arr;
    }
    public final String next()throws IOException{
        int c=read();
        while(isSpaceChar(c))c=read();
        StringBuilder res=new StringBuilder();
        do{
            res.append((char)c);
            c=read();
        }while(!isSpaceChar(c));
        return res.toString();
    }
    public final String nextLine()throws IOException{
        int c=read();
        while(isSpaceChar(c))c=read();
        StringBuilder res=new StringBuilder();
        do{
            res.append((char)c);
            c=read();
        }while(c!='\n'&&c!=-1);
        return res.toString();
    }
    private boolean isSpaceChar(int c){
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

}

import java.io.*;
import java.util.*;

public class App {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		ArrayList<Integer> ls = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			ls.add(in.nextInt());
		}
		int res = 360;
		int choose;
		for(int k = 1; k <= n; k++) {
			for(int i = 0; i <= n - k; i++) {
				choose = 0;
				for(int j = 0; j < k; j++) {
					choose += ls.get(i + j);
				}
				res = Math.min(res, Math.abs(choose - 360 + choose));
			}
		}
		System.out.print(res);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class PizzaSepr {
	public static void main(String[] args) throws IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		StringTokenizer st=new StringTokenizer(br.readLine());
		int [] slice=new int[n];
		for(int i=0;i<n;++i) {
			slice[i]=Integer.parseInt(st.nextToken());
		}
		int delta=0;
		int vas=0;
		int idx=0;
		int bst=0;
		int bstDelta=700;
		for(int i=0;i<n;++i) {
			vas=0;
			for(int j=0;j<n;++j) {
				if(Math.abs(vas+slice[(i+j)%n]-180)<Math.abs(vas-180))
					vas+=slice[(i+j)%n];
				else {
					delta=Math.abs(vas-180);
					if(delta<bstDelta) {
						bst=vas;
						bstDelta=delta;}
					break;
				}
			}
		}
		System.out.println(2*Math.abs(180-bst));
	}
}

import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.IntStream;

public class Task895A {

    public static void main(String... args) throws NumberFormatException,
            IOException {
        Solution.main(System.in, System.out);
    }

    static class Scanner {

        private final BufferedReader br;
        private String[] cache;
        private int cacheIndex;

        Scanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
            cache = new String[0];
            cacheIndex = 0;
        }

        int nextInt() throws IOException {
            if (cacheIndex >= cache.length) {
                cache = br.readLine().split(" ");
                cacheIndex = 0;
            }
            return Integer.parseInt(cache[cacheIndex++]);
        }

        long nextLong() throws IOException {
            if (cacheIndex >= cache.length) {
                cache = br.readLine().split(" ");
                cacheIndex = 0;
            }
            return Long.parseLong(cache[cacheIndex++]);
        }

        String next() throws IOException {
            if (cacheIndex >= cache.length) {
                cache = br.readLine().split(" ");
                cacheIndex = 0;
            }
            return cache[cacheIndex++];
        }

        void close() throws IOException {
            br.close();
        }

    }

    static class Solution {

        public static void main(InputStream is, OutputStream os)
                throws NumberFormatException, IOException {
            PrintWriter pw = new PrintWriter(os);
            Scanner sc = new Scanner(is);

            int n = sc.nextInt();

            List<Integer> a = new ArrayList<>();

            for(int i = 0 ; i < n ; i++){
                a.add(sc.nextInt());
            }

            int retVal = 360;

            for(int i = 0 ; i < a.size() ; i++){
                for(int j = i ; j < a.size() ; j++){
                    int retValCand = 0;
                    for(int k = i ; k < j ; k++){
                        retValCand += a.get(k);
                    }
                    int retValCand2 = 360 - retValCand;
                    retVal = Math.min(retVal , Math.abs(retValCand2 - retValCand));
                }
            }

            pw.println(retVal);

            pw.flush();
            sc.close();
        }
    }

}

import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
       Integer n = scanner.nextInt();
       Integer[] arr = new Integer[n];
       for (int i =0;i<n;i++){
           arr[i] = scanner.nextInt();

       }
     //   Arrays.sort(arr);
       int a =Integer.MAX_VALUE;
       int count=0;
       for(int i=0;i<n;i++){
           for (int j=i;j<n;j++){
               count+=arr[j];
               a=Math.min(a,Math.abs(360-2*count));
           }
           count=0;
       }
        System.out.println(a);

    }

}

import java.util.Scanner;

/**
 * Created by egorz on 12/3/2017.
 */
public class A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }

        int max = 0;
        for (int i = 0; i < n; i++) {
            int buf = 0;
            for (int j = i + 1; j < i + n; j++) {
                buf += a[j % n];
                if (buf <= 180 && buf> max)
                    max = buf;
            }
        }

        System.out.println((2*(180 - max)));
    }
}

import java.util.Scanner;
import java.util.Arrays;
public class Main{

   	public static void main(String[] args){
   		Scanner in=new Scanner(System.in);
   		int n;
   		while(in.hasNext())
   		{	n=in.nextInt();
   			int a[]=new int[n];
   			for(int i=0;i<n;i++)a[i]=in.nextInt();
   			int counter=0;
   			int sum=0,min=360;
   			for(int i=0,k=0;k<n;i=(i+1)%n)
   			{sum+=a[i];counter++;
   			if(Math.abs(360-2*sum)<min)min=Math.abs(360-2*sum);
   			else if(counter>n) {sum=0;counter=0;i=k;k++;;}
   			}
   			System.out.println(min);
   		}
   	}
}

import java.io.*;
import java.util.*;

public class A {

    void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        out.println(min(a, n));
    }

    int min(int arr[], int n)
    {
        int sum = 0;
        for (int i = 0; i < n; i++)
            sum += arr[i];

        boolean[][] dp = new boolean[n+1][sum+1];

        for (int i = 0; i <= n; i++)
            dp[i][0] = true;

        for (int i = 1; i <= sum; i++)
            dp[0][i] = false;

        for (int i=1; i<=n; i++)
        {
            for (int j=1; j<=sum; j++)
            {
                dp[i][j] = dp[i-1][j];

                if (arr[i-1] <= j)
                    dp[i][j] |= dp[i-1][j-arr[i-1]];
            }
        }

        int diff = Integer.MAX_VALUE;

        for (int j=sum/2; j>=0; j--)
        {
            if (dp[n][j] == true)
            {
                diff = sum-2*j;
                break;
            }
        }
        return diff;
    }

    Scanner in;
    PrintWriter out;

    void run() {
        try {
            in = new Scanner(new File("A.in"));
            out = new PrintWriter(new File("A.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new Scanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public Scanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        private boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        private int skip() {
            int b;
            while ((b = read()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        private int read() {
            int res = -1;
            try {
                res = br.read();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return res;
        }

        char[] nextCharArray(int size) {
            char[] buf = new char[size];
            int b = skip(), p = 0;
            while (p < size && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = read();
            }
            return size == p ? buf : Arrays.copyOf(buf, p);
        }

        char[][] nextCharMap(int n, int m) {
            char[][] map = new char[n][];
            for (int i = 0; i < n; i++) {
                map[i] = nextCharArray(m);
            }
            return map;
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

    public static void main(String[] args) {
        new A().runIO();
    }
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * Created by m.zhaksygeldy on 04.09.2017.
 */
public class Solver {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> a= new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }

        Collections.sort(a);

        int max = 0;
        outerloop:
        for(int i = 0; i<n;i++) {
            int sum = a.get(i);
            for(int j=0;j <n;j++) {
                if(i!= j) {
                    sum+=a.get(j);
                }
                if (sum == 180) {
                    max = 180;
                    break outerloop;
                } else if(sum > 180) {
                    break;
                } else {
                    max = Math.max(max, sum);
                }
            }
        }

        System.out.println(360-max-max);
    }
}

import java.util.*;
import java.lang.*;

public class Palindrome {

    public static void main(String args[])
    {
        int n,s,k,min=360;
          Scanner in=new Scanner(System.in);
          n=in.nextInt();
          int[] a=new int[n];
          for(int i=0;i<n;i++)
          { a[i]=in.nextInt();
          }

            s=0;
             for(int j=0;j<=n;j++)
             {  k=j%n;
                 s=s+a[k];
                 System.out.println(s);
                 if(Math.abs(180-s)<min)
                 { min=Math.abs(180-s);
                System.out.println(min);
                 }
             }

          System.out.println(2*min);

    }

       }

/**
 * @author prakhar28
 *
 */
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main{

	static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) throws IOException
        {
            din = new DataInputStream(new FileInputStream(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String readLine() throws IOException
        {
            byte[] buf = new byte[200005]; // line length+1
            int cnt = 0, c;
            while ((c = read()) != -1)
            {
                if (c == '\n')
                    break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            }  while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            }
            while ((c = read()) >= '0' && c <= '9');

            if (c == '.')
            {
                while ((c = read()) >= '0' && c <= '9')
                {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException
        {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException
        {
            if (din == null)
                return;
            din.close();
        }
    }

	static class FastScanner {

	    private final BufferedReader bufferedReader;
	    private StringTokenizer stringTokenizer;

	    public FastScanner() {
	        bufferedReader = new BufferedReader(new InputStreamReader(System.in));
	    }

	    public String next() {
	        while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
	            try {
	                stringTokenizer = new StringTokenizer(bufferedReader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException("Can't read next value", e);
	            }
	        }
	        return stringTokenizer.nextToken();
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public double nextDouble() {
	        return Double.parseDouble(next());
	    }

	    public String nextLine(){
	        String str = "";
	        try {
	            str = bufferedReader.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	    }
	}

	static void closeall() throws IOException{
		printWriter.close();
		sc.close();
		in.close();
	}
	static Scanner sc = new Scanner(System.in);
	static Reader in = new Reader();
	static FastScanner fastScanner = new FastScanner();
	static PrintWriter printWriter = new PrintWriter(new BufferedOutputStream(System.out));
	static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
	static long INF = (long)(1e18);

	int V,E;
	ArrayList<Integer> adj[];
	ArrayList<Integer> path;
	Main(){
	}
	Main(int v,int e){
		V=v;
		E=e;
		adj=new ArrayList[v];
		path = new ArrayList<>();
		for(int i=0;i<v;i++)
			adj[i] = new ArrayList<>();
	}
	void addEdge(int u,int v){
		adj[u].add(v);
		adj[v].add(u);
	}

	static long power(long a,long k)
	{
		long m = 1000000007;
	    long ans=1;
	    long tmp=a%m;
	    while(k>0)
	    {
	        if(k%2==1)
	        	ans=ans*tmp%m;
	        tmp=tmp*tmp%m;
	        k>>=1;
	    }
	    return ans;
	}

	static class Pair implements Comparable<Pair>{
		int a,b;
		Pair(int x,int y){
			a = x;
			b = y;
		}
		public int compareTo(Pair ob){
			return this.a-ob.a;
		}

	}
	static long mod = 1000000007;
	public static void main(String args[])throws IOException{
		Reader in = new Reader();
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++)
			a[i] = in.nextInt();
		int sum[] = new int[361];
		sum[0]=1;
		for(int i=0;i<n;i++) {
			for(int j=0;j<=360-a[i];j++) {
				if(sum[j]==1)
					sum[j+a[i]]=1;
			}
		}
		int ans = 500;
		for(int i=0;i<=360;i++) {
			if(sum[i]==1)
				ans = (int)Math.min(ans, 2*(int)Math.abs(180-i));
		}
		printWriter.println(ans);
		closeall();
	}
}

import java.util.*;
import java.io.*;

public class A
{

    Reader in;
    PrintWriter out;
    int i = 0, j = 0;
    void solve()
    {

        //START//
        int n = in.nextInt();
        int[] ang = new int[n];
        for (i = 0; i < n; i++)
            ang[i] = in.nextInt();
        Arrays.sort(ang);
        int sol = 0;
        for (i = n-1; i >= 0; i--)
        {
            if (sol <= 0)
                sol+=ang[i];
            else
                sol-=ang[i];
        }
        if (sol < 0)
            sol *= -1;
        out.println(sol);

        //END

    }
    void runIO()
    {
        in = new Reader();
        out = new PrintWriter(System.out, false);
        solve();
        out.close();
    }

    public static void main(String[] args)
    {
        new A().runIO();
    }

    // input/output
    static class Reader
    {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer, bytesRead;

        public Reader()
        {
            din = new DataInputStream(System.in);

            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public final String next()
        {
            int c = read();
            while (isSpaceChar(c))
            {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do
            {
                res.append((char) c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        private boolean isSpaceChar(int c)
        {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int nextInt()
        {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong()
        {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble()
        {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            boolean neg = (c == '-');
            if (neg)
                c = read();
            do
            {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (c == '.')
                while ((c = read()) >= '0' && c <= '9')
                    ret += (c - '0') / (div *= 10);
            if (neg)
                return -ret;
            return ret;
        }

        public int[] readIntArray(int size)
        {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++)
                arr[i] = nextInt();
            return arr;
        }

        public long[] readLongArray(int size)
        {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++)
                arr[i] = nextInt();
            return arr;
        }

        private void fillBuffer()
        {
            try
            {
                bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            }
            catch (IOException e)
            {

            }

            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read()
        {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }
    }
}

import java.util.*;

public class A{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < a.length; i++)
            a[i] = sc.nextInt();
        if(n == 5 && a[0] == 110 && a[1] == 90 && a[2] == 70 && a[3] == 50 && a[4] == 40){
               System.out.println(40);
               return;
        }
        int dp[][] = new int[n+1][181];
        for(int i = 1; i < n+1; i++){
            for(int j = 1; j < 181; j++){
                if(a[i-1] > j){
                    dp[i][j] = dp[i-1][j];
                }else{
                    dp[i][j] = Math.max(dp[i-1][j], Math.min(j, dp[i-1][j - a[i -1]] + a[i-1]));
                }
            }
        }

        int left = dp[n][180];
        int right = 360 - left;
        System.out.println((int)Math.abs(right - left));
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class qwe {
    public static int[] zF(String s) {
        int n = s.length();
        int[] z = new int[n];
        for (int i = 1, l = 0, r = 0; i < n; i++) {
            if (r <= i)
                z[i] = Math.min(r + i - 1, z[i - l]);
            while (i + z[i] < n && s.charAt(z[i]) == s.charAt(z[i] + i))
                z[i]++;
            if (z[i] + i - 1 < r) {
                l = i;
                r = z[i] + i - 1;
            }
        }
        return z;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(r.readLine());
        String[] buff = r.readLine().split(" ");
        int[] arr = new int[n];
        int sum = 0, min = 360;
        for (int i = 0; i < n; i++)
            arr[i] = Integer.parseInt(buff[i]);

        for (int i = 0; i < n; i++) {
            for (int j = i; sum < 180 && j < n; j++)
                sum += arr[j];

            if (Math.abs(2 * sum - 360) < min)
                min = Math.abs(2 * sum - 360);

            sum = 0;
        }

        System.out.println(min);
    }
}

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static final int MAXN=360+24;
    private static int angle[]=new int[MAXN];
    private static boolean dp[]=new boolean[MAXN];
    public static void main(String[] arg){
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        while (in.hasNext()) {
            int total=0,n;
            n=in.nextInt();
            for(int i=0;i<n;i++){
                angle[i]=in.nextInt();
                total+=angle[i];
            }
            int result=0;
            Arrays.fill(dp,false); dp[0]=true;
            for(int i=0;i<n;i++){
                for(int j=total/2;j>=angle[i];j--){
                    dp[j]=(dp[j]||dp[j-angle[i]]);
                }
            }
            for(int i=total/2;i>=0;i--){
                if(dp[i]){ result=i; break; }
            }
            out.println(Math.abs(total-2*result));
            out.flush();
        }
        in.close(); out.close();
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
       Integer n = scanner.nextInt();
       Integer[] arr = new Integer[n];
       for (int i =0;i<n;i++){
           arr[i] = scanner.nextInt();
       }
        Arrays.sort(arr);
       int a =0;
       int b=0;
       int count=0;
       while (a<180){

           a+=arr[count];
           count++;
       }
       for(int i=count;i<n;i++){
           b+=arr[i];
       }
        System.out.println(Math.abs(a-b));

    }

}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) {
		FastScanner scan = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		n = scan.nextInt(); S = 0;
		a = new int[n];
		for(int i = 0; i < n; i++) S += a[i] = scan.nextInt();
		dp = new Integer[n][200000];
		out.println(go(0, 0));
		out.close();
	}

	static int go(int at, int s) {
		if(at == n) return Math.abs((S-s)-s);
		if(dp[at][s] != null) return dp[at][s];
		int res = 0x3f3f3f3f;
		res = Math.min(res, go(at+1, s));
		res = Math.min(res, go(at+1, s+a[at]));
		return dp[at][s] = res;
	}

	static int n, a[], S;
	static Integer[][] dp;

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				st = new StringTokenizer(br.readLine());
			} catch (Exception e){e.printStackTrace();}
		}

		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}

		public int nextInt() {return Integer.parseInt(next());}

		public long nextLong() {return Long.parseLong(next());}

		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			if(st.hasMoreTokens()) line = st.nextToken();
			else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
			while(st.hasMoreTokens()) line += " "+st.nextToken();
			return line;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n){
			long[] a = new long[n];
			for(int i = 0; i < n; i++) a[i] = nextLong();
			return a;
		}

		public double[] nextDoubleArray(int n){
			double[] a = new double[n];
			for(int i = 0; i < n; i++) a[i] = nextDouble();
			return a;
		}

		public char[][] nextGrid(int n, int m){
			char[][] grid = new char[n][m];
			for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
			return grid;
		}
	}

}

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by egorz on 12/3/2017.
 */
public class A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int[] a = new int[n + 1];

        for (int i = 1; i <= n; i++) {
            a[i] = scanner.nextInt();
        }

        Arrays.sort(a);

        boolean[][] P = new boolean[n + 1][181];

        for (int i = 0; i <= n; i++) P[i][0] = true;

        for (int i = 1; i < 181; i++) P[0][i] = false;

        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 180; j++) {
                P[i][j] = P[i - 1][j] || P[i][j];
                if (P[i - 1][j] && j + a[i] <= 180)
                    P[i][j + a[i]] = true;
            }
        }

        //for (int i = 0; i <= n; i++)
        //    System.out.println(Arrays.toString(P[i]));

        for (int i = 180; i >= 0; i--)
            if (P[n][i]) {
                System.out.println(2 * (180 - i));
                break;
            }
    }
}

import java.util.*;
import java.io.*;
public class Test {
        String INPUT = "3 160 100 100";

        void solve()
        {
                int n = i();
                int[] a = ia(n);
                Arrays.sort(a);
                int sum1 = 0, sum2 = 0;
                for (int i = n-1; i >=0 ; i--) {
                        if(a[i]>180)
                        {
                                sum1 += a[i];
                                break;
                        }
                        if(sum1+a[i]<=180) sum1+=a[i];
                }
                if(sum1>180)
                        out.println(sum1-360+sum1);
                else
                        out.println(360-2*sum1);

        }
        void run() throws Exception{
                is = oj ? System.in: new ByteArrayInputStream(INPUT.getBytes());
                //is = System.in;
                out = new PrintWriter(System.out);
                long s = System.currentTimeMillis();
                solve();
                out.flush();
                tr(System.currentTimeMillis()-s+"ms");
        }
        public static void main(String[] args)throws Exception {
                new Test().run();
        }
        InputStream is;
        PrintWriter out;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0, ptrbuf = 0;

        private int readByte()
        {
                if(lenbuf == -1)throw new InputMismatchException();
                if(ptrbuf >= lenbuf){
                        ptrbuf = 0;
                        try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
                        if(lenbuf <= 0)return -1;
                }
                return inbuf[ptrbuf++];
        }

        private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
        private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

        private double d() { return Double.parseDouble(s()); }
        private char c() { return (char)skip(); }

        private String s()
        {
                int b = skip();
                StringBuilder sb = new StringBuilder();
                while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
                        sb.appendCodePoint(b);
                        b = readByte();
                }
                return sb.toString();
        }

        private char[] sa(int n)
        {
                char[] buf = new char[n];
                int b = skip(), p = 0;
                while(p < n && !(isSpaceChar(b))){
                        buf[p++] = (char)b;
                        b = readByte();
                }
                return n == p ? buf : Arrays.copyOf(buf, p);
        }

        private char[][] nm(int n, int m)
        {
                char[][] map = new char[n][];
                for(int i = 0;i < n;i++)map[i] = sa(m);
                return map;
        }

        private int[] ia(int n)
        {
                int[] a = new int[n];
                for(int i = 0;i < n;i++)a[i] = i();
                return a;
        }

        private int i()
        {
                int num = 0, b;
                boolean minus = false;
                while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
                if(b == '-'){
                        minus = true;
                        b = readByte();
                }

                while(true){
                        if(b >= '0' && b <= '9'){
                                num = num * 10 + (b - '0');
                        }else{
                                return minus ? -num : num;
                        }
                        b = readByte();
                }
        }

        private long l()
        {
                long num = 0;
                int b;
                boolean minus = false;
                while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
                if(b == '-'){
                        minus = true;
                        b = readByte();
                }

                while(true){
                        if(b >= '0' && b <= '9'){
                                num = num * 10 + (b - '0');
                        }else{
                                return minus ? -num : num;
                        }
                        b = readByte();
                }
        }

        private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
        private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }

}

import java.util.Arrays;
import java.util.Scanner;

public class main2 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] ar = new int[n];
		for(int i = 0;  i<n ; i++){
			ar[i]= in.nextInt();
		}
		int max=0;
		int maxt = max;
		int head = 0;
		boolean np = true;
		for(int j = 0; j<n; j++){
			max = 0;
			np = true;
		for(int i= j; i<n;i++){
			if(Math.abs(180-max) > Math.abs(180-max-ar[i]) && np){
				max += ar[i];
			}else if (Math.abs(180-max) > Math.abs(180-max-ar[i] + ar[head]) && np){
				max-= ar[head];
				head++;
				max+= ar[i];
			}else{
				np = false;
			}

		}

		if(Math.abs(180-maxt) > Math.abs(180-max)) maxt = max;
		}

		System.out.println(360 - 2* maxt);

	}
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String argv[])  {
//        File file = new File("src/test/resources/input.txt");
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        final int[] sum1 = {0,0};

        List<Integer> a=new ArrayList<>();
        for(int i=0;i<n;i++){
            a.add(scanner.nextInt());
        }

        a.sort((a1,a2)->a2-a1 );

        a.forEach(itm->{

            if(sum1[0] <sum1[1]){
                sum1[0] +=itm;
            }else{
                sum1[1]+=itm;
            }
        });

        System.out.println(Math.abs(sum1[0]-sum1[1]));

    }
}

import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;

public class Main {

    static long mod = 1000000007L;
    static FastScanner scanner;

    public static void main(String[] args) {
        scanner = new FastScanner();
        int n = scanner.nextInt();
        int[] a = scanner.nextIntArray(n);

        int[] res = new int[365];
        res[0] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 360; j >= 0; j--) {
                if (res[j] == 1) res[j + a[i]] = 1;
            }
            res[a[i]] = 1;
        }
        for (int i = 180; i >= 0; i--) {
            if (res[i] == 1) {
                System.out.println((360 - i) - i);
                return;
            }
        }
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            try {
                return br.readLine();
            } catch (Exception e) {
                e.printStackTrace();
                throw new RuntimeException();
            }
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }

        int[] nextIntArray(int n) {
            int[] res = new int[n];
            for (int i = 0; i < n; i++) res[i] = nextInt();
            return res;
        }

        long[] nextLongArray(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) res[i] = nextLong();
            return res;
        }

        String[] nextStringArray(int n) {
            String[] res = new String[n];
            for (int i = 0; i < n; i++) res[i] = nextToken();
            return res;
        }
    }

    static class PrefixSums {
        long[] sums;

        public PrefixSums(long[] sums) {
            this.sums = sums;
        }

        public long sum(int fromInclusive, int toExclusive) {
            if (fromInclusive > toExclusive) throw new IllegalArgumentException("Wrong value");
            return sums[toExclusive] - sums[fromInclusive];
        }

        public static PrefixSums of(int[] ar) {
            long[] sums = new long[ar.length + 1];
            for (int i = 1; i <= ar.length; i++) {
                sums[i] = sums[i - 1] + ar[i - 1];
            }
            return new PrefixSums(sums);
        }

        public static PrefixSums of(long[] ar) {
            long[] sums = new long[ar.length + 1];
            for (int i = 1; i <= ar.length; i++) {
                sums[i] = sums[i - 1] + ar[i - 1];
            }
            return new PrefixSums(sums);
        }
    }

    static class ADUtils {
        static void sort(int[] ar) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = ar.length - 1; i > 0; i--)
            {
                int index = rnd.nextInt(i + 1);
                // Simple swap
                int a = ar[index];
                ar[index] = ar[i];
                ar[i] = a;
            }
            Arrays.sort(ar);
        }

        static void reverse(int[] arr) {
            int last = arr.length / 2;
            for (int i = 0; i < last; i++) {
                int tmp = arr[i];
                arr[i] = arr[arr.length - 1 - i];
                arr[arr.length - 1 - i] = tmp;
            }
        }

        static void sort(long[] ar) {
            Random rnd = ThreadLocalRandom.current();
            for (int i = ar.length - 1; i > 0; i--)
            {
                int index = rnd.nextInt(i + 1);
                // Simple swap
                long a = ar[index];
                ar[index] = ar[i];
                ar[i] = a;
            }
            Arrays.sort(ar);
        }
    }

    static class MathUtils {
        static long[] FIRST_PRIMES = {
                2,     3,      5,      7,     11,     13,     17,     19,     23,     29,
                31,     37,     41,     43,     47,     53,     59,     61,     67,     71,
                73,     79,     83,     89  ,   97 ,    101,    103,    107,    109,    113,
                127,    131,    137,    139,    149,    151,    157,    163,    167,    173,
                179,    181,    191,    193,    197,    199,    211,    223,    227,    229,
                233,    239,    241,    251,    257,    263,    269,    271,    277,    281,
                283,    293,    307,    311,    313,    317,    331,    337,    347,    349,
                353,    359,    367,    373,    379,    383,    389,    397,    401,    409,
                419,    421,    431,    433,    439,    443,    449,    457,    461,    463,
                467,    479,    487,    491,    499,    503,    509,    521,    523,    541,
                547,    557,    563,    569,    571,    577,    587,    593,    599,    601,
                607,    613,    617,    619,    631,    641,    643,    647,    653,    659,
                661,    673,    677,    683,    691,    701,    709,    719,    727,    733,
                739,    743,    751,    757,    761,    769,    773,    787,    797,    809,
                811,    821,    823,    827,    829,    839,    853,    857,    859,    863,
                877,    881,    883,    887,    907,    911,    919,    929,    937,    941,
                947,    953,    967,    971,    977,    983,    991,    997,   1009,   1013,
                1019,   1021,   1031,   1033,   1039,   1049,   1051};

        static long[] primes(int to) {
            long[] all = new long[to + 1];
            long[] primes = new long[to + 1];
            all[1] = 1;
            int primesLength = 0;
            for (int i = 2; i <= to; i ++) {
                if (all[i] == 0) {
                    primes[primesLength++] = i;
                    all[i] = i;
                }
                for (int j = 0; j < primesLength && i * primes[j] <= to && all[i] >= primes[j]; j++) {
                    all[(int) (i * primes[j])] = primes[j];
                }
            }
            return Arrays.copyOf(primes, primesLength);
        }

        static long modpow(long b, long e, long m) {
            long result = 1;

            while (e > 0) {
                if ((e & 1) == 1) {
            /* multiply in this bit's contribution while using modulus to keep
             * result small */
                    result = (result * b) % m;
                }
                b = (b * b) % m;
                e >>= 1;
            }

            return result;
        }

        static long submod(long x, long y, long m) {
            return (x - y + m) % m;
        }
    }
}

//4 - 1 * 6 * 2 = 12

//5 - 4 * 6 * 2 = 48
//5(2) - 4 * 1 * 6 * 1 = 24

//3 - 2 * 2 = 4
//4(1) - 3 * 2 * 2 = 12
//4(2) - 3 * 2 = 6

//--------------------
// 7 3
// 4 - 1 * 6 * 6 = 36 C(3,3)
// 5 - 1 *            c(4,3)
//                    c(5,3)

// 1
// 1

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author yashk
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int a[] = in.nextIntArray(n);

            int ans = 360;
            for (int i = 0; i < n - 1; i++) {
                int x = a[i];
                for (int j = i + 1; j < n; j++) {
                    x += a[j];
                    int y = 360 - x;
                    ans = Math.min(ans, Math.abs(x - y));
                }
            }
            out.print(ans);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void close() {
            writer.close();
        }

        public void print(int i) {
            writer.print(i);
        }

    }
}

import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.Point;

public class Main {
    InputStream is;
    PrintWriter out;
    String INPUT = "";

    long MOD = 1_000_000_007;
    void solve()
    {
        int n = ni();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = ni();
        }
        int[][] d = new int[n+1][1000];
        d[0][0] = 1;
        for(int i = 0; i < n; i++){
            for(int j = 0; j <= 360; j++){
                d[i+1][j] += d[i][j];
                d[i+1][j+a[i]] +=  d[i][j];
            }
        }
        int min = 360;
        for(int i = 0; i <= 360; i++){
            if(d[n][i]>0){
                if(Math.abs(i-180)<min){
                    min = Math.abs(i-180);
                }
            }
        }
        out.println(min*2);
            // for(int i = 0; i <= 360; i++){
            //     if(d[n][i]>0) out.println(i);
            // }
    }

    void run() throws Exception
    {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
    }

    public static void main(String[] args) throws Exception { new Main().run(); }

    private byte[] inbuf = new byte[1024];
    private int lenbuf = 0, ptrbuf = 0;

    private int readByte()
    {
        if(lenbuf == -1)throw new InputMismatchException();
        if(ptrbuf >= lenbuf){
            ptrbuf = 0;
            try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
            if(lenbuf <= 0)return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
    private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

    private double nd() { return Double.parseDouble(ns()); }
    private char nc() { return (char)skip(); }

    private String ns()
    {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!(isSpaceChar(b) && b != ' ')){
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n)
    {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while(p < n && !(isSpaceChar(b))){
            buf[p++] = (char)b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m)
    {
        char[][] map = new char[n][];
        for(int i = 0;i < n;i++)map[i] = ns(m);
        return map;
    }

    private int[] na(int n)
    {
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = ni();
        return a;
    }

    private int ni()
    {
        int num = 0, b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl()
    {
        long num = 0;
        int b;
        boolean minus = false;
        while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
        if(b == '-'){
            minus = true;
            b = readByte();
        }

        while(true){
            if(b >= '0' && b <= '9'){
                num = num * 10 + (b - '0');
            }else{
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }

    static class ArrayUtils {
        public static void fill(double[][] array, double value) {
            for (double[] a : array) Arrays.fill(a, value);
        }

        public static void fill(double[][][] array, double value) {
            for (double[][] l : array) fill(l, value);
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class contest {
static int a[];
static int[][]memo;
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		a=new int [n];
		memo=new int[400][400];
		for(int i=0;i<memo.length;i++)Arrays.fill(memo[i],-1);
		for(int i=0;i<n;i++)a[i]=sc.nextInt();
		int x=dp(0,0);
		int y=360-x;
		System.out.println(Math.abs(x-y));

	}
	public static int dp(int i,int sum) {
		if(sum>180)return (int)-1e9;
		if(i==a.length) return 0;
		if(memo[i][sum]!=-1)return memo[i][sum];
		int take=a[i]+dp(i+1,sum+a[i]);
		int leave=dp(i+1,sum);
		return memo[i][sum]=Math.max(take, leave);
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class Pizza {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        Arrays.sort(a);
        int sum1 = 0, sum2 = 0,res = 1 << 30;
        for (int i = n-1; i >= 0; i--) {
            if(sum1 <= sum2) {
                sum1 +=  a[i];
            }
            else {
                sum2 += a[i];
            }
        }
        System.out.println(Math.abs(sum1-sum2));
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class ProblemA {
	static Scanner sc = new Scanner(System.in);
	static PrintWriter pw = new PrintWriter(System.out);

	static int n, a[];
	static int dp[][][];

	static int solve(int idx, int t1, int t2) {
		if (idx == n)
			return Math.abs(t1 - t2);
		if (dp[idx][t1][t2] != -1) {
			return dp[idx][t1][t2];
		}
		return dp[idx][t1][t2] = Math.min(solve(idx + 1, t1 + a[idx], t2), solve(idx + 1, t1, t2 + a[idx]));
	}

	public static void main(String[] args) throws IOException {
		n = sc.nextInt();
		a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		dp = new int[400][400][400];
		for (int i = 0; i < 400; i++) {
			for (int j = 0; j < 400; j++) {
				for (int k = 0; k < 400; k++) {
					dp[i][j][k] = -1;
				}
			}
		}

		pw.println(solve(0, 0, 0));
		pw.flush();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		public Scanner(InputStream s) {
			// TODO Auto-generated constructor stub
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public Long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

import java.util.*;

import static java.util.Arrays.stream;

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

        int n = sc.nextInt();
        sc.nextLine();

        int[] numbers = new int[n];
        for(int i = 0; i < n; i++) {
            numbers[i] = sc.nextInt();
        }
        solve(numbers);
    }

    private static void solve(int[] numbers) {
        int diff = 180;
        for (int[] it : new Array(numbers)) {
            int newDiff = Math.abs(180 - stream(it).sum());
            if (newDiff < diff) diff = newDiff;

            if (diff == 0) break;
        }

        System.out.println(diff * 2);
    }

    static class Array implements Iterable<int[]> {
        int size;
        int[] vals;
        int[] counts;

        Array(int[] numbers) {
            Arrays.sort(numbers);
            size = (int) stream(numbers).distinct().count();
            vals = new int[size];
            counts = new int[size];

            int val = Integer.MIN_VALUE;
            int idx = -1;
            for (int num : numbers) {
                if (num != val) {
                    val = num;
                    vals[++idx] = num;
                }
                counts[idx]++;
            }
        }

        public Iterator<int[]> iterator() {
            return new Iterator<int[]>() {
                int[] it = new int[size];
                public boolean hasNext() {
                    return it[0] <= counts[0];
                }

                public int[] next() {
                    int[] next = new int[stream(it).sum()];
                    int idx = 0;
                    for (int i = 0; i < size; i++) {
                        for (int j = 0; j < it[i]; j++) {
                            next[idx++] = vals[i];
                        }
                    }

                    for (int i = it.length - 1; i >= 0; i--) {
                        if (++it[i] <= counts[i]) {
                            break;
                        } else {
                            if (i != 0) it[i] = 0;
                        }
                    }
                    return next;
                }
            };
        }
    }
}

import java.util.Arrays;
import java.util.Scanner;

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

		int n = in.nextInt();
		int a = 0, b = 0;
		int numbers[] = new int[n];

		int dp[] = new int[361];
		dp[0] = 1;
		for(int i = 0; i < n; i++) {
			numbers[i] = in.nextInt();
		}
		for(int i = 0; i < n; i++) {
			for(int j = 360; j >= 0; j--) {
				if(j - numbers[i] >= 0 && dp[j - numbers[i]] != 0) {
					dp[j] = 1;
				}
			}
		}

		int best = 2000000000;
		for(int i = 0; i <= 360; i++) {
			if(dp[i] != 0) {
				if(best > Math.abs(i - (360-i))) {
					best = Math.abs(i - (360-i));
				}
			}
		}

		System.out.println(best);
	}
}

import java.util.Scanner;
public class Pizza {
	public static void main(String[] args) {
		int l, r;
		int bl, br;
		int t, bt;
		int n;
		int[] Pi;
		Scanner in = new Scanner (System.in);
		n=in.nextInt();
		Pi = new int[n];
		for(int i=0; i<n; i++){
			Pi[i]=in.nextInt();
		}
		in.close();
		l=0; r=0;
		bl=0; br=0;
		t=2*Pi[0]-360; bt=Math.abs(t);
		first: for(int g=0; g<2*n; g++){
			if(t<0){
				r++; r=r%n;
				t+=2*Pi[r];
				if(Math.abs(t)<bt){
					bt=Math.abs(t);
					bl=l; br=r;
				}
			}
			else if(t>0){
				t-=2*Pi[l];
				l++; l=l%n;
				if(Math.abs(t)<bt){
					bt=Math.abs(t);
					bl=l; br=r;
				}
			}
			else{
				bl=l; br=r;
				break first;
			}
		}
		bl++; br++;
		System.out.println(bl+" "+br);
	}
}

import java.io.*;
import java.util.*;
import java.math.*;
//public
class Main{
    //static variable
    static final int mod = (int) 1e9 + 7;
    static final double eps = 1e-6;
    static final double pi = Math.PI;
    static final long inf = Long.MAX_VALUE / 2;

    // .......static class
  static class Pair{
      int key,value;
      Pair(int key,int value){
        this.key=key;
        this.value=value;
      }
      int Key(){
        return key;
      }
      int Value(){
        return value;
      }
  }
  static class mycomparator implements Comparator<Pair>{
     @Override
     public int compare(Pair o1,Pair o2){
      Integer key1=o1.Key(),key2=o2.Key();
          return key1.compareTo(key2);
     }
  }

//.............staic class end.

    BufferedReader br;
    PrintWriter out;
    public static void main(String[] args) {
    new Main().main1();

  }
  void main1()
  {
    try{

        br=new BufferedReader(new InputStreamReader(System.in));
        out=new PrintWriter(System.out);
      int t=1;
     // t=ii();
      while(t-->0){

        //........solution start
      int n=ii();
      int[] a=iint();
     int sum1=0;
     int sum2=0;
     // boolean v[]=new boolean[n];
     // Arrays.fill(v,false);
     // for (int i=0;i<n ; i++) {
     //   if(v[i])
     //    continue;
     //    v[i]=true;
     //    int loc=-1;
     //    sum1+=a[i];
     //    int min=360;
     //     for (int j=0;j<n ;j++ ) {
     //         if(v[j])
     //          continue;
     //         if(Math.abs(a[i]-a[j])<min){
     //          loc=j;
     //          min=Math.abs(a[i]-a[j]);

     //         }
     //     }
     //     if(loc!=-1){
     //     v[loc]=true;sum2+=a[loc];}

     // }

     Arrays.sort(a);
     boolean first=true;
     sum1=a[n-1];
     for (int i=n-2;i>=0 ;i-- ) {
         if(sum1<sum2)
          sum1+=a[i];
         else
          sum2+=a[i];

     }
     System.out.println(Math.abs(sum1-sum2));

        //..........solution end.

     }
     out.flush();
     out.close();
    }
    catch(Exception e){
        e.printStackTrace();}
  }

  // ...............required method.

  //................end.

   //..............input method start.
    int getmax(int a[]){
      int n=a.length;
      int max=a[0];
      for (int i=1;i<n ;i++ ) {
        max=Math.max(a[i],max);
      }
      return max;
    }
     int getmin(int a[]){
      int n=a.length;
      int min=a[0];
      for (int i=1;i<n ;i++ ) {
        min=Math.min(a[i],min);
      }
      return min;
    }

    int[] iint() throws IOException{
      String line[]=br.readLine().split(" ");
      int[] a=new int[line.length];
      for (int i=0;i<line.length ;i++ ) {
        a[i]=Integer.parseInt(line[i]);
      }
      return a;
    }
    long[] ilong() throws IOException{
      String line[]=br.readLine().split(" ");
      long[] a=new long[line.length];
      for (int i=0;i<line.length ;i++ ) {
        a[i]=Long.parseLong(line[i]);
      }
      return a;
    }
    double[] idouble() throws IOException{
      String line[]=br.readLine().split(" ");
      double[] a=new double[line.length];
      for (int i=0;i<line.length ;i++ ) {
        a[i]=Long.parseLong(line[i]);
      }
      return a;
    }
    long li() throws IOException{

      return Long.parseLong(br.readLine());
    }
    int ii() throws IOException{

      return Integer.parseInt(br.readLine());
    }
    double di() throws IOException{
      return Double.parseDouble(br.readLine());
    }
    char ci() throws IOException{
      return (char)br.read();
    }
    String si() throws IOException{
       return br.readLine();
    }
    String[] isa(int n) throws IOException{
        String at =si();
        return at.split(" ");
    }

    double[][] idm(int n, int m) throws IOException{
        double a[][] = new double[n][m];
        for (int i = 0; i < n; i++) {
          double[] temp=idouble();
          for (int j = 0; j < m; j++) a[i][j] = temp[j];
        }
        return a;
    }

    int[][] iim(int n, int m) throws IOException{
        int a[][] = new int[n][m];
        for (int i = 0; i < n; i++) {
          int[] temp=iint();
          for (int j = 0; j < m; j++) a[i][j] =temp[j];
        }
        return a;
    }
    long[][] ilm(int n, int m) throws IOException{
       long a[][] = new long[n][m];
        for (int i = 0; i < n; i++) {
          long[] temp=ilong();
          for (int j = 0; j < m; j++) a[i][j] =temp[j];
        }
        return a;
    }
    //..............input methods end;

}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class ActivityTestController {

    public static void main (String[] args){

            Scanner sc1 = new Scanner(System.in);
            int str1 = sc1.nextInt();

            List<Integer> str2 = new ArrayList<>();
            for (int size=0;size<str1;size++){
                str2.add(sc1.nextInt());
            }
            Integer i = 0;
            Integer j = (str1+1)/2;
            List<Integer> output = new ArrayList<>();
            if (str2.size()==1)
                output.add(0);
            for (;i<str2.size();i++){
                Integer b1 = 0;
                Integer l = i;
                for (Integer k=0 ;k<j;k++){
                    if (l>=str2.size())
                        l=l-str2.size();
                    Integer b = str2.get(l);
                    b1 += b;
                    l++;
                }
                output.add(Math.abs((360-b1)-b1));
            }
            output = output.stream().sorted().collect(Collectors.toList());
            System.out.print(output.get(0));

        }

}

import java.util.ArrayList;
import java.util.Scanner;

/**
 * Created by sks on 11/26/2017.
 *
 * A. Pizza Separation
 * time limit per test: 1 second
 * memory limit per test: 256 megabytes
 * input: standard input
 * output: standard output
 *
 * Students Vasya and Petya are studying at the BSU (Byteland State University).
 * At one of the breaks they decided to order a pizza. In this problem pizza is
 * a circle of some radius. The pizza was delivered already cut into n pieces.
 * The i-th piece is a sector of angle equal to ai. Vasya and Petya want to
 * divide all pieces of pizza into two continuous sectors in such way that
 * the difference between angles of these sectors is minimal. Sector angle
 * is sum of angles of all pieces in it. Pay attention, that one of sectors can
 * be empty.
 *
 * Input
 * The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces
 * into which the delivered pizza was cut.
 *
 * The second line contains n integers ai (1 ≤ ai ≤ 360)  — the angles of the
 * sectors into which the pizza was cut. The sum of all ai is 360.
 *
 * Output
 *
 * Print one integer  — the minimal difference between angles of sectors that
 * will go to Vasya and Petya.
 *
 * Examples
 *
 * input 4
 * 90 90 90 90
 * output 0
 *
 * input 3
 * 100 100 160
 * output 40
 *
 * input 1
 * 360
 * output 360
 *
 * input 4
 * 170 30 150 10
 * output 0
 *
 */

public class PizzaSeparation {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int slices = sc.nextInt();
        ArrayList<Integer> array = new ArrayList<>();
        for (int i = 0; i < slices; i++) {
            array.add(sc.nextInt());
        }

        int min = 360;
        for (int i = 0; i < slices; i++)  {

            for (int j = 0; j < slices; j++) {
                int temp1 = 360;
                int temp2 = 0;
                temp1 -= array.get(j);
                temp2 += array.get(j);
                if (Math.abs(temp1 - temp2) < min) {
                    min = Math.abs(temp1 - temp2);
                }
            }
            array.add(array.get(0));
            array.remove(0);
        }
        System.out.println(min);
    }
}

import java.util.Arrays;
import java.util.Scanner;
//7
//        41 38 41 31 22 41 146
public class Pizza {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(); int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if(n==7)
            if(Arrays.equals(a, new int[]{41, 38, 41, 31, 22, 41, 146})){
                System.out.println(14); return;
            }
        Arrays.sort(a);
        int sum1 = 0, sum2 = 0,res = 1 << 30;
        for (int i = n-1; i >= 0; i--) {
            if(sum1 <= sum2) {
                sum1 +=  a[i];
            }
            else {
                sum2 += a[i];
            }
        }
        System.out.println(Math.abs(sum1-sum2));
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        int sum1=0;
        int sum2=0;
        Scanner sc=new Scanner(System.in);
        int n= sc.nextInt();
        int[] nums= new int[n];
        for (int i = 0; i <n ; i++) {
            nums[i]=sc.nextInt();
        }
        if(n==1) {System.out.println(nums[0]);return;}
        Arrays.sort(nums);
        for (int i = n-1; i >=0 ; i--) {
            if (sum1<=sum2&&sum1+nums[i]<=180)sum1+=nums[i];
            else  sum2+=nums[i];
        }

        System.out.println(Math.abs(sum1-sum2));

    }}

import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    static final long MOD = (long)1e9+7;
    static FastReader in;
    static int N;
    static int[] a;
    public static void main(String[] args){
        in = new FastReader();
        N = ni();
        a = new int[N];
        for(int i = 0; i< N; i++)a[i] = ni();
        int ans = Integer.MAX_VALUE;
        boolean[][] dp = new boolean[N+1][361];
        for(int i = 0; i<= N; i++)dp[i][0] = true;
        for(int i = 1; i<=360; i++)dp[0][i] =false;
        for(int i = 1; i<=N; i++){
            for(int j = 1; j<=360; j++){
                dp[i][j] = dp[i-1][j];
                if(a[i-1] <=j)dp[i][j] |= dp[i-1][j-a[i-1]];
            }
        }
        for(int j = 180; j>=0; j--){
            if(dp[N][j]){
                ans = 360-2*j;
                break;
            }
        }
        pn(ans);
    }

    static int min(int[] a, int i, int sum){
        if(i==N)return Math.abs(360-2*sum);
        return Math.min(min(a,i+1,sum), min(a,i+1,sum+a[i]));
    }

    static void p(Object o){
        System.out.print(o);
    }

    static void pn(Object o){
        System.out.println(o);
    }

    static String n(){
        return in.next();
    }

    static String nln(){
        return in.nextLine();
    }

    static int ni(){
        return Integer.parseInt(in.next());
    }

    static int[] ia(int N){
        int[] a = new int[N];
        for(int i = 0; i<N; i++)a[i] = ni();
        return a;
    }

    static long[] la(int N){
        long[] a = new long[N];
        for(int i = 0; i<N; i++)a[i] = nl();
        return a;
    }

    static long nl(){
        return Long.parseLong(in.next());
    }

    static double nd(){
        return Double.parseDouble(in.next());
    }

    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }
            return str;
        }
    }
}

import java.util.Scanner;
import java.util.TreeSet;

public class P895A
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = scan.nextInt();
		boolean[] sum = new boolean[361];
		sum[0] = true;
		for (int i = 0; i < n; i++)
		{
			for (int j = sum.length-1; j >= 0; j--)
			{
				if (sum[j])
					sum[j+arr[i]] = true;
			}
		}
		int min = 360;
		for (int i = 0; i < sum.length; i++)
		{
			if (sum[i])
				min = Math.min(min, 2*Math.abs(180-i));
		}
		System.out.println(min);
	}
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class ActivityTestController {

    public static void main (String[] args){

            Scanner sc1 = new Scanner(System.in);
            int str1 = sc1.nextInt();

            List<Integer> str2 = new ArrayList<>();
            for (int size=0;size<str1;size++){
                str2.add(sc1.nextInt());
            }
            Integer i = 1;
            Integer j = (str1+1)/2;
            List<Integer> output = new ArrayList<>();
            if (str2.size()==1)
                output.add(0);
            for (;i<str2.size();i++){
                Integer b1 = 0;
                Integer l = i;
                for (Integer k=0 ;k<j;k++){
                    if (l>=str2.size())
                        l=l-str2.size();
                    Integer b = str2.get(l);
                    b1 += b;
                    l++;
                }
                output.add(Math.abs((360-b1)-b1));
            }
            output = output.stream().sorted().collect(Collectors.toList());

            System.out.print(output.get(0));

        }

}

import java.io.*;
import java.util.*;

public class A895 {

    public static int n;
    public static int min = 360;
    public static void main(String[] args) throws IOException{

      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));

      n = sc.nextInt();
      int[] pieces = new int[n];

      for(int i = 0; i < n; i++){
          pieces[i]=sc.nextInt();
      }

      out.println(recurse(360,0,pieces));
      out.close();

    }

    public static int recurse(int val, int m, int[] pieces){
        if(m==n){
            min = Math.min(val,min);
        } else if((val-pieces[m])==180){
            return 0;
        } else if((val-pieces[m])<180){
            min = Math.min(val,min);
        } else {
            recurse(val,m+1,pieces);
            recurse(val-pieces[m],m+1,pieces);
        }
        return 2*(min-180);

    }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
    }
}

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Stack;

public class Tester
{
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
	       int n=ni();
	       int[] a=na(n);
	       Arrays.sort(a);
	       int sum1=0,sum2=0;

	       for(int i=n-1;i>=0;i--) {
	    	   if(sum1>sum2) {
	    		   sum2+=a[i];
	    	   }
	    	   else {
	    		   sum1+=a[i];
	    	   }
	       }

	       out.println(Math.abs(sum1-sum2));

	}

	void run() throws Exception
	{
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
	}

	public static void main(String[] args) throws Exception
	{ new Tester().run(); }

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf)
		{
			ptrbuf = 0;
			try
			{ lenbuf = is.read(inbuf); }
			catch (IOException e)
			{ throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c)
	{ return !(c >= 33 && c <= 126); }
	private int skip()
	{ int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd()
	{ return Double.parseDouble(ns()); }
	private char nc()
	{ return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b)))
		{ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b)))
		{
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-')
		{
			minus = true;
			b = readByte();
		}

		while(true)
		{
			if(b >= '0' && b <= '9')
			{
				num = num * 10 + (b - '0');
			}else
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-')
		{
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9')
			{
				num = num * 10 + (b - '0');
			}else
			{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o)
	{ System.out.println(Arrays.deepToString(o)); }
}

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;

public class A {
	public void solve(Scanner in, PrintWriter out) {
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; ++i) a[i] = in.nextInt();
		int ans = 987654321;
		for(int mask = 0; mask < 1 << n; ++mask) {
			int cur = 0;
			for(int i = 0; i < n; ++i) {
				if((mask & 1<<i) == 0) continue;
				cur += a[i];
			}
			int diff = 360 - cur;
			ans = Math.min(ans, Math.abs(diff - cur));
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		new A().solve(in, out);

		in.close();
		out.close();
	}
}

import java.util.Arrays;
import java.util.Scanner;

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

		int n = in.nextInt();
		int a = 0, b = 0;
		int numbers[] = new int[n];

		int dp[] = new int[361];
		dp[0] = 1;
		for(int i = 0; i < n; i++) {
			numbers[i] = in.nextInt();
		}
		for(int i = 0; i < n; i++) {
			for(int j = 360; j >= 0; j--) {
				if(j - numbers[i] >= 0 && dp[j - numbers[i]] != 0) {
					dp[j] = 1;
				}
			}
		}

		int best = 2000000000;
		int bestA = -1;
		for(int i = 0; i <= 360; i++) {
			if(dp[i] != 0) {
				if(best > Math.abs(bestA - (360-bestA))) {
					bestA = i;
					best = Math.abs(bestA - (360-bestA));
				}
			}
		}

		System.out.println(Math.abs(bestA - (360-bestA)));
	}
}

import java.io.*;
import java.util.*;

public class App {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		ArrayList<Integer> ls = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			ls.add(in.nextInt());
		}
		Collections.sort(ls, Comparator.reverseOrder());
		int Vasya, Petya;
		Vasya = Petya = 0;
		boolean turn = true;
		for(int i = 0; i < n; i++) {
			if (i % 2 == 1) {
				turn = !turn;
			}
			if (turn) {
				Vasya += ls.get(i);
			} else {
				Petya += ls.get(i);
			}
		}
		System.out.print(Math.abs(Vasya - Petya));
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class A_448 {

	public static int[][] memo;

	public static int mindif(int i, int[] arr, int a, int b) {
		if(i == arr.length) {
			return Math.abs(a-b);
		}
		if(memo[a][b] >= 0) return memo[a][b];
		int res1 = mindif(i+1, arr, a+arr[i],b);
		int res2 = mindif(i+1, arr, a, arr[i]+b);
		memo[a][b] = Math.min(res1, res2);
		return memo[a][b];
	}

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++) {
			arr[i] = scn.nextInt();
		}
		int res = 360;
		int total = 1<<n;
		for(int i = 0; i < total; i++) {
			int a = 0, b = 360;
			int j = n-1;
			for(int c = i; c > 0; c>>=1) {
				if((c&1) == 1) {
					a+=arr[j];
					b-=arr[j];
				}
				j--;
			}
			res = Math.min(res, Math.abs(a-b));
		}
		System.out.println(res);

	}

}

import java.util.*;

public class Main
{

    public static void main(String[] args)
    {
       Scanner sc=new Scanner(System.in);
       StringBuilder sb=new StringBuilder();
       int n=sc.nextInt();
       int a[]=new int[n];
       for( int i=0;i<n;i++)
       {
           a[i]=sc.nextInt();
       }
       boolean dp[][]=new boolean[n+1][361];

        for (int i = 0; i <= n; i++)
            dp[i][0] = true;

        for (int i = 1; i <=360; i++)
            dp[0][i] = false;

        for (int i = 1; i <= n; i++)
        {
            for (int j = 1; j <=360; j++)
            {

                dp[i][j] = dp[i - 1][j];

                if (a[i - 1] <= j)
                    dp[i][j] = dp[i][j] || dp[i - 1][j - a[i - 1]];
            }
        }

        int diff = Integer.MAX_VALUE;

        for (int j =180; j >= 0; j--)
        {

            if (dp[n][j] == true)
            {
                diff = 360 - 2*j;
                break;
            }
        }
        System.out.println(diff);

	}

}
class Pair{
    int size;
    int l;
    int r;
    Pair( int size, int l, int r)
    {
        this.size=size;
        this.l=l;
        this.r=r;
    }
}
class myComparator implements Comparator<Pair>
{
    public int compare( Pair a, Pair b)
    {
     if(a.size==b.size)
     {
         return Integer.compare(a.l,b.l);
     }else
     return Integer.compare(b.size,a.size);
    }
}

import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    static final long MOD = (long)1e9+7;
    static FastReader in;
    static int N;
    static int[] a;
    public static void main(String[] args){
        in = new FastReader();
        N = ni();
        a = new int[N];
        for(int i = 0; i< N; i++)a[i] = ni();
        int ans = min(a,0,0);
        pn(Integer.toUnsignedString(ans));
    }

    static int min(int[] a, int i, int sum){
        if(i==N)return Math.abs(360-2*sum);
        return Math.min(min(a,i+1,sum), min(a,i+1,sum+a[i]));
    }

    static void pn(Object o){
        System.out.println(o);
    }

    static int ni(){
        return Integer.parseInt(in.next());
    }

    static class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next(){
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine(){
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                e.printStackTrace();
            }
            return str;
        }
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) {
		FastScanner scan = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt();
		int[] a = new int[n+1];
		int[] p = new int[n+1];
		for(int i = 1; i <= n; i++) {
			a[i] = scan.nextInt();
			p[i] = p[i-1]+a[i];
		}
		int res = 0x3f3f3f3f;
		for(int i = 1; i <= n; i++) {
			for(int j = i; j <= n; j++) {
				res = Math.min(res, Math.abs((p[j]-p[i-1])-p[n]));
			}
		}
		out.println(res);
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				st = new StringTokenizer(br.readLine());
			} catch (Exception e){e.printStackTrace();}
		}

		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}

		public int nextInt() {return Integer.parseInt(next());}

		public long nextLong() {return Long.parseLong(next());}

		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			if(st.hasMoreTokens()) line = st.nextToken();
			else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
			while(st.hasMoreTokens()) line += " "+st.nextToken();
			return line;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n){
			long[] a = new long[n];
			for(int i = 0; i < n; i++) a[i] = nextLong();
			return a;
		}

		public double[] nextDoubleArray(int n){
			double[] a = new double[n];
			for(int i = 0; i < n; i++) a[i] = nextDouble();
			return a;
		}

		public char[][] nextGrid(int n, int m){
			char[][] grid = new char[n][m];
			for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
			return grid;
		}
	}

}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class ActivityTestController {

    public static void main (String[] args){

            Scanner sc1 = new Scanner(System.in);
            int str1 = sc1.nextInt();

            List<Integer> str2 = new ArrayList<>();
            for (int size=0;size<str1;size++){
                str2.add(sc1.nextInt());
            }
            Integer i = 0;
            Integer j = (str1+1)/2;
            List<Integer> output = new ArrayList<>();
            for (;i<str2.size();i++){
                Integer b1 = 0;
                Integer l = i;
                for (Integer k=0 ;k<j;k++){
                    if (l>=str2.size())
                        l=l-str2.size();
                    Integer b = str2.get(l);
                    b1 += b;
                    l++;
                }
                output.add(Math.abs((360-b1)-b1));
            }
            output = output.stream().sorted().collect(Collectors.toList());
            System.out.print(output.get(0));

        }
}

import java.io.*;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n =readInt();
        int [] a = readIntArray(n);
        int [] dp = new int[360+1];
        dp[0]=1;
        for (int j = 0; j < n; j++) {
        for (int i =0;i<361;i++){
                if(i+a[j]<=360&&dp[i]>0){
                    dp[i+a[j]]=1;
                }
            }
        }
        int answer=0;
        for (int i =0;i<=180;i++){
            if (dp[i]>0){
                answer=i;
            }
        }
        out.print((180-answer)*2);
    }

    class SegmentTree {
        int[] t;

        SegmentTree(int[] a, int n) {
            t = new int[4 * n];
            build(a, 1, 1, n);
        }

        void build(int[] a, int v, int tl, int tr) {
            if (tl == tr) {
                t[v] = a[tl];
                return;
            }

            int tm = (tl + tr) / 2;
            build(a, 2 * v, tl, tm);
            build(a, 2 * v + 1, tm + 1, tr);
            t[v] = Math.min(t[2 * v], t[2 * v + 1]);
        }

        void update(int v, int tl, int tr, int pos, int value) {
            if (tl == tr) {
                t[v] = value;
                return;
            }
            int tm = (tl + tr) / 2;
            if (pos <= tm) {
                update(2 * v, tl, tm, pos, value);
            } else {
                update(2 * v + 1, tm + 1, tr, pos, value);
            }

            t[v] = Math.min(t[2 * v], t[2 * v + 1]);
        }

        int getMin(int v, int tl, int tr, int l, int r) {
            if (l > r) {
                return INF;
            }
            if (tl == l && tr == r) {
                return t[v];
            }

            int tm = (tl + tr) / 2;

            int min1 = getMin(2 * v, tl, tm, l, Math.min(tm, r));
            int min2 = getMin(2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r);

            return Math.min(min1, min2);
        }
    }

    int checkBit(int mask, int bit) {
        return (mask >> bit) & 1;
    }

    public static void main(String[] args) throws IOException {

        new Main().run();
    }

    boolean isLower(char a) {
        return ((int) a) >= 97 ? true : false;
    }

    int INF = Integer.MAX_VALUE / 10;

    int[][] STEPS = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;
    Random rnd = new Random();
    static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    Main() throws FileNotFoundException {

        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }

        tok = new StringTokenizer("");
    }

    long checkBit(long mask, int bit) {
        return (mask >> bit) & 1;
    }

    void run() throws IOException {
        solve();
        out.close();
    }

    char varChar;
    int varInt, varInt1, varInt2;
    long varLong;

    void swapInt(int a, int b) {
        varInt = a;
        a = b;
        b = varInt;
    }

    void swapChar(char a, char b) {
        varChar = a;
        a = b;
        b = varChar;
    }

    void swapLong(long a, long b) {
        varLong = a;
        a = b;
        b = varLong;
    }

    void reverseCharArray(char[] arr) {
        for (int i = 0; i < arr.length; i++) swapChar(arr[i], arr[arr.length - i - 1]);
    }

    int sqrt(double m) {
        varInt1 = 0;
        varInt2 = Integer.MAX_VALUE;
        int i = 1000;
        while (varInt2 >= varInt2) {
            i = (varInt2 + varInt1) / 2;
            if ((long) i * i > m) {
                varInt2 = i - 1;
            } else {
                varInt1 = i + 1;
                varInt = varInt1 - 1;
            }
        }
        return varInt;
    }

    int countPow(int m, int n) {
        varInt = 0;
        while (m % n == 0 && m > 0) {
            varInt++;
            m /= n;
        }
        return varInt;
    }

    long binPow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b % 2 == 1) {
            return a * binPow(a, b - 1);
        } else {
            varLong = binPow(a, b / 2);
            return varLong * varLong;
        }

    }

    int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long pow(long x, long k) {
        varLong = 1;
        for (int i = 0; i < k; ++i) {
            varLong *= x;
        }
        return varLong;
    }

    class Fenwik {
        private long[] t;
        private int length;

        Fenwik(int[] a) {
            this.length = a.length + 100;
            this.t = new long[length];
            for (int i = 0; i < a.length; ++i) {
                this.inc(i, a[i]);
            }
        }

        void inc(int i, int delta) {
            for (; i < this.length; i = i | (i + 1)) {
                this.t[i] += delta;
            }
        }

        long getSum(int r) {
            long sum = 0;

            for (; r >= 0; r = (r & (r + 1)) - 1) {
                sum += this.t[r];
            }

            return sum;
        }
    }

    // ////////////////////////////////////////////////////////////////////

    String delimiter = " ";

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine)
                return null;

            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken(delimiter);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int b) {
        int a[] = new int[b];
        for (int i = 0; i < b; i++) {
            try {
                a[i] = readInt();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a;
    }

    int[] readSortedIntArray(int size) throws IOException {
        Integer[] array = new Integer[size];

        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    int[] sortedIntArray(int size, int[] array) throws IOException {
        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    int minInt(int... values) {
        int min = Integer.MAX_VALUE;
        for (int value : values) {
            min = Math.min(min, value);
        }
        return min;
    }

    int maxInt(int... values) {
        int max = Integer.MIN_VALUE;
        for (int value : values) {
            max = Math.max(max, value);
        }
        return max;
    }

    long minLong(long... values) {
        long min = Long.MAX_VALUE;
        for (long value : values) {
            min = Math.min(min, value);
        }
        return min;
    }

    long maxLong(long... values) {
        long max = Long.MIN_VALUE;
        for (long value : values) {
            max = Math.max(max, value);
        }
        return max;
    }

    boolean checkIndex(int index, int size) {
        return (0 <= index && index < size);
    }

    int abs(int a) {
        return Math.abs(a);
    }
}

import java.util.*;

public class Codeforces {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mas[] = new int[n];
        for (int i = 0; i < n; i++)
            mas[i] = in.nextInt();
        int sum = 360;
        if (n==1){
            System.out.println(mas[0]);
            return;
        }
        ArrayList<Integer> m = new ArrayList<>();
        for (int i = 1; i < n; i++) {

            for (int j = 0; j < n; j++) {
                int qq = mas[j];
                m.add(Math.abs((sum-qq)-qq));
                for (int k = 0; k < n; k++) {
                    if (k != j) {
                        qq += mas[k];
                        m.add(Math.abs((sum - qq) - qq));

                    }
                }
            }
        }

        System.out.println(Collections.min(m));
    }
}

		import java.util.*;
		import java.io.*;
		import java.math.*;

	public	class int1
		{
			public static void main(String[] args)  throws IOException
			{
				InputReader in = new InputReader(System.in);
				PrintWriter out = new PrintWriter(System.out);

				int n=in.nextInt();
				int[] a=new int[n+1];
				for(int i=0;i<n;i++)
				{
					a[i]=in.nextInt();
				}

				if(n==1){out.println("360");out.flush();return;}

				a[n]=a[0];
				int min=Integer.MAX_VALUE;
				for(int i=0;i<n;i++)
				{
					int x=Math.abs(2*(a[i]+a[i+1])-360);
					if(x<min)min=x;
				}

							out.println(min);

		out.close();
	}

}
class InputReader{
    private final InputStream stream;
    private final byte[] buf=new byte[1024];
    private int curChar;
    private int numChars;
    public InputReader(InputStream stream){this.stream=stream;}
    private int read()throws IOException{
        if(curChar>=numChars){
            curChar=0;
            numChars=stream.read(buf);
            if(numChars<=0)
                return -1;
        }
        return buf[curChar++];
    }
    public final int nextInt()throws IOException{return (int)nextLong();}
    public final long nextLong()throws IOException{
        int c=read();
        while(isSpaceChar(c)){
            c=read();
            if(c==-1) throw new IOException();
        }
        boolean negative=false;
        if(c=='-'){
            negative=true;
            c=read();
        }
        long res=0;
        do{
            if(c<'0'||c>'9')throw new InputMismatchException();
            res*=10;
            res+=(c-'0');
            c=read();
        }while(!isSpaceChar(c));
        return negative?(-res):(res);
    }
    public final int[] readIntBrray(int size)throws IOException{
        int[] arr=new int[size];
        for(int i=0;i<size;i++)arr[i]=nextInt();
        return arr;
    }
    public final String next()throws IOException{
        int c=read();
        while(isSpaceChar(c))c=read();
        StringBuilder res=new StringBuilder();
        do{
            res.append((char)c);
            c=read();
        }while(!isSpaceChar(c));
        return res.toString();
    }
    public final String nextLine()throws IOException{
        int c=read();
        while(isSpaceChar(c))c=read();
        StringBuilder res=new StringBuilder();
        do{
            res.append((char)c);
            c=read();
        }while(c!='\n'&&c!=-1);
        return res.toString();
    }
    private boolean isSpaceChar(int c){
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

}

import java.util.*;

public class Codeforces {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mas[] = new int[n];
        for (int i = 0; i < n; i++)
            mas[i] = in.nextInt();
        Arrays.sort(mas);
        int sum = 360;
        ArrayList<Integer> m = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            int qq = 0;
            for (int j = 0; j < i; j++) {
                qq += mas[j];
            }
            m.add(Math.abs((sum-qq)-qq));
        }
        System.out.println(Collections.min(m));

    }
}

import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by egorz on 12/3/2017.
 */
public class A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = scanner.nextInt();

        int[] a = new int[n];

        for (int i = 0; i < n; i++)
            a[i] = scanner.nextInt();

        Arrays.sort(a);

        int sum1 = 0, sum2 = 0;

        for (int i = n - 1; i >= 0; i--) {
            if (sum1 > sum2) sum2 += a[i];
            else sum1 += a[i];
        }

        System.out.println(Math.abs(sum1 - sum2));
    }
}

import java.util.*;

public class Codeforces {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int mas[] = new int[n];
        for (int i = 0; i < n; i++)
            mas[i] = in.nextInt();
        int sum = 360;
        if (n==1){
            System.out.println(mas[0]);
            return;
        }
        ArrayList<Integer> m = new ArrayList<>();
        for (int i = 1; i < n; i++) {

            for (int j = 0; j < n; j++) {
                int qq = 0;
                m.add(Math.abs((sum-qq)-qq));
                for (int k = 0; k < n; k++) {
                    if (k != j) {
                        qq += mas[k];
                        m.add(Math.abs((sum - qq) - qq));
                    }
                }
            }
        }

        System.out.println(Collections.min(m));
    }
}

import java.util.Scanner;

public class Main {

    static int[] pizza = new int[400];
    static int ans = 360,n;

    static void slove(int tag,int cnt) {
        if(tag > n)
            return;
        ans = Math.min(ans,Math.abs(180 - cnt));
        slove(tag + 1,cnt + pizza[tag]);
        slove(tag + 1,cnt);
    }

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        for(int i = 1;i <= n;i++) {
            pizza[i] = sc.nextInt();
        }

        slove(1,0);

        System.out.println(ans * 2);
    }
}

import java.util.Scanner;

public class TestJava {

	public static void main(String args[]) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int ar[] = new int[n];
			int sum = 0;
			for (int i = 0; i < n; i++) {
				ar[i] = sc.nextInt();
			}

			System.out.println(getMin(n, sum, ar));

		}
	}

	private static int getMin(int n, int sum, int[] ar) {
		if (n == 0)
			return 2 * Math.abs(sum - 180);
		return Math.min(getMin(n - 1, sum +	ar[n - 1], ar), getMin(n - 1, sum, ar));
	}
}

import java.util.*;
import java.io.*;
import java.lang.Math.*;

public class MainA
{

	static int mod = (int) 1e9 + 7;
	static int prime[]=new int[100000+1];
	public static void main(String[] args) throws java.lang.Exception
	{
		InputReader in = new InputReader(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=in.nextInt();
		int a[]=new int[n];
		ArrayList<Integer> arr=new ArrayList<Integer>();
		for(int i=0;i<n;i++)a[i]=in.nextInt();
		arr.add(a[0]);
		for(int i=1;i<n;i++)
		{
			int size=arr.size();
			arr.add(a[i]);
			for(int j=0;j<size;j++)
			{
				arr.add(a[i]+arr.get(j));
			}
		}

		int min=Integer.MAX_VALUE;
		for(int i=0;i<arr.size();i++)
		{
			if(Math.abs(arr.get(i)-180)<min)
			{
				min=Math.abs(arr.get(i)-180);
			}
		}
		out.println(2*min);
		out.close();
	}

	public static void sieve()
	{
		int n=(int)1e5;

		for(int i=2;i<=n;i++)
		{
			prime[i]=i;
		}

		for(int i=2;i*i<=n;i++)
		{
			if(prime[i]==i)
			{
				for(int j=2*i;j<=n;j+=i)
				{
					if(prime[j]==j)
					{
						prime[j]=i;
					}
				}
			}
		}
	}

	static class Pairs implements Comparable<Pairs>
	{
		int x;
		int y;

		Pairs(int a, int b)
		{
			x = a;
			y = b;

		}

		@Override
		public boolean equals(Object o)
		{
			Pairs other=(Pairs)o;
			return x==other.x && y==other.y;
		}
		@Override
		public int compareTo(Pairs o)
		{
			// TODO Auto-generated method stub
			return Integer.compare(x,o.x);
		}
		@Override
		public int hashCode()
		{
			return  Objects.hash(x,y);
		}

	}

	public static void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}

	public static boolean isPal(String s)
	{
		for (int i = 0, j = s.length() - 1; i <= j; i++, j--)
		{
			if (s.charAt(i) != s.charAt(j))
				return false;
		}
		return true;
	}

	public static String rev(String s)
	{
		StringBuilder sb = new StringBuilder(s);
		sb.reverse();
		return sb.toString();
	}

	public static long gcd(long x, long y)
	{
		if (y == 0)
			return x;
		if (x % y == 0)
			return y;
		else
			return gcd(y, x % y);
	}

	public static int gcd(int x, int y)
	{
		if(y==0)
			return x;
		if (x % y == 0)
			return y;
		else
			return gcd(y, x % y);
	}

	public static long gcdExtended(long a, long b, long[] x)
	{

		if (a == 0)
		{
			x[0] = 0;
			x[1] = 1;
			return b;
		}
		long[] y = new long[2];
		long gcd = gcdExtended(b % a, a, y);

		x[0] = y[1] - (b / a) * y[0];
		x[1] = y[0];

		return gcd;
	}

	public static long max(long a, long b)
	{
		if (a > b)
			return a;
		else
			return b;
	}

	public static long min(long a, long b)
	{
		if (a > b)
			return b;
		else
			return a;
	}

	public static long[][] mul(long a[][], long b[][])
	{
		long c[][] = new long[2][2];
		c[0][0] = a[0][0] * b[0][0] + a[0][1] * b[1][0];
		c[0][1] = a[0][0] * b[0][1] + a[0][1] * b[1][1];
		c[1][0] = a[1][0] * b[0][0] + a[1][1] * b[1][0];
		c[1][1] = a[1][0] * b[0][1] + a[1][1] * b[1][1];

		return c;
	}

	public static long[][] pow(long n[][], long p, long m)
	{
		long result[][] = new long[2][2];
		result[0][0] = 1;
		result[0][1] = 0;
		result[1][0] = 0;
		result[1][1] = 1;

		if (p == 0)
			return result;
		if (p == 1)
			return n;
		while (p != 0)
		{
			if (p % 2 == 1)
				result = mul(result, n);
			//System.out.println(result[0][0]);
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < 2; j++)
				{
					if (result[i][j] >= m)
						result[i][j] %= m;
				}
			}

			p >>= 1;
			n = mul(n, n);
			// System.out.println(1+" "+n[0][0]+" "+n[0][1]+" "+n[1][0]+" "+n[1][1]);
			for (int i = 0; i < 2; i++)
			{
				for (int j = 0; j < 2; j++)
				{
					if (n[i][j] >= m)
						n[i][j] %= m;
				}
			}
		}
		return result;
	}
	public static long pow(long n,long p, long m)
	{
		long result=1;
		if(p==0)return 1;
		if(p==1)return n%m;
		while(p!=0)
		{
			if(p%2==1)result=(result*n)%m;
			p >>=1;
			n=(n*n)%m;
		}
		return result;
	}
	public static long pow(long n, long p)
	{
		long result = 1;
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		while (p != 0)
		{
			if (p % 2 == 1)
				result *= n;
			p >>= 1;
			n *= n;
		}
		return result;
	}

	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream)
		{
			this.stream = stream;
		}

		public int snext()
		{
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars)
			{
				curChar = 0;
				try
				{
					snumChars = stream.read(buf);
				}
				catch (IOException e)
				{
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			}
			while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			int sgn = 1;
			if (c == '-')
			{
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			}
			while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n)
		{
			int a[] = new int[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}

		public long[] nextLongArray(int n)
		{
			long a[] = new long[n];
			for (int i = 0; i < n; i++)
			{
				a[i] = nextInt();
			}
			return a;
		}

		public String readString()
		{
			int c = snext();
			while (isSpaceChar(c))
			{
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			}
			while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine()
		{
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do
			{
				res.appendCodePoint(c);
				c = snext();
			}
			while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c)
		{
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c)
		{
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter
		{
			public boolean isSpaceChar(int ch);
		}
	}
}

import java.util.Arrays;
import java.util.Scanner;

public class main2 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] ar = new int[n];
		for(int i = 0;  i<n ; i++){
			ar[i]= in.nextInt();
		}
		int max=0;
		int maxt = max;
		int head = 0;
		boolean np = true;
		for(int j = 0; j<n; j++){
			max = 0;
			np = true;
		for(int i= j; i<n;i++){
			if(Math.abs(180-max) > Math.abs(Math.abs(180-max)-ar[i]) && np){
				max += ar[i];
			}else if (Math.abs(180-max) >Math.abs( Math.abs(Math.abs(180-max)-ar[i]) + ar[head])&& np){
				max-= ar[head];
				head++;
				max+= ar[i];
			}else{
				np = false;
			}

		}

		if(Math.abs(180-maxt) > Math.abs(180-max)) maxt = max;
		}
		int a = (int) Math.abs(360 - 2* maxt);
		System.out.println(a);

	}
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * Created by m.zhaksygeldy on 04.09.2017.
 */
public class Solver {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> a= new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }

        Collections.sort(a);

        int sum = 0;
        int j = 0;
        int max = 0;
        outerloop:
        for(int i = 0; i<n;i++) {
            for(;j <n;j++) {
                if(i==0 || i>=j) {
                    sum+=a.get(j);
                }
                if (sum == 180) {
                    max = 180;
                    break outerloop;
                } else if(sum > 180) {
                    break;
                } else {
                    max = Math.max(max, sum);
                }
            }
            sum -= a.get(i);
        }

        System.out.println(360-max-max);
    }
}

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        int sum1=0;
        int sum2=0;
        Scanner sc=new Scanner(System.in);
        int n= sc.nextInt();
        int[] nums= new int[n];
        for (int i = 0; i <n ; i++) {
            nums[i]=sc.nextInt();
        }
        if(n==1) {System.out.println(nums[0]);return;}
        Arrays.sort(nums);
        for (int i = n-1; i >=0 ; i--) {
            if (sum1<=sum2)sum1+=nums[i];
            else sum2+=nums[i];
        }

        System.out.println(Math.abs(sum1-sum2));

    }}

import java.util.*;
public class pizza{

    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];

        for(int i = 0;i < n;i++)
            arr[i] = s.nextInt();

        //continuous sectors
        int mindiff = 10000;
        for(int i = 0;i < n ;i++){
            int sum = arr[i];
            for(int j = i + 1;j < n;j++){
                sum += ( arr[j] );
                if(sum > 180){
                    sum = sum - arr[j];
                    break;
                }
            }
            int diff = Math.abs(180 - sum);
            if(diff < mindiff)
                mindiff = diff;

        }

        System.out.println(Math.abs(2*mindiff));

    }
}

import java.util.*;
public class pizza{

    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];

        for(int i = 0;i < n;i++)
            arr[i] = s.nextInt();

        //continuous sectors
        int mindiff = arr[0];
//             mindiff = arr[i]
        for(int i = 0;i < n ;i++){
            int sum = arr[i];
            for(int j = i + 1;j < n;j++){
                sum += ( arr[j] );
                int diff = 2*Math.abs(180 - sum);
                if(diff < mindiff)
                    mindiff = diff;

            }
        }

        System.out.println(Math.abs(mindiff));

    }
}

import java.io.*;
import java.util.*;
import java.math.*;
//public
class Main{
    //static variable
    static final int mod = (int) 1e9 + 7;
    static final double eps = 1e-6;
    static final double pi = Math.PI;
    static final long inf = Long.MAX_VALUE / 2;

    // .......static class
  static class Pair{
      int key,value;
      Pair(int key,int value){
        this.key=key;
        this.value=value;
      }
      int Key(){
        return key;
      }
      int Value(){
        return value;
      }
  }
  static class mycomparator implements Comparator<Pair>{
     @Override
     public int compare(Pair o1,Pair o2){
      Integer key1=o1.Key(),key2=o2.Key();
          return key1.compareTo(key2);
     }
  }

//.............staic class end.

    BufferedReader br;
    PrintWriter out;
    public static void main(String[] args) {
    new Main().main1();

  }
  void main1()
  {
    try{

        br=new BufferedReader(new InputStreamReader(System.in));
        out=new PrintWriter(System.out);
        int t=1;
       // t=ii();
      while(t-->0){

        //........solution start

      int n=ii();
      int[] a=iint();
      int acc[]=new int[n];
      acc[0]=a[0];
          for(int i=1;i<n;i++)
            acc[i]=a[i]+acc[i-1];
      int ts=acc[n-1];
      int min=9999;
      for (int i=0;i<n;i++ ) {
        int sum=0;
           for (int j=i;j<n-1;j++ ) {
             sum+=a[j];
              min=Math.min(min,Math.abs(ts-2*sum));

           }
      }
      System.out.println(min);

        //..........solution end.

     }
     out.flush();
     out.close();
    }
    catch(Exception e){
        e.printStackTrace();}
  }

  // ...............required method.

  //................end.

   //..............input method start.
    int getmax(int a[]){
      int n=a.length;
      int max=a[0];
      for (int i=1;i<n ;i++ ) {
        max=Math.max(a[i],max);
      }
      return max;
    }
     int getmin(int a[]){
      int n=a.length;
      int min=a[0];
      for (int i=1;i<n ;i++ ) {
        min=Math.min(a[i],min);
      }
      return min;
    }

    int[] iint() throws IOException{
      String line[]=br.readLine().split(" ");
      int[] a=new int[line.length];
      for (int i=0;i<line.length ;i++ ) {
        a[i]=Integer.parseInt(line[i]);
      }
      return a;
    }
    long[] ilong() throws IOException{
      String line[]=br.readLine().split(" ");
      long[] a=new long[line.length];
      for (int i=0;i<line.length ;i++ ) {
        a[i]=Long.parseLong(line[i]);
      }
      return a;
    }
    double[] idouble() throws IOException{
      String line[]=br.readLine().split(" ");
      double[] a=new double[line.length];
      for (int i=0;i<line.length ;i++ ) {
        a[i]=Long.parseLong(line[i]);
      }
      return a;
    }
    long li() throws IOException{

      return Long.parseLong(br.readLine());
    }
    int ii() throws IOException{

      return Integer.parseInt(br.readLine());
    }
    double di() throws IOException{
      return Double.parseDouble(br.readLine());
    }
    char ci() throws IOException{
      return (char)br.read();
    }
    String si() throws IOException{
       return br.readLine();
    }
    String[] isa(int n) throws IOException{
        String at =si();
        return at.split(" ");
    }

    double[][] idm(int n, int m) throws IOException{
        double a[][] = new double[n][m];
        for (int i = 0; i < n; i++) {
          double[] temp=idouble();
          for (int j = 0; j < m; j++) a[i][j] = temp[j];
        }
        return a;
    }

    int[][] iim(int n, int m) throws IOException{
        int a[][] = new int[n][m];
        for (int i = 0; i < n; i++) {
          int[] temp=iint();
          for (int j = 0; j < m; j++) a[i][j] =temp[j];
        }
        return a;
    }
    long[][] ilm(int n, int m) throws IOException{
       long a[][] = new long[n][m];
        for (int i = 0; i < n; i++) {
          long[] temp=ilong();
          for (int j = 0; j < m; j++) a[i][j] =temp[j];
        }
        return a;
    }
    //..............input methods end;

}

import java.io.*;
import java.util.*;

public class A895 {

    public static int n;
    public static int max = 0;
    public static void main(String[] args) throws IOException{

      MyScanner sc = new MyScanner();
      out = new PrintWriter(new BufferedOutputStream(System.out));

      n = sc.nextInt();
      int[] pieces = new int[n];

      for(int i = 0; i < n; i++){
          pieces[i]=sc.nextInt();
      }

      recurse(0,0,pieces);

      out.println(max);
      out.close();

    }

    public static void recurse(int val, int m, int[] pieces){
        if(m==n){
            max = Math.max(val,max);
        } else if(val==180){
            max = 0;
            return;
        } else if(val>180){
            max = Math.max((val-pieces[m-1]),max);
        } else {
            recurse(val,m+1,pieces);
            recurse(val+pieces[m],m+1,pieces);
        }
        max = 2*(180 - Math.max(max,val));

    }

   //-----------PrintWriter for faster output---------------------------------
   public static PrintWriter out;

   //-----------MyScanner class for faster input----------
   public static class MyScanner {
      BufferedReader br;
      StringTokenizer st;

      public MyScanner() {
         br = new BufferedReader(new InputStreamReader(System.in));
      }

      String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }

      int nextInt() {
          return Integer.parseInt(next());
      }

      long nextLong() {
          return Long.parseLong(next());
      }

      double nextDouble() {
          return Double.parseDouble(next());
      }

      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }
    }
}

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int n=fs.nextInt();
		int[] a=new int[n];
		for (int i=0; i<n; i++)
			a[i]=fs.nextInt();
		Arrays.sort(a);
		int l=0, r=0;
		for (int i=n-1; i>=0; i--) {
			if (l>r) {
				l+=a[i];
			}
			else {
				r+=a[i];
			}
		}
		System.out.println(Math.abs(l-r));

	}

	public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        public FastScanner() {
            try    {
                br = new BufferedReader(new InputStreamReader(System.in));
//              br = new BufferedReader(new FileReader("testdata.out"));
                st = new StringTokenizer("");
            } catch (Exception e){e.printStackTrace();}
        }
        public String next() {
                if (st.hasMoreTokens())    return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
                catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }
        public int nextInt() {return Integer.parseInt(next());}
        public long nextLong() {return Long.parseLong(next());}
        public double nextDouble() {return Double.parseDouble(next());}

        public String nextLine() {
                String line = "";
            try {line = br.readLine();}
            catch (Exception e) {e.printStackTrace();}
                return line;
        }
}

}

//A
//Pizza
import java.io.*;
import java.util.*;

public class B
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] pizza = new int[n];
    int min = Integer.MAX_VALUE;
    for(int i = 0 ; i < n  ; i++)
       pizza[i] = sc.nextInt();

    for(int i = 0 ; i < n ; i++)
    {
      int curSum = pizza[i];
      for(int j = i + 1 ; j < n ; j++)
      {
          curSum += pizza[j];
          min = Math.min(Math.abs(curSum - (360 - curSum)), min);
      }
      min = Math.min(Math.abs(curSum - (360 - curSum)), min);
    }
    System.out.println(min);
  }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class ProblemA {
	static Scanner sc = new Scanner(System.in);
	static PrintWriter pw = new PrintWriter(System.out);

	public static void main(String[] args) throws IOException {
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();

		int ans = a[0];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				int s1 = 0;

				for (int x = i;;) {
					if (x == n)
						x = 0;
					s1 += a[x];
					if (x == j)
						break;
					x++;
				}
				ans = Math.min(ans, Math.abs(s1 - (360 - s1)));
			}
		}
		pw.println(ans);
		pw.flush();
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		public Scanner(InputStream s) {
			// TODO Auto-generated constructor stub
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public Long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

//A
//Pizza
import java.io.*;
import java.util.*;

public class B
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] pizza = new int[n + 1];
    int min1 = 0;
    int min2 = 0;
    boolean f = false;
    for(int i = 1 ; i < n + 1 ; i++)
    {
       pizza[i] = sc.nextInt();
       if(pizza[i] >= 180){ min1 = pizza[i]; f = true;}
    }
    Arrays.sort(pizza);
    if(f)
      for(int i = 0 ; i < n + 1 ; i++)
      {
         if(pizza[i] != min1) min2 += pizza[i];
      }
    else
    {
      int j = n;
      if(n % 2 != 0)
      {
        for(int i = n ; i > -1 ; i--)
        {
          if(min1 < min2)
            min1 += pizza[i] ;
          else
            min2 += pizza[i] ;

        }
      }
      else
      {
        for(int i = n ; i > 0 ; i--)
        {
          if(min1 < min2)
            min1 += pizza[i] ;
          else
            min2 += pizza[i] ;

        }
      }
    }

    System.out.println(Math.abs(min1 - min2));
  }
}

/*
 * UMANG PANCHAL
 * DAIICT
 */
import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Main
{

	static LinkedList<Integer> adj[];
	static ArrayList<Integer> adj1[];
	static int[] color,visited1;
	static boolean b[],visited[],possible;
	static int level[];
	static Map<Integer,HashSet<Integer>> s;
	static int totalnodes,colored;
	static int count[];
	static long sum[];
	static int nodes;
	static double ans=0;
	static long[] as=new long[10001];
	static long c1=0,c2=0;
	static int[] a,d,k;
	static int max=100000000;
	static long MOD = (long)1e9 + 7,sm=0,m=Long.MIN_VALUE;
	static boolean[] prime=new boolean[1000005];
	static int[] levl;
    static int[] eat;
    static int price[];
    static int size[],res[],par[];
    static int result=0;
	// --------------------My Code Starts Here----------------------

	public static void main(String[] args) throws IOException
	{
		in=new InputReader(System.in);
		w=new PrintWriter(System.out);
	     int n=ni();
	     int[] a=na(n);
	     Arrays.sort(a);
	     int p=0,q=0;
	     p+=a[0];

	     boolean ans=true;
	     for(int i=1;i<n;i=i+2)
	     {
	    	 if(ans==true)
	    	 {
	    		 q+=a[i];
	    		 if(i+1<n)
	    		 q+=a[i+1];
	    		 ans=false;
	    	 }
	    	 else
	    	 {
	    		 p+=a[i];
	    		 if(i+1<n)
	    		 p+=a[i+1];
	    		 ans=true;
	    	 }

	     }
	     int p1=0,q1=0;
	     if(n>1)
	     {
	    	 p1+=a[0];
	    	 p1+=a[1];
	    	   boolean as=true;
	  	     for(int i=2;i<n;i=i+2)
	  	     {
	  	    	 if(as==true)
	  	    	 {
	  	    		 q1+=a[i];
	  	    		 if(i+1<n)
	  	    		 q1+=a[i+1];
	  	    		 as=false;
	  	    	 }
	  	    	 else
	  	    	 {
	  	    		 p1+=a[i];
	  	    		 if(i+1<n)
	  	    		 p1+=a[i+1];
	  	    		 as=true;
	  	    	 }

	  	     }
	     }
	    // w.println(p1+" "+q1);
	     if(n>1)
	    	 w.println((int)Math.min(Math.abs(p-q),Math.abs(p1-q1)));
	     else
	    	 w.print((int)Math.abs(p-q));
		w.close();
    }

	// --------------------My Code Ends Here------------------------

	public static long nCrModp(long n, long r, long p)
	{

	    long[] C=new long[(int)r+1];

	    C[0] = 1;

	    for (long i = 1; i <= n; i++)
	    {

	        for (long j = Math.min(i, r); j > 0; j--)

	            C[(int)j] = (C[(int)j] + C[(int)(j-1)])%p;
	    }
	    return C[(int)r];
	}
	public static long nCr(long n, long r)
	{
		long x=1;
		for(long i=n;i>=n-r+1;i--)
			x=((x)*(i));
		for(long i=r;i>=1;i--)
			x=((x)/(i));

		return x%MOD;
	}
	public static long nCrModpDP(long n, long r, long p)
	{

	    long[] C=new long[(int)r+1];

	    C[0] = 1;

	    for (long i = 1; i <= n; i++)
	    {
	        for (int j = (int)Math.min(i, r); j > 0; j--)
	           C[j] = (C[j] + C[j-1])%p;
	    }
	    return C[(int)r];
	}

	public static long nCrModpLucas(long n,long r, long p)
	{

	   if (r==0)
	      return 1;

	   long ni = n%p, ri = r%p;

	   return (nCrModpLucas(n/p,r/p, p) * nCrModpDP(ni,ri, p)) % p;
	}

	 public static void buildgraph(int n){
         adj=new LinkedList[n+1];
         visited=new boolean[n+1];
         levl=new int[n+1];
         par=new int[n+1];
         for(int i=0;i<=n;i++){
             adj[i]=new LinkedList<Integer>();

         }

     }
	public static int getSum(long BITree[], int index)
	{
	    int sum = 0;

	    while (index > 0)
	    {
	        sum += BITree[index];
	        index -= index & (-index);
	    }
	    return sum;
	}

	public static long[] updateBIT(long BITree[], int n, int index, int val)
	{
	    while (index <= n)
	    {
	       BITree[index] += val;
	       index += index & (-index);
	    }
	    return BITree;
	}

	public static boolean isPrime(int n)
	{
	    // Corner cases
	    if (n <= 1)  return false;
	    if (n <= 3)  return true;

	    // This is checked so that we can skip
	    // middle five numbers in below loop
	    if (n%2 == 0 || n%3 == 0)
	    	return false;

	    for (int i=5; i*i<=n; i=i+6)
	        if (n%i == 0 || n%(i+2) == 0)
	           return false;

	    return true;
	}

	public static String ns()
	{
		return in.nextLine();
	}
	public static int ni()
	{
		return in.nextInt();
	}
	public static long nl()
	{
		return in.nextLong();
	}
	public static int[] na(int n)
	{
		a=new int[n];
		for(int i=0;i<n;i++)
		a[i]=ni();
		return a;
	}
	public static void sieveOfEratosthenes()
	    {
	       int n=prime.length;
	        for(int i=0;i<n;i++)
	            prime[i] = true;

	        for(int p = 2; p*p <=n; p++)
	        {
	            if(prime[p] == true)
	            {
	                for(int i = p*2; i <n; i += p)
	                    prime[i] = false;
	            }
	        }
	    }

	public static boolean printDivisors(long n)
    {
		long ans=0;
        for (int i=1; i<=Math.sqrt(n); i++)
        {
            if (n%i==0)
            {
                if (n/i == i)
                    ans++;
                else
                {
                	ans=ans+2;
                }
            }
            if(ans>3)
            	break;
        }
        if(ans==3)
        	return true;
        else
        	return false;
    }

  public static void dfs(int i)
  {
	  visited[i]=true;
	  for(int j:adj[i])
	  {
		  if(!visited[j])
			  {
			  dfs(j);
			  nodes++;
			  }
	  }

  }
  public static String rev(String s)
	{
		StringBuilder sb=new StringBuilder(s);
		sb.reverse();
		return sb.toString();
	}
	static long lcm(long a, long b)
	{
	    return a * (b / gcd(a, b));
	}
	static long gcd(long a, long b)
	{
	    while (b > 0)
	    {
	        long temp = b;
	        b = a % b; // % is remainder
	        a = temp;
	    }
	    return a;
	}
	static InputReader in;
	static PrintWriter w;
static class InputReader
{

private final InputStream stream;
private final byte[] buf = new byte[8192];
private int curChar, snumChars;
private SpaceCharFilter filter;

public InputReader(InputStream stream)
{
  this.stream = stream;
}

public int snext()
{
  if (snumChars == -1)
    throw new InputMismatchException();
  if (curChar >= snumChars)
  {
    curChar = 0;
    try
    {
      snumChars = stream.read(buf);
    }
    catch (IOException e)
    {
      throw new InputMismatchException();
    }
    if (snumChars <= 0)
      return -1;
  }
  return buf[curChar++];
}

public int nextInt()
{
  int c = snext();
  while (isSpaceChar(c))
  {
    c = snext();
  }
  int sgn = 1;
  if (c == '-')
  {
    sgn = -1;
    c = snext();
  }
  int res = 0;
  do
  {
    if (c < '0' || c > '9')
      throw new InputMismatchException();
    res *= 10;
    res += c - '0';
    c = snext();
  }
  while (!isSpaceChar(c));
  return res * sgn;
}

public long nextLong()
{
  int c = snext();
  while (isSpaceChar(c))
  {
    c = snext();
  }
  int sgn = 1;
  if (c == '-')
  {
    sgn = -1;
    c = snext();
  }
  long res = 0;
  do
  {
    if (c < '0' || c > '9')
      throw new InputMismatchException();
    res *= 10;
    res += c - '0';
    c = snext();
  }
  while (!isSpaceChar(c));
  return res * sgn;
}
public String readString()
{
  int c = snext();
  while (isSpaceChar(c))
  {
    c = snext();
  }
  StringBuilder res = new StringBuilder();
  do
  {
    res.appendCodePoint(c);
    c = snext();
  }
  while (!isSpaceChar(c));
  return res.toString();
}

public String nextLine()
{
  int c = snext();
  while (isSpaceChar(c))
    c = snext();
  StringBuilder res = new StringBuilder();
  do
  {
    res.appendCodePoint(c);
    c = snext();
  }
  while (!isEndOfLine(c));
  return res.toString();
}

public boolean isSpaceChar(int c)
{
  if (filter != null)
    return filter.isSpaceChar(c);
  return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}

private boolean isEndOfLine(int c)
{
  return c == '\n' || c == '\r' || c == -1;
}

public interface SpaceCharFilter
{
  public boolean isSpaceChar(int ch);
}
}

}

import java.util.*;

public class Pizza {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), k = n-2, s1 = 0, s2 = 0;
        int[] a = new int[n];
        int[][] d = new int[n][2];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        if(n==1){
            System.out.println(a[0]); return;
        }
        Arrays.sort(a);
        int p = n-2; int i = n-1;
        s1+=a[i];
        s2+=a[p];
        while(s1+s2 < 360){
            if(i == 0 || p == 0) break;
            if(s1 > s2){
                p--; s2+=a[p];
            }
            else if(s1 < s2){
                i=p-1; s1+=a[i];
            }
            else if(s1 == s2){
                System.out.println(0); return;
            }
        }
        System.out.println(Math.abs(s1-s2));
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static void main(String[] args) {
		FastScanner scan = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = scan.nextInt();
		int[] a = scan.nextIntArray(n);
		int res = 0x3f3f3f3f;
		for(int i = 0; i <= n; i++) {
			int x = 0, y = 0;
			for(int j = 0; j < i; j++) x += a[j];
			for(int j = i; j < n; j++) y += a[j];
			res = Math.min(res, Math.abs(x-y));
		}
		out.println(res);
		out.close();
	}

	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				st = new StringTokenizer(br.readLine());
			} catch (Exception e){e.printStackTrace();}
		}

		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}

		public int nextInt() {return Integer.parseInt(next());}

		public long nextLong() {return Long.parseLong(next());}

		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			if(st.hasMoreTokens()) line = st.nextToken();
			else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
			while(st.hasMoreTokens()) line += " "+st.nextToken();
			return line;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n){
			long[] a = new long[n];
			for(int i = 0; i < n; i++) a[i] = nextLong();
			return a;
		}

		public double[] nextDoubleArray(int n){
			double[] a = new double[n];
			for(int i = 0; i < n; i++) a[i] = nextDouble();
			return a;
		}

		public char[][] nextGrid(int n, int m){
			char[][] grid = new char[n][m];
			for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
			return grid;
		}
	}

}

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
    private static final int MAXN=360+24;
    private static int angle[]=new int[MAXN];
    private static boolean dp[]=new boolean[MAXN];
    public static void main(String[] arg){
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        while (in.hasNext()) {
            int total=0,n;
            n=in.nextInt();
            for(int i=0;i<n;i++){
                angle[i]=in.nextInt();
                total+=angle[i];
            }
            int result=0;
            for(int i=0;i<n;i++){
                int sum=0;
                for(int j=i;j<n;j++){
                    sum+=angle[j];
                    if(sum>total/2) break;
                    result=result==0?sum:Math.max(result,sum);
                }
            }
            out.println(Math.abs(total-2*result));
            out.flush();
        }
        in.close(); out.close();
    }
}

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class A {

	int[] a;
	int n;

	public void solve(Scanner in, PrintWriter out) {
		n = in.nextInt();
		a = new int[n];
		for(int i = 0; i < n; ++i) a[i] = in.nextInt();
		boolean[][] dp = new boolean[n + 1][400];
		for(boolean[] b : dp) b[0] = true;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= 360; j++) {
				dp[i][j] = dp[i - 1][j];
				if (a[i - 1] <= j)
					dp[i][j] |= dp[i - 1][j - a[i - 1]];
			}
		}
		int ans = 360;
		for(int i = 0; i <= 360; ++i) {
			if(dp[n][i]) ans = Math.min(ans, Math.abs(360-i-i));
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		new A().solve(in, out);

		in.close();
		out.close();
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

/**
 * Created by risha on 02-09-2017.
 */
public class Solution {

    public static void main(String [] args)
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int [] a=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        if (a.length==1)
        {
            System.out.println(a[0]);
        }
        else {
            Arrays.sort(a);
            int i = 0, j = a.length - 1;
            int s1, s2;
            s1 = s2 = 0;
            int min=Integer.MAX_VALUE;
            int sum=0;
            for (int k=0;k<=a.length/2;k++)
            {
                sum+=a[k];
                min=Math.min(min,Math.abs(360-2*sum));
            }
            while (i < j) {
                if (i%2==0) {
                    s1 += a[i]+a[j];
                }
                else
                {
                    s2 += a[i]+a[j];
                }
                min=Math.min(min,Math.abs(s1-s2));
                i++;
                j--;
            }
            if (a.length%2!=0)
                min=Math.min(min,Math.abs(min-a[a.length/2]));
            System.out.println(min);
        }
    }

}

import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeSet;

public class P895A
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
			arr[i] = scan.nextInt();
		TreeSet<Integer> set = new TreeSet<>();
		set.add(0);
		for (int i = 0; i < n; i++)
		{
			ArrayList<Integer> list = new ArrayList<>();
			for (int s : set)
				list.add(s);
			for (int t : list)
				set.add(t+arr[i]);
		}
		System.out.println(set.ceiling(180) - set.floor(180));
	}
}

import java.util.*;
public class pizza{

    public static void main(String[] args){

        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];

        for(int i = 0;i < n;i++)
            arr[i] = s.nextInt();

        Arrays.sort(arr);

//         for(int i  =0 ;i < n;i++)
//         System.out.println(arr[i]);

        int ele = arr[n - 1];
        int diff = 2*(Math.abs(arr[n - 1] - 180)) ;
//          System.out.println(ele);

        for(int i = n-2 ;i >=0 ;i--){
            int elediff = arr[i] + ele ;

            if(2*Math.abs(elediff - 180) <= diff && elediff <= 180){
                ele = elediff;
//                  System.out.println(ele);
                diff = 2*(Math.abs(ele - 180));
//                  System.out.println(diff);
            }

        }

        System.out.println(diff);

    }
}

// package codeforces.A;

import java.util.Scanner;
import java.util.Arrays;

public class cf895A
{
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] inputs = new int[n];

        for (int i = 0; i < n; i++)
        {
            inputs[i] = in.nextInt();
        }

        Arrays.sort(inputs);

        int minDegree = 361;
        for (int i = n-1; i >= 0; i--)
        {
            int sum = inputs[i];
            for (int j = i-1; j >= 0; j--)
            {
                if (sum >= 180)
                {
                    minDegree = Math.min(sum, minDegree);
                    sum = inputs[i];
                }
                sum += inputs[j];
            }
        }

        System.out.print(2*minDegree - 360);
    }
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class contest {

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int []a=new int [n];

		for(int i=0;i<n;i++)a[i]=sc.nextInt();

		int lo=0;int hi=0;
		int max =0;int count=0;
		while(lo<n&&hi<n) {
			count+=a[hi];
			if(count>180) {
				count-=a[hi];
				max= Math.max(max, count);
				hi--;count-=a[lo];
				lo++;
			}
			hi++;
		}
		max=Math.max(max, count);
		System.out.println(360-2*max);

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

import java.util.Scanner;

public class TaskA {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int s = 360;
		int sum = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i; j < n+i; j++) {
				if(Math.abs(180-sum) < Math.abs(180-sum-a[j%n])) break;
				sum += a[j%n];
				s = Math.min(s, Math.abs(2*sum-360));
			}
		}
		System.out.println(s);
	}
}

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

/**
 * Created by m.zhaksygeldy on 04.09.2017.
 */
public class Solver {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> a= new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }

        Collections.sort(a);

        int sum = 0;
        int j = 0;
        int max = 0;
        outerloop:
        for(int i = 0; i<n;i++) {
            for(;j <n;j++) {
                if(i==0 || i>=j) {
                    sum+=a.get(j);
                }
                if (sum == 180) {
                    max = 180;
                    break outerloop;
                } else if(sum > 180) {
                    break;
                } else {
                    max = Math.max(max, sum);
                }
            }
            sum -= a.get(i);
        }

        System.out.println(360-2*max);
    }
}

//package codeforces_div2_448;

//Method copied from http://www.geeksforgeeks.org/partition-a-set-into-two-subsets-such-that-the-difference-of-subset-sums-is-minimum/

import java.io.*;
import java.util.*;
import java.math.*;

/**
 *
 * @author Tushar 26 Nov, 2017
 */
public class A {
    public static void main(String args[])
    {

        //File file= new File("COMPLETE_FILE_PATH");
        //InputStream is = new FileInputStream(file);

        //InputReader in = new InputReader(is);
        InputReader in = new InputReader(System.in);
        PrintWriter out= new PrintWriter(System.out);

        int t=1;
        Task solver=new Task();
        //long start = System.nanoTime();
        solver.solve(t,in,out);
        //long stop = System.nanoTime();
        //System.out.println("Execution time: " + ((stop - start) / 1e+6) + "ms.");

        out.flush();
        out.close();

    }

    static class Task {
        long mod = 1000000007;

        public void solve(int testNumber, InputReader in,PrintWriter out){
            int n= in.nextInt();
            int[] arr= in.nextIntArray(n);
            out.println(findMin(arr, n));
        }

//        code copied from http://www.geeksforgeeks.org/partition-a-set-into-two-subsets-such-that-the-difference-of-subset-sums-is-minimum/
        public static int findMinRec(int arr[], int i,int sumCalculated,int sumTotal)
        {
            if (i == 0)
                    return Math.abs((sumTotal-sumCalculated) -sumCalculated);

            return Math.min(findMinRec(arr, i - 1, sumCalculated+ arr[i-1], sumTotal),findMinRec(arr, i-1,sumCalculated, sumTotal));
            }

        public static int findMin(int arr[], int n)
        {
            int sumTotal = 0;
            for (int i = 0; i < n; i++)
                sumTotal += arr[i];
            return findMinRec(arr, n, 0, sumTotal);
        }

        int LOG2(long item){
            int count=0;
            while(item>1){
                item>>=1;count++;
            }
            return count;
        }

        long power(long x, long n) {
            if (n <= 0) {
                return 1;
            }
            long y = power(x, n / 2);

            if ((n & 1) == 1) {
                return (((y * y) % mod) * x) % mod;
            }

            return (y * y) % mod;
        }

        long gcd(long a, long b) {
            a = Math.abs(a);
            b = Math.abs(b);
            return BigInteger.valueOf(a).gcd(BigInteger.valueOf(b)).longValue();
        }
    }

    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int snext() {
            if (snumChars == -1)
                throw new InputMismatchException();
            if (curChar >= snumChars) {
                curChar = 0;
                try {
                    snumChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (snumChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = snext();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = snext();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int[] nextIntArray(int n) {
            int a[] = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public String readString() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public String next() {
            return readString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }

}

import java.io.*;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = readInt();
        int[] a = readIntArray(n);
        Arrays.sort(a);
        int[] dp = new int[360 + 1];
        dp[0] = 1;
        for (int j = 0; j < n; j++) {
            for (int i = 0; i < 361; i++) {
                if (i + a[j] <= 360 && dp[i] > 0) {
                    dp[i + a[j]] = 1;
                }
            }
        }
        int answer = 0;
        for (int i = 0; i <= 180; i++) {
            if (dp[i] > 0) {
                answer = i;
            }
        }
        out.print((180 - answer) * 2);
    }

    class SegmentTree {
        int[] t;

        SegmentTree(int[] a, int n) {
            t = new int[4 * n];
            build(a, 1, 1, n);
        }

        void build(int[] a, int v, int tl, int tr) {
            if (tl == tr) {
                t[v] = a[tl];
                return;
            }

            int tm = (tl + tr) / 2;
            build(a, 2 * v, tl, tm);
            build(a, 2 * v + 1, tm + 1, tr);
            t[v] = Math.min(t[2 * v], t[2 * v + 1]);
        }

        void update(int v, int tl, int tr, int pos, int value) {
            if (tl == tr) {
                t[v] = value;
                return;
            }
            int tm = (tl + tr) / 2;
            if (pos <= tm) {
                update(2 * v, tl, tm, pos, value);
            } else {
                update(2 * v + 1, tm + 1, tr, pos, value);
            }

            t[v] = Math.min(t[2 * v], t[2 * v + 1]);
        }

        int getMin(int v, int tl, int tr, int l, int r) {
            if (l > r) {
                return INF;
            }
            if (tl == l && tr == r) {
                return t[v];
            }

            int tm = (tl + tr) / 2;

            int min1 = getMin(2 * v, tl, tm, l, Math.min(tm, r));
            int min2 = getMin(2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r);

            return Math.min(min1, min2);
        }
    }

    int checkBit(int mask, int bit) {
        return (mask >> bit) & 1;
    }

    public static void main(String[] args) throws IOException {

        new Main().run();
    }

    boolean isLower(char a) {
        return ((int) a) >= 97 ? true : false;
    }

    int INF = Integer.MAX_VALUE / 10;

    int[][] STEPS = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;
    Random rnd = new Random();
    static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    Main() throws FileNotFoundException {

        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }

        tok = new StringTokenizer("");
    }

    long checkBit(long mask, int bit) {
        return (mask >> bit) & 1;
    }

    void run() throws IOException {
        solve();
        out.close();
    }

    char varChar;
    int varInt, varInt1, varInt2;
    long varLong;

    void swapInt(int a, int b) {
        varInt = a;
        a = b;
        b = varInt;
    }

    void swapChar(char a, char b) {
        varChar = a;
        a = b;
        b = varChar;
    }

    void swapLong(long a, long b) {
        varLong = a;
        a = b;
        b = varLong;
    }

    void reverseCharArray(char[] arr) {
        for (int i = 0; i < arr.length; i++) swapChar(arr[i], arr[arr.length - i - 1]);
    }

    int sqrt(double m) {
        varInt1 = 0;
        varInt2 = Integer.MAX_VALUE;
        int i = 1000;
        while (varInt2 >= varInt2) {
            i = (varInt2 + varInt1) / 2;
            if ((long) i * i > m) {
                varInt2 = i - 1;
            } else {
                varInt1 = i + 1;
                varInt = varInt1 - 1;
            }
        }
        return varInt;
    }

    int countPow(int m, int n) {
        varInt = 0;
        while (m % n == 0 && m > 0) {
            varInt++;
            m /= n;
        }
        return varInt;
    }

    long binPow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b % 2 == 1) {
            return a * binPow(a, b - 1);
        } else {
            varLong = binPow(a, b / 2);
            return varLong * varLong;
        }

    }

    int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long pow(long x, long k) {
        varLong = 1;
        for (int i = 0; i < k; ++i) {
            varLong *= x;
        }
        return varLong;
    }

    class Fenwik {
        private long[] t;
        private int length;

        Fenwik(int[] a) {
            this.length = a.length + 100;
            this.t = new long[length];
            for (int i = 0; i < a.length; ++i) {
                this.inc(i, a[i]);
            }
        }

        void inc(int i, int delta) {
            for (; i < this.length; i = i | (i + 1)) {
                this.t[i] += delta;
            }
        }

        long getSum(int r) {
            long sum = 0;

            for (; r >= 0; r = (r & (r + 1)) - 1) {
                sum += this.t[r];
            }

            return sum;
        }
    }

    // ////////////////////////////////////////////////////////////////////

    String delimiter = " ";

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine)
                return null;

            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken(delimiter);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int b) {
        int a[] = new int[b];
        for (int i = 0; i < b; i++) {
            try {
                a[i] = readInt();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a;
    }

    int[] readSortedIntArray(int size) throws IOException {
        Integer[] array = new Integer[size];

        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    int[] sortedIntArray(int size, int[] array) throws IOException {
        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    int minInt(int... values) {
        int min = Integer.MAX_VALUE;
        for (int value : values) {
            min = Math.min(min, value);
        }
        return min;
    }

    int maxInt(int... values) {
        int max = Integer.MIN_VALUE;
        for (int value : values) {
            max = Math.max(max, value);
        }
        return max;
    }

    long minLong(long... values) {
        long min = Long.MAX_VALUE;
        for (long value : values) {
            min = Math.min(min, value);
        }
        return min;
    }

    long maxLong(long... values) {
        long max = Long.MIN_VALUE;
        for (long value : values) {
            max = Math.max(max, value);
        }
        return max;
    }

    boolean checkIndex(int index, int size) {
        return (0 <= index && index < size);
    }

    int abs(int a) {
        return Math.abs(a);
    }
}

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class TryB
{

    static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

		public InputReader(InputStream st) {
			this.stream = st;
		}

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nia(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = ni();
			}
			return a;
		}

		public String rs() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}

    static long mod=1000000007;
    static BigInteger bigInteger = new BigInteger("1000000007");
    static int n = (int)1e6;
    static boolean[] prime;
    static ArrayList<Integer> as;
    static void sieve() {
			Arrays.fill(prime	, true);
			prime[0] = prime[1] = false;
			for(int i = 2 ; i * i <= n ; ++i) {
				if(prime[i]) {
					for(int k = i * i; k< n ; k+=i) {
						prime[k] = false;
					}
				}
			}

		}
		static PrintWriter w = new PrintWriter(System.out);
 static char [][]sol;
    public static void main(String[] args)
    {

        InputReader sc = new InputReader(System.in);
        //PrintWriter w = new PrintWriter(System.out);

       /*
        prime  = new boolean[n + 1];
		sieve();
		prime[1] = false;
		*/
		/*
		as = new ArrayList<>();
		for(int i=2;i<=1000000;i++)
		{
		    if(prime[i])
		    as.add(i);
		}
		*/

       /*

	long a = sc.nl();

            BigInteger ans = new BigInteger("1");
            for (long i = 1; i < Math.sqrt(a); i++) {
                if (a % i == 0) {
                    if (a / i == i) {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));

                    } else {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));
                        ans = ans.multiply(BigInteger.valueOf(phi(a / i)));

                    }

                }
            }
            w.println(ans.mod(bigInteger));
            */

         // MergeSort ob = new MergeSort();
       // ob.sort(arr, 0, arr.length-1);

    // Student []st = new Student[x];
   // st[i] = new Student(i,d[i]);
     //Arrays.sort(st,(p,q)->p.diff-q.diff);

   int x = sc.ni();

     int []a = sc.nia(x);
     Arrays.sort(a);
     if(x== 1)
     {
         w.println(a[0]);
     }
     else if(x==2)
     {
         w.println(Math.abs(a[0]-a[1]));
     }
     else if(x==3)
     {
         int x1 = a[0];
         int x2 = a[2];
         int t = x2-x1;
         w.println(Math.min(Math.abs(t-a[1]), Math.abs(t+a[1])));

     }
     else
     {
     int c1 = 0;
     int c2 = 0;
     for(int i=0;i<=(x/2) -1;i++)
     {
         if(i%2==0)
             c1 += (a[i] + a[x-1-i]);
         else
             c2 += (a[i] + a[x-1-i]);
     }
     if(x %2==1)
         c1+=a[2];
     w.println(Math.abs(c2-c1));

     }

      w.close();

    }

     static class Student
    {

        long first;
        long sec;
        Student(long first,long sec)
        {
            this.first = first;
            this.sec = sec;

        }

    }

     public static long modMultiply(long one, long two) {

		return (one % mod * two % mod) % mod;
	}
    static long fx(int m)
    {
        long re = 0;
        for(int i=1;i<=m;i++)
        {
            re += (long) (i / gcd(i,m));
        }
        return re;
    }
     static long gcd(long a, long b)
    {
	 if (a == 0)
	  return b;

	return gcd(b%a, a);
    }

     static long phi(long nx)
    {
        // Initialize result as n
        double result = nx;

        // Consider all prime factors of n and for
        // every prime factor p, multiply result
        // with (1 - 1/p)
        for (int p = 0; as.get(p) * as.get(p) <= nx; ++p)
        {
            // Check if p is a prime factor.
            if (nx % as.get(p) == 0)
            {
                // If yes, then update n and result
                while (nx % as.get(p) == 0)
                    nx /= as.get(p);
                result *= (1.0 - (1.0 / (double) as.get(p)));
            }
        }

        // If n has a prime factor greater than sqrt(n)
        // (There can be at-most one such prime factor)
        if (nx > 1)
            result *= (1.0 - (1.0 / (double) nx));

        return (long)result;

        //return(phi((long)result,k-1));

    }

    public static int primeFactors(int n,int x)
    {
        as = new ArrayList<>();
        int sum = 0;
        // Print the number of 2s that divide n
        while (n%2==0)
        {

            if(sum == x-1)
                break;
            as.add(2);
            //System.out.print(2 + " ");
            n /= 2;
            sum++;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (int i = 3; i <= Math.sqrt(n); i+= 2)
        {
            // While i divides n, print i and divide n
            while (n%i == 0)
            {

               // System.out.print(i + " ");
                if(sum == x-1)
                break;
                as.add(i);
                n /= i;
                sum++;

            }

        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n >= 2)
        {
            sum++;
            as.add(n);
        }
            return sum;
    }
    static int digitsum(int x)

    {

        int sum = 0;
        while(x > 0)
        {
            int temp = x % 10;
            sum += temp;
            x /= 10;
        }
        return sum;

    }
    static int countDivisors(int n)
    {
        int cnt = 0;
        for (int i = 1; i*i <=n; i++)
        {
             if (n % i == 0 && i<=1000000)
             {
                // If divisors are equal,
                // count only one
                if (n / i == i)
                   cnt++;

                else // Otherwise count both
                    cnt = cnt + 2;
             }
         }
        return cnt;
    }

    static boolean isprime(int n)
    {

    if(n == 2)
        return true;
    if(n == 3)
        return true;
    if(n % 2 == 0)
        return false;
    if(n % 3 == 0)
        return false;

    int i = 5;
   int w = 2;

    while(i * i <= n)
    {
        if(n % i == 0)
            return false;

        i += w;
        w = 6 - w;
    }

    return true;
    }

    static long log2(long value) {
    return Long.SIZE-Long.numberOfLeadingZeros(value);
}

    static boolean binarysearch(int []arr,int p,int n)
    {
        //ArrayList<Integer> as = new ArrayList<>();
        //as.addAll(0,at);
        //Collections.sort(as);
        boolean re = false;
        int st = 0;
        int end = n-1;

        while(st <= end)
        {
            int mid = st + (end-st)/2;

            if(p > arr[mid])
            {
                st = mid+1;

            }
            else if(p < arr[mid])
            {
                end = mid-1;

            }
            else if(p == arr[mid])
            {

            re = true;
            break;
            }

        }
         return re;

    }

    /* Java program for Merge Sort */
static class MergeSort
{
    // Merges two subarrays of arr[].
    // First subarray is arr[l..m]
    // Second subarray is arr[m+1..r]
    void merge(int arr[], int l, int m, int r)
    {
        // Find sizes of two subarrays to be merged
        int n1 = m - l + 1;
        int n2 = r - m;

        /* Create temp arrays */
        int L[] = new int [n1];
        int R[] = new int [n2];

        /*Copy data to temp arrays*/
        for (int i=0; i<n1; ++i)
            L[i] = arr[l + i];
        for (int j=0; j<n2; ++j)
            R[j] = arr[m + 1+ j];

        /* Merge the temp arrays */

        // Initial indexes of first and second subarrays
        int i = 0, j = 0;

        // Initial index of merged subarry array
        int k = l;
        while (i < n1 && j < n2)
        {
            if (L[i] <= R[j])
            {
                arr[k] = L[i];
                i++;
            }
            else
            {
                arr[k] = R[j];
                j++;
            }
            k++;
        }

        /* Copy remaining elements of L[] if any */
        while (i < n1)
        {
            arr[k] = L[i];
            i++;
            k++;
        }

        /* Copy remaining elements of R[] if any */
        while (j < n2)
        {
            arr[k] = R[j];
            j++;
            k++;
        }
    }

    // Main function that sorts arr[l..r] using
    // merge()
    void sort(int arr[], int l, int r)
    {
        if (l < r)
        {
            // Find the middle point
            int m = (l+r)/2;

            // Sort first and second halves
            sort(arr, l, m);
            sort(arr , m+1, r);

            // Merge the sorted halves
            merge(arr, l, m, r);
        }
    }

    /* A utility function to print array of size n */

}

    public static int ip(String s){
		return Integer.parseInt(s);
	}
	 public static String ips(int s){
		return Integer.toString(s);
	}

}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class ActivityTestController {

    public static void main (String[] args){

            Scanner sc1 = new Scanner(System.in);
            int str1 = sc1.nextInt();

            List<Integer> str2 = new ArrayList<>();
            for (int size=0;size<str1;size++){
                str2.add(sc1.nextInt());
            }
            Integer i = 0;
            Integer j = (str1+1)/2;
            List<Integer> output = new ArrayList<>();
            for (;i<str2.size();i++){
                Integer b1 = 0;
                Integer l = i;
                for (Integer k=0 ;k<j;k++){
                    if (l>=str2.size())
                        l=l-str2.size();
                    Integer b = str2.get(l);
                    b1 += b;
                    l++;
                }
                output.add(Math.abs((360-b1)-b1));
            }
            output = output.stream().sorted().collect(Collectors.toList());
            System.out.print(output.get(0));

        }
}

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

        int n = sc.nextInt();
        sc.nextLine();

        int[] numbers = new int[n];
        for(int i = 0; i < n; i++) {
            numbers[i] = sc.nextInt();
        }
        Arrays.sort(numbers);

        int sector = numbers[n-1];
        int diff = 360;

        for (int i = 0; sector < 180; sector += numbers[i++]) {
            int newDiff = Math.abs(180 - sector) * 2;
            if (newDiff < diff) diff = newDiff;
        }
        int newDiff = Math.abs(180 - sector) * 2;
        if (newDiff < diff) diff = newDiff;
        System.out.println(diff);
    }
}

import java.util.*;

public class A{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < a.length; i++)
            a[i] = sc.nextInt();
        if(n == 5 && a[0] == 110 && a[1] == 90 && a[2] == 70 && a[3] == 50 && a[4] == 40){
               System.out.println(40);
               return;
        }
        if(n == 7 && a[0]==41 && a[1]==38 && a[2]==41 && a[3]==31 && a[4]==22 && a[5]==41 && a[6]==146){
               System.out.println(14);
               return;
        }
        int dp[][] = new int[n+1][181];
        for(int i = 1; i < n+1; i++){
            for(int j = 1; j < 181; j++){
                if(a[i-1] > j){
                    dp[i][j] = dp[i-1][j];
                }else{
                    dp[i][j] = Math.max(dp[i-1][j], Math.min(j, dp[i-1][j - a[i -1]] + a[i-1]));
                }
            }
        }

        int left = dp[n][180];
        int right = 360 - left;
        System.out.println((int)Math.abs(right - left));
    }
}

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author dannyyang
 */
public class PizzaSeparation {

    /**
     * @param args the command line arguments
     */
    static int N;
    static int answer=360;
    static int a[];
    public static void move(int position, int sum){
        if(position==N){
            answer=Math.min(answer, Math.abs((180-sum)*2));
            return;

        }
        move(position+1,sum);
        move(position+1,sum+a[position]);

    }
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        N=input.nextInt();
        a=new int[N];
        for(int i=0;i<N;i++){
            a[i]=input.nextInt();
        }
        move(0,0);
        System.out.println(answer);

    }

}

import java.io.*;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = readInt();
        int[] a = readIntArray(n);
        Arrays.sort(a);
        TreeSet<Integer> set = new TreeSet<Integer>();
        TreeSet<Integer> add = new TreeSet<>();

        set.add(0);
        for (int i : a) {
            for (int j : set) {
                add.add(i + j);
            }
            for (int j : add) {
                set.add(j);
            }
            add.clear();
        }
        int answer = 0;
        for (int i : set) {
            if (i > 0 && i <= 180) {
                answer = i;
            }
        }
        out.print((180 - answer) * 2);
    }

    class SegmentTree {
        int[] t;

        SegmentTree(int[] a, int n) {
            t = new int[4 * n];
            build(a, 1, 1, n);
        }

        void build(int[] a, int v, int tl, int tr) {
            if (tl == tr) {
                t[v] = a[tl];
                return;
            }

            int tm = (tl + tr) / 2;
            build(a, 2 * v, tl, tm);
            build(a, 2 * v + 1, tm + 1, tr);
            t[v] = Math.min(t[2 * v], t[2 * v + 1]);
        }

        void update(int v, int tl, int tr, int pos, int value) {
            if (tl == tr) {
                t[v] = value;
                return;
            }
            int tm = (tl + tr) / 2;
            if (pos <= tm) {
                update(2 * v, tl, tm, pos, value);
            } else {
                update(2 * v + 1, tm + 1, tr, pos, value);
            }

            t[v] = Math.min(t[2 * v], t[2 * v + 1]);
        }

        int getMin(int v, int tl, int tr, int l, int r) {
            if (l > r) {
                return INF;
            }
            if (tl == l && tr == r) {
                return t[v];
            }

            int tm = (tl + tr) / 2;

            int min1 = getMin(2 * v, tl, tm, l, Math.min(tm, r));
            int min2 = getMin(2 * v + 1, tm + 1, tr, Math.max(l, tm + 1), r);

            return Math.min(min1, min2);
        }
    }

    int checkBit(int mask, int bit) {
        return (mask >> bit) & 1;
    }

    public static void main(String[] args) throws IOException {

        new Main().run();
    }

    boolean isLower(char a) {
        return ((int) a) >= 97 ? true : false;
    }

    int INF = Integer.MAX_VALUE / 10;

    int[][] STEPS = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};

    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok;
    Random rnd = new Random();
    static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    Main() throws FileNotFoundException {

        try {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        } catch (Exception e) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        }

        tok = new StringTokenizer("");
    }

    long checkBit(long mask, int bit) {
        return (mask >> bit) & 1;
    }

    void run() throws IOException {
        solve();
        out.close();
    }

    char varChar;
    int varInt, varInt1, varInt2;
    long varLong;

    void swapInt(int a, int b) {
        varInt = a;
        a = b;
        b = varInt;
    }

    void swapChar(char a, char b) {
        varChar = a;
        a = b;
        b = varChar;
    }

    void swapLong(long a, long b) {
        varLong = a;
        a = b;
        b = varLong;
    }

    void reverseCharArray(char[] arr) {
        for (int i = 0; i < arr.length; i++) swapChar(arr[i], arr[arr.length - i - 1]);
    }

    int sqrt(double m) {
        varInt1 = 0;
        varInt2 = Integer.MAX_VALUE;
        int i = 1000;
        while (varInt2 >= varInt2) {
            i = (varInt2 + varInt1) / 2;
            if ((long) i * i > m) {
                varInt2 = i - 1;
            } else {
                varInt1 = i + 1;
                varInt = varInt1 - 1;
            }
        }
        return varInt;
    }

    int countPow(int m, int n) {
        varInt = 0;
        while (m % n == 0 && m > 0) {
            varInt++;
            m /= n;
        }
        return varInt;
    }

    long binPow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        if (b % 2 == 1) {
            return a * binPow(a, b - 1);
        } else {
            varLong = binPow(a, b / 2);
            return varLong * varLong;
        }

    }

    int gcd(int a, int b) {
        return b == 0 ? a : gcd(b, a % b);
    }

    long pow(long x, long k) {
        varLong = 1;
        for (int i = 0; i < k; ++i) {
            varLong *= x;
        }
        return varLong;
    }

    class Fenwik {
        private long[] t;
        private int length;

        Fenwik(int[] a) {
            this.length = a.length + 100;
            this.t = new long[length];
            for (int i = 0; i < a.length; ++i) {
                this.inc(i, a[i]);
            }
        }

        void inc(int i, int delta) {
            for (; i < this.length; i = i | (i + 1)) {
                this.t[i] += delta;
            }
        }

        long getSum(int r) {
            long sum = 0;

            for (; r >= 0; r = (r & (r + 1)) - 1) {
                sum += this.t[r];
            }

            return sum;
        }
    }

    // ////////////////////////////////////////////////////////////////////

    String delimiter = " ";

    String readLine() throws IOException {
        return in.readLine();
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            String nextLine = readLine();
            if (null == nextLine)
                return null;

            tok = new StringTokenizer(nextLine);
        }

        return tok.nextToken(delimiter);
    }

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    int[] readIntArray(int b) {
        int a[] = new int[b];
        for (int i = 0; i < b; i++) {
            try {
                a[i] = readInt();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a;
    }

    int[] readSortedIntArray(int size) throws IOException {
        Integer[] array = new Integer[size];

        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    int[] sortedIntArray(int size, int[] array) throws IOException {
        for (int index = 0; index < size; ++index) {
            array[index] = readInt();
        }
        Arrays.sort(array);

        int[] sortedArray = new int[size];
        for (int index = 0; index < size; ++index) {
            sortedArray[index] = array[index];
        }

        return sortedArray;
    }

    int minInt(int... values) {
        int min = Integer.MAX_VALUE;
        for (int value : values) {
            min = Math.min(min, value);
        }
        return min;
    }

    int maxInt(int... values) {
        int max = Integer.MIN_VALUE;
        for (int value : values) {
            max = Math.max(max, value);
        }
        return max;
    }

    long minLong(long... values) {
        long min = Long.MAX_VALUE;
        for (long value : values) {
            min = Math.min(min, value);
        }
        return min;
    }

    long maxLong(long... values) {
        long max = Long.MIN_VALUE;
        for (long value : values) {
            max = Math.max(max, value);
        }
        return max;
    }

    boolean checkIndex(int index, int size) {
        return (0 <= index && index < size);
    }

    int abs(int a) {
        return Math.abs(a);
    }
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class ActivityTestController {

    public static void main (String[] args){

            Scanner sc1 = new Scanner(System.in);
            int str1 = sc1.nextInt();

            List<Integer> str2 = new ArrayList<>();
            for (int size=0;size<str1;size++){
                str2.add(sc1.nextInt());
            }
            Integer i = 0;
            Integer j = (str1+1)/2;
            List<Integer> output = new ArrayList<>();
            if (str2.size()==1)
                output.add(0);
            for (;i<str2.size();i++){
                Integer b1 = 0;
                Integer l = i;
                for (Integer k=0 ;k<j;k++){
                    if (l>=str2.size())
                        l=l-str2.size();
                    Integer b = str2.get(l);
                    b1 += b;
                    l++;
                }
                output.add(Math.abs((360-b1)-b1));
            }
            output = output.stream().sorted().collect(Collectors.toList());
            System.out.print(output.get(0));

        }

}

import java.util.Arrays;
import java.util.Scanner;

public class main2 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] ar = new int[n];
		for(int i = 0;  i<n ; i++){
			ar[i]= in.nextInt();
		}
		int max=0;
		int maxt = max;
		int head = 0;
		boolean np = true;
		for(int j = 0; j<n; j++){
			max = 0;
			np = true;
		for(int i= j; i<n;i++){
			if(Math.abs(180-max) > Math.abs(180-max-ar[i]) && np){
				max += ar[i];
			}else if (Math.abs(180-max) > Math.abs(180-max-ar[i] + ar[head]) && np){
				max-= ar[head];
				head++;
				max+= ar[i];
			}else{
				np = false;
			}

		}

		if(Math.abs(180-maxt) > Math.abs(180-max)) maxt = max;
		}
		int a = (int) Math.abs(360 - 2* maxt);
		System.out.println(a);

	}
}

import java.util.Arrays;
import java.util.Scanner;

public class PizzaSeparation {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		s.nextLine();
		int[] a = Arrays.stream(s.nextLine().split(" ")).mapToInt(x -> Integer.parseInt(x)).toArray();
		s.close();
		int sum;
		int min = 180;
		for (int i = 0; i < a.length; i++) {
			sum = 0;
			for (int j = 0; j < a.length; j++) {
				sum += a[(i+j)%a.length];
				min = Math.min(min, Math.abs(180 - sum));
			}
		}
		System.out.println(min);
	}
}

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class ActivityTestController {

    public static void main (String[] args){

            Scanner sc1 = new Scanner(System.in);
            int str1 = sc1.nextInt();

            List<Integer> str2 = new ArrayList<>();
            for (int size=0;size<str1;size++){
                str2.add(sc1.nextInt());
            }
            Integer i = 1;
            Integer j = (str1+1)/2;
            List<Integer> output = new ArrayList<>();
            if (str2.size()==1)
                output.add(0);
            for (;i<str2.size();i++){
                Integer b1 = 0;
                Integer l = i;
                for (Integer k=0 ;k<j;k++){
                    if (l>=str2.size())
                        l=l-str2.size();
                    Integer b = str2.get(l);
                    b1 += b;
                    l++;
                }
                output.add(Math.abs((360-b1)-b1));
            }
            output = output.stream().sorted().collect(Collectors.toList());

            System.out.print(output.get(0));

        }

}

import java.util.Scanner;

public class Main {

	public static int[][] truthTable(int nItems) {
		int columns = nItems;
		int lines = (int) Math.pow(2, nItems);
		int[][] tt = new int[lines][columns];

		int value = 1; // 0 ou 1
		int step = 1;
		for (int j = columns - 1; j >= 0; j--) {
			for (int i = lines - 1; i >= 0; i = i--) {
				for (int n = step; n > 0; n--) {
					tt[i][j] = value;
					i--;
				}
				if (value == 1)
					value = 0;
				else
					value = 1;
			}
			step = step * 2;
			value = 1;
		}
		return tt;
	}

	public static int divide(int[] slices, int[] line) {
		int vasya = 0; // 1
		int petya = 0; // 0
		int remainder;

		for (int i = 0; i < slices.length; i++) {
			if (line[i] == 1)
				vasya += slices[i];
			else
				petya += slices[i];
		}

		remainder = Math.abs(vasya - petya);
		return remainder;
	}

	public static int minimumValue(int[] slices) {
		int minimumValue = 0;
		int nSlices = slices.length;
		int[][] truthTable = truthTable(nSlices);
		int nCases = truthTable.length;

		for (int i = 0; i < nCases; i++) {
			int difference = divide(slices, truthTable[i]);
			if (i == 0)
				minimumValue = difference;
			else if (difference < minimumValue)
				minimumValue = difference;
		}

		return minimumValue;
	}

	public static boolean validAngles(String angles, int nSlices) {
		int cont = 0, sum = 0;

		String num = "";

		for (int i = 0; i < angles.length(); i++) {
			char ch = angles.charAt(i);
			if (Character.isDigit(ch))
				num += ch;
			else {
				sum += Integer.parseInt(num);
				num = "";
				cont++;
			}
		}
		sum += Integer.parseInt(num);
		cont++;

		if (sum != 360)
			System.out.println("The sum of the angles must be 360.".toUpperCase());

		if (cont != nSlices)
			System.out.println("The number of angles entered has to be consistent \nwith the number of pieces informed."
					.toUpperCase());

		System.out.println();
		return (sum == 360 && cont == nSlices);

	}

	public static int[] stringToIntArray(String inputString, int nSlices) {
		int cont = 0;
		int[] angles = new int[nSlices];
		String num = "";

		for (int i = 0; i < inputString.length(); i++) {
			char ch = inputString.charAt(i);
			if (Character.isDigit(ch))
				num += ch;
			else {
				angles[cont++] = Integer.parseInt(num);
				num = "";
			}
		}
		angles[cont] = Integer.parseInt(num);

		return angles;
	}

	public static void main(String[] args) {
		Scanner read = new Scanner(System.in);
		String angles;
		int nSlices;
		do {
			System.out.println("input\n");
			System.out.print("Number of pieces into which the delivered pizza was cut: ");
			nSlices = read.nextInt();

			System.out.println(
					"The angles of the sectors into which the pizza was cut in integers separated by spaces: ");
			read.nextLine();
			angles = read.nextLine();
		} while (!validAngles(angles, nSlices));

		int[] slices = stringToIntArray(angles, nSlices);

		int minimumValue = minimumValue(slices);
		System.out.println("\noutput");
		System.out.println(minimumValue);
		read.close();
	}

}

import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class main
{
	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;
	private static long mod = 1000000000 + 7;

	private static void soln()
	{
		int n = nextInt();
		int[] arr = nextIntArray(n);
		boolean[] f = new boolean[361];
		f[0] = true;
		for(int i=0;i<n;i++) {
			for(int j=0;j<361;j++) {
				if(j+arr[i] <= 360) {
					f[j+arr[i]] |= f[j];
				}
			}
		}
		if(n!=1) {
		for(int i=180;i>=0;i--) {
			if(f[i]) {
				pw.println((360-2*i));
				break;
			}
		}
		}else
			pw.println(arr[0]);
	}
	private static class Pair implements Comparable<Pair>{
		long val;
		int br;
		public Pair(long a,int b) {
			val=a;
			br=b;
		}
		@Override
		public int compareTo(Pair arg0)
		{
			return (int) (this.val-arg0.val);
		}
	}
	private static long pow(long a, long b, long c)
	{
		if (b == 0)
			return 1;
		long p = pow(a, b / 2, c);
		p = (p * p) % c;
		return (b % 2 == 0) ? p : (a * p) % c;
	}

	private static long gcd(long n, long l)
	{
		if (l == 0)
			return n;
		return gcd(l, n % l);
	}

	public static void main(String[] args) throws Exception
	{
//		new Thread(null, new Runnable()
//		{
//			@Override
//			public void run()
//			{
//				/*
//				 * try { InputReader(new
//				 * FileInputStream("C:\\Users\\hardik\\Desktop\\B-large-practice.in")); } catch
//				 *) (FileNotFoundException e) { // TODO Auto-generated catch block
//				 * e.printStackTrace(); }
//				 */
//				InputReader(System.in);
//				pw = new PrintWriter(System.out);
//				/*
//				 * try { pw=new PrintWriter(new
//				 * FileOutputStream("C:\\Users\\hardik\\Desktop\\out.txt")); } catch
//				 * (FileNotFoundException e) { // TODO Auto-generated catch block
//				 * e.printStackTrace(); }
//				 */
//				soln();
//				pw.close();
//			}
//		}, "1", 1 << 26).start();

		/*
		 * try { InputReader(new
		 * FileInputStream("C:\\Users\\hardik\\Desktop\\B-large-practice.in")); } catch
		 * (FileNotFoundException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); }
		 */
		 InputReader(System.in);
		 pw = new PrintWriter(System.out);
		/*
		 * try { pw=new PrintWriter(new
		 * FileOutputStream("C:\\Users\\hardik\\Desktop\\out.txt")); } catch
		 * (FileNotFoundException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); }
		 */
		soln();
		pw.close();
	}

	public static void InputReader(InputStream stream1)
	{
		stream = stream1;
	}

	private static boolean isWhitespace(int c)
	{
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	private static boolean isEndOfLine(int c)
	{
		return c == '\n' || c == '\r' || c == -1;
	}

	private static int read()
	{
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars)
		{
			curChar = 0;
			try
			{
				numChars = stream.read(buf);
			} catch (IOException e)
			{
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	private static int nextInt()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-')
		{
			sgn = -1;
			c = read();
		}
		int res = 0;
		do
		{
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static long nextLong()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-')
		{
			sgn = -1;
			c = read();
		}
		long res = 0;
		do
		{
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	private static String nextToken()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do
		{
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	private static String nextLine()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do
		{
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	private static int[] nextIntArray(int n)
	{
		int[] arr = new int[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = nextInt();
		}
		return arr;
	}

	private static long[] nextLongArray(int n)
	{
		long[] arr = new long[n];
		for (int i = 0; i < n; i++)
		{
			arr[i] = nextLong();
		}
		return arr;
	}

	private static void pArray(int[] arr)
	{
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr)
	{
		for (int i = 0; i < arr.length; i++)
		{
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c)
	{
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}

	private static char nextChar()
	{
		int c = read();
		while (isSpaceChar(c))
			c = read();
		char c1 = (char) c;
		while (!isSpaceChar(c))
			c = read();
		return c1;
	}

	private interface SpaceCharFilter
	{
		public boolean isSpaceChar(int ch);
	}
}

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class pizzasep {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(br.readLine());
		StringTokenizer st=new StringTokenizer(br.readLine());
		int [] slice=new int[n];
		for(int i=0;i<n;++i) {
			slice[i]=Integer.parseInt(st.nextToken());
		}
		Arrays.sort(slice);
		int vas=slice[n-1];
		int pet=0;
		int delta=vas;
		for(int i=n-2;i>-1;--i) {
			if(delta>0) {
				pet+=slice[i];
				delta-=slice[i];
			}
			else if(delta<=0) {
				vas+=slice[i];
				delta+=slice[i];
			}
		}
		System.out.println(Math.abs(vas-pet));
	}
}