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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  string in;
  while(getline(cin,in)){
    if(in=="0") break;
    vector<int> num;
    stringstream ss(in);
    int tmp;
    while(ss>>tmp) num.push_back(tmp);
    int ace = 0;
    int ans = 0;
    REP(i,num.size()){
      if(num[i]>10) num[i] = 10;
      if(num[i]==1){
        ace++;
        num[i] = 11;
      }
      ans += num[i];
    }
    while(ace&&ans>21){
      ace--;
      ans-=10;
    }
    cout<<((ans>21)?0:ans)<<endl;
  }
  return 0;
}

C++: #include<cstdio>
#include<sstream>
#define MAX(x,y) ((x>y)?x:y)
using namespace std;

int main(){
	int i,j,x,sum,f,ans;
	char s[200];
	
	while(fgets(s,200,stdin)!=NULL){
		istringstream ss(s);
		f=sum=0;
		while(ss>>x){
			if(x==0)goto fin;
			if(x==1)f++;
			else if(x>9)sum+=10;
			else sum+=x;
		}
		ans=0;
		for(i=0;i<=f;i++){
			x=sum+i+11*(f-i);
			if(x>21)x=0;
			ans=MAX(ans,x);
		}
		printf("%d\n",ans);
	}
	fin:
	
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        string s;
        getline(cin, s);
        if(s == "0")
            return 0;

        istringstream iss(s);
        int ret = 0;
        int num1 = 0;
        for(;;){
            int a;
            if(!(iss >> a))
                break;
            if(a > 10)
                a = 10;
            if(a == 1){
                ++ num1;
                a = 11;
            }
            ret += a;
            while(ret > 21 && num1 > 0){
                ret -= 10;
                -- num1;
            }
        }

        if(ret > 21)
            ret = 0;
        cout << ret << endl;
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <numeric>
#include <iterator>
using namespace std;

vector<int> parse(string s) {
    istringstream iss(s);
    vector<int> res;
    for(int n; iss >> n; ) {
        if(n > 10) n = 10;
        res.push_back(n);
    }
    return res;
}

int main() {
    for(string line; getline(cin, line), line != "0"; ) {
        vector<int> cards = parse(line);
        int one = 0;
        for(int c : cards) if(c == 1) one++;
        int s = accumulate(begin(cards), end(cards), 0);
        for(int i = 0; i < one; i++) {
            if(s + 10 <= 21) s += 10;
        }
        if(s > 21) s = 0;
        cout << s << endl;
    }
}

C++: #include <iostream>
#include <vector>
#include <cstring>
#include <cstdlib>

using namespace std;

int main(int argc, char const* argv[])
{
	vector<int> data;
	char str[90];

	while( cin.getline( str, 90 ) && strcmp( str, "0" ) != 0 ){
		char *t;
		data.clear();
		t = strtok( str, " " );
		data.push_back( atoi( t ) );
		while( ( ( t = strtok( NULL, " " ) ) != NULL ) ){
			data.push_back( atoi( t ) );
		}

		int answer;
		int count;

		answer = 0;
		count = 0;

		for( int i = 0;i < data.size();i++ ){
			if( data[i] >= 10 ) answer += 10;
			else answer += data[i];
			if( data[i] == 1 ) count++;
		}
		if( answer > 21 ) answer = 0;
		else if( answer <= 11 ){
			for( int i = 0;i < count;i++ ){
				if( answer + 10 > 21 ) break;
				else answer += 10;
			}
		}
		cout << answer << endl;
	}
	return 0;
}

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

int main(){
    while(1){
        string s;
        getline(cin, s);
        if(s == "0") return 0;

        int n = s.size();
        int sum = 0;
        int cnt1 = 0;
        for(int i=0; i<n; i++){
            string t = "";
            while(i < n && '0' <= s[i] && s[i] <= '9'){
                t += s[i];
                i++;
            }
            int num = stoi(t);
            if(10 <= num) sum += 10;
            else if(1 < num) sum += num;
            else{
                cnt1++;
                sum++;
            }
        }

        vector<int> v;
        v.emplace_back(sum);

        for(int i=1; i<=cnt1; i++){
            sum += 10;
            v.emplace_back(sum);
        }

        sort(v.begin(), v.end(), greater<int>());

        bool valid = false;
        for(auto i : v){
            if(21 >= i){
                cout << i << endl;
                valid = true;
                break;
            }
        }

        if(!valid){
            cout << 0 << endl;
        }
    }
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int main(){
    string s;
    while(1){
        getline(cin,s);
        if(s=="0")break;
        s+=" ";
        vector<string> st;
        string buf="";
        rep(i,s.size()){
            if(s[i]!=' ')buf+=s[i];
            else{
                st.pb(buf);
                buf="";
            }
        }
        
        int score=0;
        int c=0;
        rep(i,st.size()){
            if(st[i]!="1"){
                int num=stoi(st[i]);
                if(10<=num)score+=10;
                else score+=num;
            }
            else{
                score+=1;
                c++;
            }
        }
        rep(i,c){
            if(21-score>=10)score+=10;
        }
        if(score>21)cout<<"0"<<endl;
        else cout<<score<<endl;
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rrep(i,n) for(int i=(int)(n)-1; i>=0; i--)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  string s;
  while(getline(cin,s)) {
    if(s=="0") break;
    int sum=0,k=0,x;
    stringstream ss;
    ss << s;
    while(ss >> x) {
      if(x>10) x=10;
      sum+=x;
      if(x==1) {
	k++;
	sum+=10;
      }
    }
    while(sum>21 && k--) sum-=10;
    if(sum>21) sum=0;
    pr(sum);
  }
  return 0;
}