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

int main()
{
  string s;
  while (getline(cin, s)) {
    if (s.find_first_of("\n") != string::npos)
      s.erase(s.end()-1);
    if (s.find_first_of("\r") != string::npos)
      s.erase(s.end()-1);

    if (s == "0")
      break;

    istringstream iss(s);
    int one = 0, sum = 0;
    while (!iss.eof()) {
      int num;
      iss >> num;

      if (num == 1)
	++one;
      else if (num >= 10)
	sum += 10;
      else
	sum += num;
    }

    int ans = sum;
    if (sum > 21)
      ans = 0;

    for (int i = 0; i <= one; ++i) {
      int p = i + (one-i)*11 + sum;
      if (p > 21)
	p = 0;
      ans = max(ans, p);
    }

    cout << ans << 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 <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);
		vi num;
		stringstream ss(str);
		int tmp;
		while(ss >> tmp){
			num.PB(tmp);
		}
		if(num[0] == 0)break;
		int one = 0;
		int ans = 0;
		rep(i,num.size()){
			if(num[i]==1)one++;
			else{
				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;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  while (getline(cin, s), s != "0") {
    stringstream ss;
    ss << s;
    int sum = 0, one = 0, a;
    while (ss >> a) {
      if (a == 1) one++;
      else sum += min(10, a);
    }
    if (one > 21 || sum > 21 || one + sum > 21) {
      cout << 0 << endl;
    } else {
      int p = (11 * one + sum - 21 + 10 - 1) / 10;
      cout << p + (one - p) * 11 + sum << endl;
    }
  }

  return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<stack>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

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

int main(void){
  string str;
  while(getline(cin,str),str!="0"){
    int a,b,c;  a = b = c = 0;
    bool one = false;
    int sum = 0;
    for(int i = 0 ; i < str.size() ; i ++){
      if(str[i]==' ')continue;
      //--
      if(str[i] == '1') {
	if(str[i+1] == ' '){
	  one = true;
	  sum ++;
	}else if(str[i+1]=='\0'){
	  one = true;
	  sum ++;
	}else {
	  sum += 10;
	  i++;
	}
      }
      //--

      else{
	sum += str[i] - '0';
      }

    }
    if(one && sum + 10 <= 21) sum += 10;
    //cout<<sum<<endl;
    cout<<(sum<=21?sum:0)<<endl;
  }
}