#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #define ll long long #define INF 0x7fffffff #define re register
int n,m,x,sum,len,tot,flag,a[1000005],vis[100005];
boolcmp(int a,int b){return a > b;}
voiddfs(int k, int now, int las) { if(flag) return ; if(now == len) now = 0, k++, las = 0; if(k > tot) { flag = 1; printf("%d\n",len); return ; } for(re int i = las + 1; i <= n; i++) { if(vis[i]) continue; if(now + a[i] <= len) vis[i] = 1,dfs(k,now + a[i],i),vis[i] = 0; if(now == 0 || now + a[i] == len) return ; while(a[i + 1] == a[i]) i++; } }
intmain() { n = read(); while(n) { sum = 0; m = 0; flag = 0; //初始化点题 for(re int i = 1; i <= n; i++) { x = read(); if(x <= 50) a[++m] = x,sum += x; } sort(a + 1, a + n + 1, cmp); for(re int i = a[1]; i <= sum / 2; i++) { if(sum % i != 0) continue; memset(vis,0,sizeof(vis)); tot = sum / i; len = i; flag = 0; dfs(1,0,0); if(flag) break; } if(!flag) printf("%d\n",sum); n = read(); } return0; }