Result: Accepted
Time: 6ms
Memory: 3280kB
#include<cstring>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 200010;
const int inf = 0x3f3f3f3f;
const int mo = 1e9+7;
int t,n,m,l,r,ans,cnt;
int a[maxn],b[maxn];
int main(){
while(cin>>t){
if(t==0)break;
int flag=0;
for(int i=0;i<t;i++){
cin>>a[i];
if(a[i]<2) flag=1;
}
if(flag==1) cout<<"-1"<<endl;
else{
sort(a,a+t);
ans=0;
for(int i=1;i<t;i++){
ans+=a[i];
}
cout<<ans+2<<endl;
}
}
return 0;
}