import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
import java.util.TreeMap;
public class Main1 {
public static void main(String[] args) {
new Main1();
}
int l;
public Main1() {
Scanner s = new Scanner(System.in);
while (s.hasNextInt()) {
int count = s.nextInt();
if (count == 0) {
break;
}
NumNum nn = new NumNum();
int sum = 0;
for (int i = 0; i < count; i++) {
int num = s.nextInt();
sum += num;
nn.add(num, 1);
}
int max = nn.map.keySet().iterator().next();
for (int i : getList(max, sum)) {
l = i;
if (exec(nn, i)) {
System.out.println(i);
break;
}
}
}
s.close();
}
public List<Integer> getList(int max, int n) {
List<Integer> list = new ArrayList<Integer>();
for (int i = max; i <= Math.sqrt(n); i++) {
if (n % i == 0) {
list.add(i);
if (i * i != n) {
list.add(n / i);
}
}
}
Collections.sort(list);
return list;
}
public boolean exec(NumNum nn, int length) {
for (Iterator<Integer> i = nn.map.keySet().iterator(); i.hasNext();) {
int num = i.next();
int allCount = nn.map.get(num);
if (allCount == 0) {
continue;
}
int needCount = length / num;
if (needCount == 0) {
continue;
}
int count = Math.min(allCount, needCount);
nn.del(num, count);
int left = length - num * count;
if (left == 0) {
if (nn.isEmpty()) {
return true;
} else {
if (!exec(nn, l)) {
nn.add(num, count);
} else {
return true;
}
}
} else {
if (!exec(nn, left)) {
nn.add(num, count);
} else {
return true;
}
}
}
return false;
}
}
class NumNum {
TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>(new Comparator<Integer>() {
@Override
public int compare(Integer arg0, Integer arg1) {
return arg1 - arg0;
}
});
public void add(int i, int j) {
if (map.containsKey(i)) {
map.put(i, map.get(i) + j);
} else {
map.put(i, j);
}
}
public void del(int i, int j) {
map.put(i, map.get(i) - j);
}
public boolean isEmpty() {
for (Iterator<Integer> i = map.values().iterator(); i.hasNext();) {
if (0 != i.next()) {
return false;
}
}
return true;
}
}