Go: package main

import (
	"bufio"
		"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		cards := make([]int, len(buf))
		for i := range buf {
			cards[i], _ = strconv.Atoi(buf[i])
		}
		if cards[0] == 0 {
			break
		}
		sum, ace := 0, 0
		for _, v := range cards {
			if v == 1 {
				v = 0
				ace++
			} else if v >= 10 {
				v = 10
			}
			sum += v
			if sum+ace > 21 {
				break
			}
		}
		if sum+ace > 21 {
			fmt.Println(0)
		} else if ace > 0 && sum+ace<= 11 {
			fmt.Println(sum+ace+10) // 1->11なるAceは高々1枚
		} else {
			fmt.Println(sum+ace)
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

vector<string> Split(char c,string s){
  vector<string> res(0);
  string str = "";
  rep(i,s.size()){
    if(s[i] == c){
      res.push_back(str);
      str.clear();
    }
    else{
      str += s[i];
    }
  }
  res.push_back(str);
  return res;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(getline(cin,s)){
    if(s[0] == '0') break;
    auto ss = Split(' ',s);
    vector<int> v(ss.size());
    int one = 0;
    rep(i,v.size()){
      v[i] = ston(ss[i],1);
      v[i] = (v[i]>10)?10:v[i];
      if(v[i] == 1){
        ++one;
      }
    }
    sort(all(v),greater<int>());
    int sc = 0;
    bool f = true;
    rep(i,v.size()){
      if(v[i] != 1){
        sc += v[i];
        if(sc > 21){
          sc = 0;
          f = false;
          cout << sc << endl;
          break;
        }
      }
    }
    if(f){
      if(one >= 2){
        sc += one;
      }
      else{
        sc += one * 11;
      }
      cout << sc << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
	string hands;
	while( getline( cin, hands ) ){
		if( hands == "0" ) break;
		stringstream ss( hands );
		int ans = 0;
		int ex = 0;
		while( !ss.eof() ){
			int p;
			ss >> p;
			if( p > 10 ){
				p = 10;
			}
			if( p == 1 ){
				++ex;
			}
			ans += p;
		}
		while( ex > 0 ){
			if( 21 - ans >= 10 ){
				ans += 10;
			}
			--ex;
		}
		cout << ( ans > 21 ? 0 : ans ) << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int ans,f,num;
string s;

int getNum(int x){
  int res=0;
  for(int i=x;s[i]!=' '&&i!=s.size();i++){
    res=res*10+s[i]-'0';
  }
  return res;
}

int main(){
  int d[14]={0,1,2,3,4,5,6,7,8,9,10,10,10,10};
  while(1){
    getline(cin,s);
    if(s=="0")break;
    ans=0,f=0;
    for(int i=0;i<s.size();i++){
      num=getNum(i);
      while(s[i]!=' '&&i!=s.size())i++;
      ans+=d[num];
      if(num==1)f=1;
    }
    if(f&&ans+10<=21)cout<<ans+10<<endl;
    else if(ans<=21)cout<<ans<<endl;
    else cout<<0<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(getline(cin,s),s!="0"){
    stringstream ss(s);
    int x;
    int si=0;
    vector<int> v;
    v.clear();
    v.push_back(0);
    while(ss>>x){
      si=v.size();
      for(int i=0;i<si;i++){
	if(x==1){
	  v.push_back(v[i]+11);
	  v[i]++;
	}else if(x>10) v[i]+=10;
	else v[i]+=x;
      }
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<v.size();i++){
      if(v[i]<=21) ans=v[i];
    }
    cout << ans << endl;
    s="";
  }  
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;

/*int stoi(string a){
	int ret;
	stringstream ss;
	ss<<a;
	ss>>ret;
	return ret;
	}*/

int main(){
	string s;
	while(getline(cin,s)&&s!="0"){
		s.push_back(' ');
		int one=0;
		int sum=0;
		
		string a;
		for(int i=0;i<s.size();i++){
			if(s[i]==' '){
				int b=stoi(a);
				if(b==1)one++;
				else if(b>10)sum+=10;
				else sum+=b;
				a.clear();
				}
			else a.push_back(s[i]);
			}
			sum+=one;
			for(int i=0;i<one;i++){
				if(sum<12)sum+=10;
				}	
				
			if(sum>21)sum=0;	
			cout<<sum<<endl;	
		}
	return 0;
	}

C++: #include <bits/stdc++.h>
using namespace std;

vector<int> v;

int dp(int p, int n){
    if(p == v.size() && n <= 21) return n;
    else if(21 < n) return 0;
    else {
        if(v[p] == 1){
            return max(dp(p+1, n+1), dp(p+1, n+11));
        }
        else return dp(p+1, n+v[p]);
    }
}

int main(){
    string input;
    while(getline(cin, input), input != "0"){
        int n;
        v.clear();
        while(input.find_first_of(" ") != string::npos){
            n = atoi(input.substr(0, input.find_first_of(" ")).c_str());
            if(n/10 == 1) n = n-n%10;
            v.push_back(n);
            input = input.substr(input.find_first_of(" ")+1);
        }
        n = atoi(input.c_str());
        if(n/10 == 1) n = n-n%10;
        v.push_back(n);

        cout << dp(0, 0) << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(getline(cin,s),s!="0"){
    stringstream ss(s);
    int x=0,i,ans,k;
    int si=0;
    vector<int> v;
    v.clear();
    v.push_back(0);
    
    while(ss>>x){
      si=v.size();
      for(i=0;i<si;i++){
	
	if(x==1){
	  k=v[i];
	  v.push_back(k+11);
	  v[i]++;
	}else if(x>10){
	  v[i]+=10;
	}else {
	  v[i]+=x;
	}
	
      }
    }
    
    sort(v.begin(),v.end());
    ans=0;
    for(i=0;i<v.size();i++){
      if(v[i]<=21) ans=v[i];
    }
    cout << ans << endl;
    s="";
  }  
  return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <functional>
using namespace std;

int calc_point(int* cards, int size) {
    int point = 0;
    sort(cards, cards+size, greater<int>());
    for (int i = 0; i < size; i++) {
        if (10 <= *(cards+i) && *(cards+i) <= 13) {
            point += 10;
        } else if (cards[i] != 1) {
            point += cards[i];
        } else {
            int remain_ace = size - i;
            while (remain_ace) {
                if (remain_ace == 1) {
                    if (point <= 10) {
                        point += 11;
                    } else {
                        point += 1;
                    }
                } else {
                    point += 1;
                }
                i++;
                remain_ace--;
            }
        }
    }
    if (point > 21) point = 0;
    return point;
}

#define MAX 1000
int main() {
    string s;
    int hand[MAX]; 
    while (getline(cin, s)) {
        if (s == "0") break;
        int i = 0;
        memset(hand, 0, sizeof(hand));
        istringstream ss; ss.str(s);
        while (ss >> hand[i++]);
        cout << calc_point(&hand[0], i-1) << endl;
    }
    return 0;
}