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<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<regex>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

//split delimiter??§?????????
vector<string> split(const string& input, char delimiter) {
	vector<string> ret;
	istringstream stream(input);
	string s;
	while (getline(stream, s, delimiter)) ret.push_back(s);
	return ret;
}
#define MAX 50
signed main() {
	bool a[MAX][50] = {};
	for (string s; getline(cin, s) && s != "0";) {
		fill(a[0], a[MAX], false);
		a[0][0] = true;
		vector<string> t = split(s, ' ');
		rep(i, 0, t.size()) {
			rep(j, 0, 30) {
				if (stoi(t[i]) <= 10);
					//if (a[i][j])a[i + 1][stoi(t[i]) + j] = true;
				if (stoi(t[i]) >= 11);
					//if (a[i][j])a[i + 1][10 + j] = true;
				if (stoi(t[i]) == 1);
					//if (a[i][j])a[i + 1][11 + j] = true;
			}
		}
		rrep(i, 0, 22) {
			if (a[t.size()][i]) {
				cout << i << endl;
				break;
			}
			if (i == 0)cout << 0 << endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <sstream>
#include <bitset>

using namespace std;

int main(){
    string s;
    while(getline(cin,s)){
        if(s=="0") break;
        stringstream ss;
        ss << s;
        vector<int> c;
        int temp;
        while(ss >> temp) c.push_back(temp);
        bitset<22> bits;
        bits.set(0);
        for(int i=0;i<c.size();i++){
            bitset<22> newbits;
            int x = c[i];
            for(int j=0;j<22;j++){
                if(!bits[j]) continue;
                if(x>=10) x = 10;
                if(x != 1 && j+x <= 21) newbits.set(j+x);
                if(x == 1){
                    if(j+11 <= 21) newbits.set(j+11);
                    if(j+1 <= 21) newbits.set(j+1);
                }
            }
            bits = newbits;
        }
        int mm=0;
        for(int i=0;i<22;i++){
            if(bits[i]) mm = i;
        }
        cout << mm << endl;
    }
}

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

int main() {
	while(1) {
		char input[1024];
		cin.getline(input, sizeof input);
		if(strcmp(input, "0") == 0) {
			break;
		}
		stringstream ss(input);
		vector<int> v;
		int num;
		while(ss >> num) {
			v.push_back(num);
		}
		sort(v.begin(), v.end(), greater<int>());
		int n = v.size();
		int sum = 0;
		for(int i = 0; i < n; i++) {
			if(v[i] == 1) {
				if(sum + 10 >= 21 - (n - i + 1)) {
					sum++;
				} else {
					sum += 10;
				}
				continue;
			}
			else if(v[i] >= 10) {
				sum += 10; continue;
			} else {
				sum += v[i];
			}
		}
		if(sum > 21) cout << 0 << endl;
		else cout << sum << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;

int main(){
	char c;
int n,s=0;int A=0;
while(1){
	while(1){
scanf("%d%c",&n,&c);



	
if(n>1&&n<11)s+=n;
else if(n>10)s+=10;
else if(n==1){s+=1;A++;}
if(c=='\n')break;
}
if(s==0)break;
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 <iostream>
#include <sstream>

using namespace std;

int main(){
  string in;  

  while(getline(cin,in) ,in != "0"){
    stringstream s(in);
    int sum = 0,n;
    bool flg = false;

    while(s >> n){
      if(2 <= n && n <= 9){
	sum += n;
      }else if(n >= 10){
	sum += 10;
      }else{
	sum++;
	flg = true;
      }
    }

    if(sum <= 11 && flg){
      sum += 10;
    } 

    if(sum > 21){
      cout << 0 << endl;
    }else{
      cout << sum << endl;
    }
  }

  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<complex>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

int main(){
  while(true){
    vector<int> v;
    string str;
    getline(cin, str);
    stringstream ss(str);
    int tmp;
    while(ss>>tmp){
      if(tmp == 0) goto end;
      if(tmp > 10) tmp = 10;
      v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    int sum = accumulate(ALL(v), 0);
    if(sum < 12 && v[0] == 1)
      sum += 10;
    if(sum > 21) sum = 0;
    cout << sum << endl;
  }
 end:
  return 0;
}

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

int ans;

vector<int> split(string s){
	int n=0;
	vector<int> vc;

	for(int i=0 ; i < s.size() ; i++ ){
		char c = s[i];
		if( c == ' ' ){
			vc.push_back( n );
			n = 0;
		}else if( c >= '0' && c <= '9' ){
			n *= 10;
			n += c - '0';
			if( i == s.size()-1 )
				vc.push_back( n );
		}
	}
	return vc;
}

void solve(const vector<int>& a,int i,int p){
	if( p > 21 ){
		return;
	}
	if( i == a.size() ){
		ans = max( ans , p );
		return;
	}

	if( a[i] == 1 ){
		solve( a , i+1 , p+1  );
		solve( a , i+1 , p+11 );
	}else if( a[i] >= 10 ){
		solve( a , i+1 , p+10 );
	}else{
		solve( a , i+1 , p+a[i] );
	}
}

int main(){
	string s;
	while( getline(cin,s) ){
		vector<int> a = split(s);
		if( a.size() == 1 && a[0] == 0 ) break;

		ans = 0;
		solve( a , 0 , 0 );
		cout << ans << endl;
	}
}