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 <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    while(getline(cin, s), s != "0"){
        vector<int> v{0};
        for (auto &&i : s) {
            if(i == ' ') v.emplace_back();
            else v.back() = v.back()*10 + i-'0';
        }
        int val = 0, one = 0;
        for (auto &&i : v) {
            val += min(i, 10);
            one += (i == 1);
        }
        while(val <= 11 && one){
            val += 10;
            one--;
        }
        if(val > 21) val = 0;
        cout << val << "\n";
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<stack>
using namespace std;
int main(){
    string str;
    while(getline(cin,str)){
        stringstream ss(str);
        vector<int>V;
        while(ss){
            int a;
            ss>>a;
            V.push_back(a);
        }
        if(V[0]==0)break;
        V.pop_back();
        stack<pair<int,int> >S;
        S.push(pair<int,int>(0,0));
        int Max=0;
        while(!S.empty()){
            int pnt=S.top().first,cnt=S.top().second;
            S.pop();
            if(pnt>21)continue;
            if(cnt==V.size()){
                Max=max(Max,pnt);
                continue;
            }
            int to=V[cnt];
            if(to>10)to=10;
            S.push(pair<int,int>(pnt+to,cnt+1));
            if(to==1)S.push(pair<int,int>(pnt+11,cnt+1));
        }
        cout<<Max<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <sstream>

using namespace std;

// ?????????????????????????????§????????£???????????????
vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
	
    while(getline(ss, buffer, sep)){
        v.push_back(buffer);
    }
	
    return v;
}

int int_str(string str){
	int num = 0;
	bool minus = false;
	if(str[0] == '-'){
		str = str.substr(1);
		minus = true;
	}
	for(int i = 0; i < str.size(); i++){
		num *= 10;
		num += (str[i] - '0');
	}
	if(minus){
		num = -num;
	}
	return num;
}

vector<int> str_to_int_vector(vector<string> v_str){
	vector<int> v_int;
	for(int i = 0; i < v_str.size(); i++){
		v_int.push_back(int_str(v_str.at(i)));
	}
	return v_int;
}

int main(){
	
	while(true){
		
		string str;
		
		getline(cin, str);
		
		if(cin.eof()){
			break;
		}
		
		vector<string> v_str = split(str, ' ');
		vector<int> v_int = str_to_int_vector(v_str);
		
		if(v_int.at(0) == 0){
			return 0;
		}
		
		int ans = 0;
		int count_1 = 0;
		
		for(int i = 0; i < v_int.size(); i++){
			if(v_int.at(i) == 1){
				count_1++;
				ans += v_int.at(i);
			}else if(v_int.at(i) <= 10){
				ans += v_int.at(i);
			}else{
				ans += 10;
			}
		}
		
		if(count_1 > 0){
			if(ans <= 11){
				ans += 10;
				count_1--;
			}
		}
		
		if(ans > 21){
			ans = 0;
		}
		
		cout << ans << endl;
		
	}
	
	return 0;
}

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

using namespace std;
int saiki(int ten,int ind,vector<int> &v){
    if(ind == v.size()){
        if(ten >= 22) return 0;
        return ten;
    }
    int t = v[ind];
    if(v[ind] >= 10) t=10;
    if(v[ind] == 1){
        return max(saiki(ten+11,ind+1,v),saiki(ten+1,ind+1,v));
    }else{
        return saiki(ten+t,ind+1,v);
    }
}

int main(){
    string s;
    while(getline(cin,s) && s != "0"){
        stringstream ss(s);
        vector<int> v;
        int n;
        while(ss>>n){
            v.push_back(n);
        }
        cout << saiki(0,0,v) << endl;
    }
}

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

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))

using namespace std; 

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

const int INF = 1 << 24;

int main(void){
    int res;
    for(string in; getline(cin, in), in.at(0) != '0'; cout << res << endl){
        stringstream ss;
        ss << in;
        
        bool one = false;
        res = 0;
        while(ss >> in){
            int cur = in.size() > 1 ? 10:in.at(0) - '0';
            if(cur == 1) one = true;

            res += cur;
        }
        if(one && res <= 11) res += 10;
        if(21 < res) res = 0;
    }

    return 0;
}

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

int main() {
	while(1) {
		string s;
		getline(cin, s);
		stringstream sstr(s);

		int n;
		int one_count = 0, pts = 0;
		sstr >> n;
		if(n == 0)
			break;
		do {
			if(n == 1)
				one_count++;
			else if(n < 10)
				pts += n;
			else
				pts += 10;
		} while(sstr >> n);

		int ret = pts + one_count;
		ret = ret <= 21 ? ret : 0;
		for(int i = 0; i <= one_count; i++) {
			int tmp;
			tmp = pts + i + 11 * (one_count - i);
			tmp = tmp <= 21 ? tmp : 0;

			ret = ret > tmp ? ret : tmp;
		}

		cout << ret << endl;
	}
}

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

int main(){
  string str;
  while(getline(cin,str) && str != "0"){
    int ans = 0, one = 0;
    for(int i = 0 ; i < str.size() ; i++){
      if(str[i] == ' ') continue;
      else{
	if(str[i] == '1'){
	  if(str[i+1] >= '0'){
	    ans += 10;
	    i++;
	  }
else one++, ans++;
	}
	else ans += str[i] - '0';
      }
    }
    for(int i = 0 ; i < one ; i++){
      if(ans + 10 <= 21) ans += 10;
    }
    if(ans > 21) ans = 0;
    cout << ans << endl;
  }
  return 0;
}

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

int rec(int sum, const vector<int> &v, int k) {
  if(v.size() > 21) return 0;
  if(k == v.size()) return sum <= 21 ? sum : 0;
  if(v[k] == 1) return max(rec(sum+1, v, k+1), rec(sum+11, v, k+1));
  else return rec(sum+v[k], v, k+1);
}

int main() {
  string s;
  while(getline(cin,s) && s != "0") {
    stringstream ss(s);
    int a;
    vector<int> v;
    while(ss >> a) {
      v.push_back(min(a,10));
    }
    cout << rec(0, v, 0) << endl;
  }
  return 0;
}

C++: #include<stdio.h>
#include<stdlib.h>
int main()
{
	char str[256],*p,*np;
	while(fgets(str,256,stdin),str[0]!='0')
	{
		int s=0,l,c1=0;
		for(p=str;;)
		{
			l=strtol(p,&np,10);
			if(p==np)break;
			p=np;
			s+=l;
			c1+=(l==1);
		}
		while(s<=11&&c1)s+=10,--c1;
		printf("%d\n",(s>21?0:s));
	}
	return 0;
}