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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  string s;
  while (getline(cin, s), s != "0") {
    istringstream ss(s);
    int x;
    int t = 0, one = 0;
    while (ss >> x) {
      if (x == 1) one++;
      if (2 <= x && x <= 9) t += x;
      if (10 <= x && x <= 13) t += 10;
    }
    while (t + 11 + one - 1 <= 21 && one) {
      t += 11;
      one--;
    }
    t += one;
    cout << (t > 21 ? 0 : t) << endl;
  }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

vector<string> Split(char c,string s){
  vector<string> res(0);
  string str = "";
  rep(i,s.size()){
    if(s[i] == c){
      res.push_back(str);
      str.clear();
    }
    else{
      str += s[i];
    }
  }
  res.push_back(str);
  return res;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(getline(cin,s)){
    if(s[0] == '0') break;
    auto ss = Split(' ',s);
    vector<int> v(ss.size());
    int one = 0;
    rep(i,v.size()){
      v[i] = ston(ss[i],1);
      v[i] = (v[i]>10)?10:v[i];
      if(v[i] == 1){
        ++one;
      }
    }
    sort(all(v),greater<int>());
    int sc = 0;
    bool f = true;
    rep(i,v.size()){
      if(v[i] != 1){
        sc += v[i];
        if(sc > 21){
          sc = 0;
          f = false;
          cout << sc << endl;
          break;
        }
      }
    }
    if(f){
      if(one >= 2 || sc > 10){
        sc += one;
      }
      else{
        sc += one * 11;
      }
      if(sc > 21){
        sc = 0;
      }
      cout << sc << endl;
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int power(int n)
{
    int num=1;
    for(int i=0;i<n;i++)num*=10;
    return num;
}
int serch(int sum,int n)
{
    if(sum>21)return 0;
    else if(n==0)return sum;
    else return max(serch(sum+11,n-1),serch(sum+1,n-1));
}
int main()
{
    string str;
    while(getline(cin,str)){
        if(str[0]=='0')break;
        int card[20]={},co=0,point=0;
        for(int i=0;;i++){
            if(str[i]==' '||str[i]=='\0'){
                for(int j=point;j<i;j++)card[co]+=(str[j]-'0')*power(i-1-j);
                co++;point=i+1;
            }
            if(str[i]=='\0')break;
        }
        int cou=0,sum=0;
        for(int i=0;i<co;i++){
            if(card[i]==1)cou++;
            else if(card[i]<10)sum+=card[i];
            else sum+=10;
        }
        cout<<serch(sum,cou)<<endl;
    }
}

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

int main() {
    string s;
    while (getline(cin, s), s != "0") {
        stringstream ss(s);
        int n, sum = 0, one = 0;
        while (ss >> n) {
            sum += (10 <= n ? 10 : n);
            if (n == 1) ++ one;
        }
        int res = 0;
        for (int i=0; i<=one; ++i) {
            if (21 < sum + 10 * i) break;
            res = max(res, sum + 10 * i);
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include<stdio.h>

int main(void){
	int sum=0,card,one=0,i;
	char code;

	while(0==0){
		scanf("%d%c",&card,&code);
		if(card>10) card=10;
		else if(card==1) one++;

		sum+=card;

		if(code=='\n'){
			if(sum==0) break;
			else if(sum>21) sum=0;

			else if(one>0){
				for(i=0;i<one;i++)
					if(sum<=11) sum+=10;
				
				sum=0; one=0;
			}

			printf("%d\n",sum);
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

int MAX = 21;

int main()
{
    string s;
    int l, n, one = 0;

    while(getline(cin, s))
    {
        one = 0; n = 0;
        vector<int> ans;
        ans.push_back(0);

        if(s == "0") break;
        s += " ";
        int l = s.size();
        
        REP(l)if(s[i] != ' '){ n = n*10 + s[i] - '0';}
        else 
        {
            if(n == 1) one++;
            if(n >= 10) n =10;
            ans[0] += n;
            n = 0;
        }
        REP(one){ans.push_back( ans[i] + 10); }
        int maxp = 0;
        REP(ans.size())if(ans[i] > maxp && ans[i] <= MAX) maxp = ans[i];

        cout << maxp << endl;

    }
    return 0;
}