Result: Accepted
Time: 7ms
Memory: 2160kB
#include <cstdio>
#include <iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
int n,t,i,j,k;
int a,b,c;
int s[114514];
int gcd(int n,int m){
int r;
while(1){
r=m%n;
if(r==0)
break;
m=n;
n=r;
}
return n;
}
int main()
{
int flag,sum,min;
while(~scanf("%d",&n),n)
{
flag=1;
sum=0;
min=514;
for(i=0;i<n;++i){
cin>>s[i];
sum+=s[i];
if(min>s[i])
min=s[i];
if(s[i]<2)
flag=0;
}
/*if(n==1){
if(!flag)
cout<<"-1"<<endl;
else{
cout<<"2"<<endl;
}
}
else*/{
if(!flag)
cout<<"-1"<<endl;
else{
cout<<sum-min+2<<endl;
}
memset(s,0,sizeof s);
}
}
return 0;
}