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>
#include <sstream>
#include <algorithm>
using namespace std;

int calc(int card[54], int num, int score=0, int cnt=0) {
  static int max;
  if(cnt == 0) max = -1;

  if(cnt == num) {
    if(score > 21) score = 0;
    if(score > max) max = score;
    return 0;
  }

  if(card[cnt] == 1) {
    calc(card, num, score+1, cnt+1);
    calc(card, num, score+11, cnt+1);
  } else if(card[cnt] > 10) {
    calc(card, num, score+10, cnt+1);
  } else {
    calc(card, num, score+card[cnt], cnt+1);
  }

  if(cnt == 0) return max;
}

int main() {
  while(1) {
    string str;
    getline(cin, str);
    if(str == "0") break;

    stringstream sin;
    sin << str;
    int card[54];
    fill(&card[0], &card[53]+1, 0);
    int num;
    for(int i = 0; i < 54; i++) {
      if(!(sin >> card[i])) {
	num = i;
	break;
      }
      if(i+1 == 54) {
	num = 54;
	break;
      }
    }
    cout << calc(card, num) << endl;
  }
  return 0;
}

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

int main() {
    string line;
    while (getline(cin, line)){
        if (line.size() == 1 && line[0] == '0') {
            break;
        }
        int cards[11] = {};
        while (line.empty() == false) {
            size_t erase = 2;
            if (line.size() == 1 || line[1] == ' ') {
                cards[line[0] - '0']++;
            } else {
                cards[10]++;
                erase = 3;
            }
            line.erase(0, erase);
        }
        int result = 0;
        for (int i = 1; i < 11; i++) {
            result += i * cards[i];
        }
        while (cards[1] > 0) {
            if (result < 12) {
                result += 10;
                cards[1]--;
            } else {
                break;
            }
        }
        if (result > 21) {
            result = 0;
        }
        cout << result << endl;
    }
}

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)){
        stringstream ss(s);
        vector<int> v;
        int n;
        while(ss>>n){
            if(n==0) goto out;
            v.push_back(n);
        }
        cout << saiki(0,0,v) << endl;
    }
 out:
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<sstream>
#include<string>
#include<vector>
using namespace std;
int main(){
    string s;
    while(getline(cin,s)){
        stringstream ss(s);
        vector<int> V;
        int x;
        while(ss>>x){
            V.push_back(x);
        }
        if(V[0] == 0)break;
        int ans = 0;
        int num = 0;
        for(int i = 0;i < V.size();i++){
            if(V[i] == 1)ans += 1,num++;
            else if(V[i] > 9)ans += 10;
            else ans += V[i];
        }
        if(num>0 && ans<=11)ans += 10;
        if(ans > 21)ans = 0;
        cout<<ans<<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;
}
#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[1][stoi(t[i]) + j] = true;
				if (stoi(t[i]) >= 11)
					if (a[i][j])a[1][10 + j] = true;
				if (stoi(t[i]) == 1)
					if (a[i][j])a[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<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]=='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&&s[d]<14)m += 10;
			else if (s[d] > 1)m += s[d];
			else n++;
			if (m > 21) { cout << 0 << endl; goto l; }
		}
		if (m + 10 + n < 22&&n!=0)m += 10 + n;
		else m += n;
		if (m > 21)m = 0;
		cout << m << endl;
	l:;
	}
}

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

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

C++: #include <iostream>
#include <stdio.h>
using namespace std;
int main() {
 char c[256]; 
 int d[100],i,s,p,f;
 while(true) {
 for (i=0;i<255;i++) c[i]=1;
 i=p=0;
 gets(c);
 if (c[0]=='0') break;
 while(true) {
	 if (c[p+2]==' ' || c[p+2]=='\0') { d[i]=(c[p]-'0')*10+(c[p+1]-'0'); p+=3;}
	 else if (c[p+1]==' ' || c[p+1]=='\0') { d[i]=(c[p]-'0'); p+=2;}
	 if (c[p-1]=='\0') break;
	 i++;
 }
 for (s=0,f=0;i>=0;i--) if (d[i]>0 && d[i]<10) { s+=d[i]; if (d[i]==1) f=1;} else s+=10;
 if (s>21) s=0;
 if (f==1 && s+10<22) s+=10;
 cout << s << endl;
 }
 return 0;
 }

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

int main(){

  string s;

  while(true){
    getline(cin, s);
    if(s.size() == 1 && s[0] == '0') break;

    int k = 0, p = 0, ans = 0;
    for(int i=0;i<s.size();i++){

      if(s[i] == ' ') continue;

      p += s[i]-'0';

      if(i+1 != s.size() && s[i+1] != ' '){
	p *= 10;
	continue;
      }

      if(p > 10) ans += 10;
      else ans += p;

      if(p == 1) k++;
      p = 0;
    }

    while(k--){
      if(ans+10 < 22) ans += 10;
    }

    if(ans > 21) ans = 0;

    cout << ans << endl;

  }
}