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<string>
using namespace std;
string S; int p[11];
char V[11] = "0123456789";
int main() {
	while (true) {
		S = "";
		while (S == "") {
			getline(cin, S);
		}
		if (S == "0") { break; }
		S += ' '; string T = "";
		for (int i = 0; i < 11; i++) { p[i] = 0; }
		for (int i = 0; i < S.size(); i++) {
			if (S[i] == ' ') {
				if (T.size() >= 2) { p[10]++; }
				else {
					for (int j = 1; j < 10; j++) {
						if (V[j] == T[0]) { p[j]++; }
					}
				}
				T = "";
			}
			else {
				T += S[i];
			}
		}
		int sum = 0;
		for (int i = 0; i < 11; i++) { sum += p[i] * i; }
		if (sum <= 11 && p[1] >= 1) { sum += 10; }
		if (sum >= 22) { sum = 0; }
		cout << sum << endl;
	}
	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;
}

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)
					a[i + 1][stoi(t[i]) + j] |= a[i][j];
				if (stoi(t[i]) == 1)
					a[i + 1][11 + j] |= a[i][j];
				if (stoi(t[i]) >= 11)
					a[i + 1][10 + j] |= a[i][j];
			}
		}
		rrep(i, 0, 22) {
			if (a[t.size()][i]) {
				cout << i << endl;
				break;
			}
			if (i == 0)cout << 0 << endl;
		}
	}
	return 0;
}

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

using namespace std;

int main()
{
	char buf[512];
	while (cin.getline(buf, sizeof(buf)), *buf != '0')
	{
		stringstream ss(buf);
		int total = 0;
		int one = 0;
		int c;
		while (ss >> c)
		{
			if (c == 1)
			{
				total += 11;
				++one;
			}
			else if (c >= 10)
				total += 10;
			else
				total += c;
		}
		while (total > 21 && one--)
			total -= 10;

		if (total <= 21)
			printf("%d\n", total);
		else
			puts("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);

		pts = pts <= 21 ? pts : 0;

		int ret = pts + one_count;
		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<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){
	  k=v[i];
	  v.push_back(k+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<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<stdio.h>
#include<vector>
#include<algorithm>

using namespace std;

int main(){

  int n;
  char c;
  int sum = 0;
  vector<int> V;

  while(1){
    scanf("%d%c",&n,&c);
    if(n == 0) break;
    
    V.push_back(n);
    if(c == '\n'){
      int first = 0;
      for(int i = 0; i < V.size(); i++){
	if(V[i] >= 10) V[i] = 10;
	if(V[i] != 1) sum += V[i];
	else first++;
      }

      if(sum+first*11 < 22) sum += first*11;
      else sum += first;

      if(sum > 21) sum = 0;
    }else continue;
    cout << sum << endl;
    sum = 0;
    V.clear();
  }

  return 0;
}

C++: #include<iostream>
#include<string>
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]!=' '){
				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<22)ans+=10;
		}
		if(ans>21)ans=0;
		cout << ans << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	string str;
	while(true){
		getline(cin,str);
		if(str.size() == 1 && str[0] == '0')break;
		vi num;
		stringstream ss(str);
		int tmp;
		while(ss >> tmp){
			num.PB(tmp);
		}
		sort(num.begin(),num.end());
		int one = 0;
		int ans = 0;
		rep(i,num.size()){
			if(num[i]==1)one++;
			if(num[i] > 1){
				if(num[i] > 9){
					ans+=10;
				}
				else{
					ans+=num[i];
				}
			}
		}
		if(one == 1){
			if(ans+11<22)ans += 11;
			else ans++;
		}
		else{
			ans += one;
		}
		if(ans >= 22)ans = 0;
		printf("%d\n",ans);
    }
    return 0;
}