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 Parse(string a) {
	int s = 0;
	for (int b = 0; b < a.length(); b++) {
		s *= 10;
		s += a[b] - 48;
	}
	return s;
}
int main() {
	string a;
	while (1) {
		getline(cin, a);
		if (a == "0")break;
		vector<int>s;
		string c="";
		for (int b = 0; b < a.length(); b++) {
			if (a[b] == ' ') { s.push_back(Parse(c)); c = ""; }
			else c += a[b];
		}
		s.push_back(Parse(c));
		int m = 0;
		int n = 0;
		for (int d = 0; d < s.size(); d++) {
			if (s[d] > 9)m += 10;
			else if (s[d] > 1&&s[d]<10)m += s[d];
			else n++;
			if (m > 21) { cout << 0 << endl; goto l; }
		}
		if (m + 10 + n < 22)m += 10 + n;
		else m += n;
		if (m > 21)m = 0;
		cout << m << endl;
	l:;
	}
}

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


		pts = pts <= 21 ? pts : 0;

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

			pts = pts > tmp ? pts : tmp;
		}

		cout << pts << endl;
	}
}

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

int main(){
  int n;
  char c;
  int ans,ace;

 while(1){
    ans = 0;
    ace = 0;

    while(1){
      c = getchar();
      if(c=='0')goto Loop;
      if(c=='\n')break;
      else if(c!=' '){
	n = c-'0';
	if(n==1){
	  c = getchar();
	  if(c=='\n'){
	    ans += 1;
	    ace = 1;
	    break;
	  }else if(c!=' '){
	    ans += 10;
	  }else{
	    ans += 1;
	    ace = 1;
	  }
	}else{
	  ans += n;
	}
      }
    }

    if(ans<12 && ace)ans+=10;
    if(ans>21)ans = 0;
    cout << ans << endl;
  }
 Loop:return 0;
}

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

int rec(int sum, const vector<int> &v, int k) {
  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<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;
a.clear();
				}
			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-1][j];
				dp[i][min(22,j+11)]=dp[i-1][j];
				}
			}
			
		int ans=0;
		for(int i=0;i<22;i++){
			if(dp[one][i]>0)ans=i;
			}		
		cout<<ans<<endl;	
		}
	return 0;
	}

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

int main()
{
	string str;
	while(getline(cin, str)){
		if(str[0] == '0')
			break;
		stringstream sst;
		sst << str;
		int a;
		int sum = 0;
		int onecount = 0;
		while(sst >> a){
			if(a == 1){
				sum += 1;
				onecount++;
			}
			else if(a > 10){
				sum += 10;
			}else{
				sum += a;
			}
		}
		if(sum > 21)
			sum = 0;
		else{
			while(true){
				if(sum+10 <= 21 && onecount!=0){
					sum += 10;
					onecount--;
				}
				else
					break;
			}
		}
		cout << sum << endl;
	}
	return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
int main(){
    string s;
    while(getline(cin,s)){
        if(s=="0") break;
        stringstream ss;
        vector<int> a;
        int n,f=0,sum=0;
        ss<<s;
        while(ss>>n){
            if(n==1)f=1;
            a.push_back((n>=10)?10:n);
            if(ss.eof()) break;
        }
        for(int i=0;i<a.size();++i) sum+=a[i];
        if(f&&sum<=11) sum+=10;
        if(sum>21)cout<<0<<endl;
        else cout<<sum<<endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(getline(cin,s),s!="0"){
    stringstream ss(s);
    int x=0,i,ans;
    int si=0;
    vector<int> v;
    v.clear();
    v.push_back(0);
    
    while(ss>>x){
      si=v.size();
      for(i=0;i<si;i++){
	
	if(x==1){
	  v.push_back(v[i]+11);
	  v[i]++;
	}else if(x>10){
	  v[i]+=10;
	}else {
	  v[i]+=x;
	}
	
      }
    }
    
    sort(v.begin(),v.end());
    ans=0;
    for(i=0;i<v.size();i++){
      if(v[i]<=21) ans=v[i];
    }
    cout << ans << endl;
    s="";
  }  
  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<bits/stdc++.h>
using namespace std;

int stoi(string a){
	int ret;
	stringstream ss;
	ss<<a;
	ss>>ret;
	return ret;
	}

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;
				a.clear();
				}
			else a.push_back(s[i]);
			}
			sum+=one;
			for(int i=0;i<one;i++){
				if(sum<12)sum+=10;
				}	
				
			if(sum>21)sum=0;	
			cout<<sum<<endl;	
		}
	return 0;
	}