Result: Accepted
Time: 6ms
Memory: 1720kB
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <deque>
#define clr(a,b) memset(a,b,sizeof(a))
#define ll long long
using namespace std;
const int maxn=1e3+10;
int n;
int a[maxn];
int main()
{
while(scanf("%d",&n)!=EOF)
{
if(!n)break;
int flag=1;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]<=1)flag=0;
}
if(flag==0)printf("-1\n");
else
{
int ans=0;
sort(a,a+n);
ans+=2;
for(int i=1;i<n;i++)ans+=a[i];
printf("%d\n",ans);
}
}
}