import java.util.*;
import java.lang.Math;
public class testing{
public static void main( String args[]){
Scanner x = new Scanner(System.in);
String a = x.nextLine();
String b = x.nextLine();
String[] arrS = b.split(" ");
ArrayList<Integer> num = new ArrayList<Integer>();
for(String h : arrS){
// System.out.println(Integer.parseInt(h));
num.add(Integer.parseInt(h));
}
Collections.sort(num);
//for(int i : num){
// System.out.println(i);
//}
int sum = 0;
for(int g: num){
sum += g;
}
int v = sum/2;
int d = num.get(num.size());
int o = num.get(num.size());
int x1,x2;
if(num.get(num.size()) >= v){
int a1 = 0;
for(int g : num){
a1+=g;
}
System.out.println(num.get(size())-(a1-num.get(size())));
}
else{
for(x1 = 0; x1<num.size(); x1++ ){
if(Math.abs(d+num.get(x1)-(v))< Math.abs(d)){
d = d+num.get(x1)-(v);
}
}
System.out.println(sum-d-(d));
}
}
}