import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] first = splitInt(sc.nextLine(), " ");
		int[] second = splitInt(sc.nextLine(), " ");
		
		int i= 1;
		int j = first[0]-2;
		int a = second[0];
		int b = second[first[0]-1];
		for(; i<first[0] && j>=0 && i<=j;) {
			if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			}
		}
		System.out.println(Math.abs(a-b));
	}
	public static int[] splitInt(String str, String split) {
		String[] array = str.split(split);
		int[] array2 = new int[array.length];
		for(int i=0; i<array.length; i++) {
				array2[i] = Integer.parseInt(array[i]);
		}
		return array2;
	}
} import java.lang.reflect.Array; Array java.lang.reflect import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Comparator; Comparator java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] first = splitInt(sc.nextLine(), " ");
		int[] second = splitInt(sc.nextLine(), " ");
		
		int i= 1;
		int j = first[0]-2;
		int a = second[0];
		int b = second[first[0]-1];
		for(; i<first[0] && j>=0 && i<=j;) {
			if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			}
		}
		System.out.println(Math.abs(a-b));
	}
	public static int[] splitInt(String str, String split) {
		String[] array = str.split(split);
		int[] array2 = new int[array.length];
		for(int i=0; i<array.length; i++) {
				array2[i] = Integer.parseInt(array[i]);
		}
		return array2;
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] first = splitInt(sc.nextLine(), " ");
		int[] second = splitInt(sc.nextLine(), " ");
		
		int i= 1;
		int j = first[0]-2;
		int a = second[0];
		int b = second[first[0]-1];
		for(; i<first[0] && j>=0 && i<=j;) {
			if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			}
		}
		System.out.println(Math.abs(a-b));
	} main {
		Scanner sc = new Scanner(System.in);
		int[] first = splitInt(sc.nextLine(), " ");
		int[] second = splitInt(sc.nextLine(), " ");
		
		int i= 1;
		int j = first[0]-2;
		int a = second[0];
		int b = second[first[0]-1];
		for(; i<first[0] && j>=0 && i<=j;) {
			if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			}
		}
		System.out.println(Math.abs(a-b));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int[] first = splitInt(sc.nextLine(), " "); first splitInt(sc.nextLine(), " ") splitInt sc.nextLine() sc.nextLine sc " " int[] second = splitInt(sc.nextLine(), " "); second splitInt(sc.nextLine(), " ") splitInt sc.nextLine() sc.nextLine sc " " int i= 1; i 1 int j = first[0]-2; j first[0]-2 first[0] first 0 2 int a = second[0]; a second[0] second 0 int b = second[first[0]-1]; b second[first[0]-1] second first[0]-1 first[0] first 0 1 for(; i<first[0] && j>=0 && i<=j;) {
			if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			}
		} ; i<first[0] && j>=0 && i<=j i<first[0] && j>=0 && i<=j i<first[0] i first[0] first 0 j>=0 j 0 i<=j i j {
			if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			}
		} {
			if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			}
		} if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			} a>b a b {
				b += second[j];
				j--;
			} b += second[j] b second[j] second j j-- j {
				a += second[i];
				i++;
			} a += second[i] a second[i] second i i++ i System.out.println(Math.abs(a-b)) System.out.println System.out System System.out Math.abs(a-b) Math.abs Math a-b a b String[] args args public static int[] splitInt(String str, String split) {
		String[] array = str.split(split);
		int[] array2 = new int[array.length];
		for(int i=0; i<array.length; i++) {
				array2[i] = Integer.parseInt(array[i]);
		}
		return array2;
	} splitInt {
		String[] array = str.split(split);
		int[] array2 = new int[array.length];
		for(int i=0; i<array.length; i++) {
				array2[i] = Integer.parseInt(array[i]);
		}
		return array2;
	} String[] array = str.split(split); array str.split(split) str.split str split int[] array2 = new int[array.length]; array2 new int[array.length] array.length array array.length for(int i=0; i<array.length; i++) {
				array2[i] = Integer.parseInt(array[i]);
		} int i=0; int i=0; i 0 i<array.length i array.length array array.length i++ i++ i {
				array2[i] = Integer.parseInt(array[i]);
		} {
				array2[i] = Integer.parseInt(array[i]);
		} array2[i] = Integer.parseInt(array[i]) array2[i] array2 i Integer.parseInt(array[i]) Integer.parseInt Integer array[i] array i return array2; array2 String str str String split split public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] first = splitInt(sc.nextLine(), " ");
		int[] second = splitInt(sc.nextLine(), " ");
		
		int i= 1;
		int j = first[0]-2;
		int a = second[0];
		int b = second[first[0]-1];
		for(; i<first[0] && j>=0 && i<=j;) {
			if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			}
		}
		System.out.println(Math.abs(a-b));
	}
	public static int[] splitInt(String str, String split) {
		String[] array = str.split(split);
		int[] array2 = new int[array.length];
		for(int i=0; i<array.length; i++) {
				array2[i] = Integer.parseInt(array[i]);
		}
		return array2;
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] first = splitInt(sc.nextLine(), " ");
		int[] second = splitInt(sc.nextLine(), " ");
		
		int i= 1;
		int j = first[0]-2;
		int a = second[0];
		int b = second[first[0]-1];
		for(; i<first[0] && j>=0 && i<=j;) {
			if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			}
		}
		System.out.println(Math.abs(a-b));
	}
	public static int[] splitInt(String str, String split) {
		String[] array = str.split(split);
		int[] array2 = new int[array.length];
		for(int i=0; i<array.length; i++) {
				array2[i] = Integer.parseInt(array[i]);
		}
		return array2;
	}
} Main
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] first = splitInt(sc.nextLine(), " ");
		int[] second = splitInt(sc.nextLine(), " ");
		
		int i= 1;
		int j = first[0]-2;
		int a = second[0];
		int b = second[first[0]-1];
		for(; i<first[0] && j>=0 && i<=j;) {
			if(a>b) {
				b += second[j];
				j--;
			}else {
				a += second[i];
				i++;
			}
		}
		System.out.println(Math.abs(a-b));
	}
	public static int[] splitInt(String str, String split) {
		String[] array = str.split(split);
		int[] array2 = new int[array.length];
		for(int i=0; i<array.length; i++) {
				array2[i] = Integer.parseInt(array[i]);
		}
		return array2;
	}
}