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++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;


int main(){
	string s;
	while(getline(cin,s),s != "0"){
		istringstream iss(s);
		vector<int> v; int x;
		while(iss>>x) v.push_back(x);
		int one = 0,ans = 0;
		FOR(i,sz(v)) {
			if(v[i] == 1) one++;
			else ans += min(10,v[i]);
		}
		ans += one;
		for(int i = 0; i < one; i++){
			if(ans + 10 > 21) break;
			ans += 10;
		}
		cout << (ans>21?0:ans) << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<sstream>
#include<string>
using namespace std;
int main(){
long a,b,c;
stringstream ss;
string s;
for(;;){
getline(cin,s);
if(s=="0")break;
ss.str("");ss.clear();
ss<<s;
b=c=0;
while(ss>>a){
if(a==1){c++;b+=11;}
else if(a>9)b+=10;
else b+=a;
}
while(b>21&&c>0){
b-=10;c--;
}
if(b>21)b=0;
cout<<b<<endl;
}
return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


vector<string> split(const string &s, char c = ' ') {
	vector<string> ret;
	stringstream ss(s);
	string t;
	while (getline(ss, t, c)) {
		ret.push_back(t);
	}
	return ret;
}



int main() {
	string s;
	vector<string> v;
	int p, t, n;
	while (getline(cin, s)) {
		v = split(s);
		if (v[0] == "0")break;
		p = 0;
		n = 0;
		for (int i = 0; i < v.size(); i++) {
			t = atoi(v[i].c_str());
			//cout << " " << t;
			if (t < 10)p += t;
			else p += 10;
			if (t == 1)n++;
		}
		//cout << endl;
		while (n > 0) {
			if (p + 10 <= 21)p += 10;
			n--;
		}
		if (p > 21)p = 0;
		cout << p << endl;
	}
}

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

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;
				}
			else a.push_back(s[i]);
			}
			
		int dp[114][23]={};
		dp[0][max(22,sum)]=1;
		for(int i=1;i<=one;i++){
			for(int j=0;j<22;j++){
				dp[i][j+1]=dp[i][j];
				dp[i][max(22,j+11)]=dp[i][j];
				}
			}
			
		int ans=0;
		for(int i=0;i<22;i++){
			if(dp[one][i])ans=i;
			}		
		cout<<ans<<endl;	
		}
	return 0;
	}

C++: #include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
vector<string> split(string inp);
int main(){
    string input;
    while(true){
        getline(cin, input);
        vector<string> data;
        data = split(input);
        if (atoi(input.c_str()) == 0) {
            break;
        }
        int score1 = 0;
        int score2 = 0;
        for(vector<string>::iterator it = data.begin(); it != data.end(); it++) {
            int point = atoi((*it).c_str());
            if (point >= 2 && point <= 9) {
                score1 += point;
                score2 += point;
            }
            else if (point >= 10) {
                score1 += 10;
                score2 += 10;
            }
            else if (point == 1) {
                score1 += 1;
                score2 += 11;
            }
        }
        if (score1 > 21) {
            if (score2 > 21) {
                cout << "0" << endl;
            }
            else {
                cout << score2 << endl;
            }
        }
        else if (score2 > 21) {
            cout << score1 << endl;
        }
        else {
            if (score2 >= score1) {
                cout << score2 << endl;
            }
            else {
                cout << score1 << endl;
            }
        }
    }
}
vector<string> split(string inp){
    int length = inp.length();

    string::iterator it = inp.begin();

    vector<string> ret;

    vector<char> tmp;

    while (true) {
        if (it == inp.end()) {
            //in
            char t[tmp.size()+1];
            int i = 0;
            for(vector<char>::iterator cit = tmp.begin(); cit != tmp.end(); cit++){
                t[i] = *cit;
                i++;
            }
            t[i] = '\0';
            string push = t;
            ret.push_back(push);
            tmp.clear();
            break;
        }
        if (*it == ' ') {
            //in
            char t[tmp.size()+1];
            int i = 0;
            for(vector<char>::iterator cit = tmp.begin(); cit != tmp.end(); cit++) {
                t[i] = *cit;
                i++;
            }
            t[i] = '\0';
            string push = t;
            ret.push_back(push);
            tmp.clear();
        }
        else {
            tmp.push_back(*it);
        }
        it++;
    }
    return ret;
}

C++: #include<stdio.h>

int main(){

int n,s=0;int A=0;
while(1){
scanf("%d",&n);
if(n==0)break;
s+=n;
while(scanf("%d",&n)!=EOF){
	
if(n>1&&n<11)s+=n;
else if(n>10)s+=10;
else if(n==1){s+=1;A++;}
}
if(s>=22)printf("0\n");


else {
	if(A>0){
	for(int i=0;i<A;i++)
		if(s+10<=21)s+=10;
	
	}
	
	
}
	

printf("%d\n",s);s=0;A=0;
}
return 0;
}

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

int main(){
  while(1){
    int n=0,card[100];
    while(cin>>card[n++]);
    if(card[0]==0)break;
    sort(card,card+n,greater<int>());
    int score=0;
    for(int i=0;i<n;i++){
      if(card[i]>=10)score+=10;
      else if(card[i]>1)score+=card[i];
      else if(11+(n-i)<=21)score+=11;
      else score++;
    }
    cout <<(score<=21? score:0)<<endl;
  }
  return 0;
}