Start: Jun, 27, 2019 08:30:00
2019年度暑期短学期第二天
End: Jun, 27, 2019 11:30:00
Time elapsed:
Time remaining:

Problem_ID: H
Result: Accepted
Time: 6ms
Memory: 1712kB
Author: 2018212212305
In contest: 1275

#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main(){
	int T;
	int a[502],b,n,m;
		while(scanf("%d",&n)!=EOF&&n!=0){
			b=0;
	      for(int i=1;i<=n;++i){
	      	cin>>a[i];
		  }
		  m=a[1];
		  for(int i=1;i<=n;++i){
		  	if(m>a[i])
              m=a[i];
		  }
		  for(int i=1;i<=n;++i){
		  	if(a[i]>=2) {
		  		if(a[i]!=m)
		  		   b+=a[i];
		  		if(a[i]==m)
		  			b+=2;
				  }
			  
		  	if(a[i]<2) {
			 b=0;
			 break;
			  }
		  }
		  
	     if(b!=0)
	     cout<<b<<endl;
	     else if(b==0)
	     cout<<-1<<endl;
		}
	return 0;
}