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 <vector>
#include <string>
using namespace std;

int ans;

vector<int> split(string s){
 	int n=0;
	vector<int> vc;
 	s += " ";
	for(int i=0 ; i < s.size() ; i++ ){
		if( s[i] == ' ' ){
			vc.push_back( n );
 			n = 0;
		}else if( s[i] >= '0' && s[i] <= '9' ){
			n = n*10 + (s[i] - '0');
		}
	}
	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) , s != "0" ){
		vector<int> a = split(s);
		ans = 0;
		solve( a , 0 , 0 );
		cout << ans << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

int CardNumber[100];

int main() {
	int len, sum;
	string str;
	stringstream ss;

	while (1) {
		getline(cin, str);
		if (str.size() == 1 && str[0] == '0') {
			break;
		}
		memset(CardNumber, 0, sizeof(CardNumber));
		len = 0;
		ss << str;
		while (ss >> CardNumber[len]) {
			len++;
		}
		sort(CardNumber, CardNumber + len);

		/*cout << len << endl;
		for (int i = 0; i < len; i++) {
			cout << CardNumber[i] << ends;
		}
		cout << endl;*/

		sum = 0;
		for (int i = len - 1; i > -1; i--) {
			if (CardNumber[i] != 1) {
				sum += min(CardNumber[i], 10);
			}
			else {
				if (sum + i < 11) {
					sum += 11;
				}
				else {
					sum++;
				}
			}
		}

		sum = sum > 21 ? 0 : sum;
		cout << sum << endl;
		
		ss.clear();
		str = "";
	}

	return 0;
}

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 100
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 <string>
using namespace std;

int pos = 0;

int read(string s){
	int tmp = 0;
	while(s[pos] == ' ') pos++;
	while(s[pos] != ' '){
		tmp = tmp * 10 + s[pos++] - '0';
	}
	return tmp;
}

int main(){
	string s;
	while(getline(cin,s)){
		pos = 0;
		int one = 0,sum = 0;
		if(s == "0") break;
		s += " ";
		for(int i = 0;pos < s.length() - 1;i++){
			int num = read(s);
			if(num == 1) one++;
			if(num >= 10) num = 10;
			sum += num;
		}
		while(sum <= 11 && one){
			one--;
			sum += 10;
		}
		if(sum > 21) cout << 0 << endl;
		else cout << sum << endl;
	}
}

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;
}

signed main() {
	bool a[50][50] = {};
	for (string s; getline(cin, s) && s != "0";) {
		fill(a[0], a[50], 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 <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

int main(){
	string str;
	while(getline(cin,str)){
		if(str[0]=='0')break;
		stringstream ss;
		ss <<str;
		int x;
		int sum = 0;
		int cnt = 0;
		while(ss>>x){
			if(x==1){
				cnt++;
			}
			if(x >=11){
				x = 10;
			}
			sum +=x;
		}
		for(int i =0;i < cnt;i++){
			if(sum+10<=21){
				sum +=10;
			}else{
				break;
			}
		}
		if(sum >21)sum = 0;
		cout <<sum<<endl;
	}
	return 0;
}