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 <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){
      while(one){
        if(sc + 11 + one-1 < 22){
          sc += 11;
          --one;
        }
        else{
          sc += 1;
          --one;
        }
      }

      if(sc > 21){
        sc = 0;
      }
      cout << sc << endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
	char num[1000];
	
	while (gets(num) != NULL){
		if (num[0] == '0'){
			break;
		}
		int score = 0;
		int f = 0;
		int i = 0;
		
		int len = strlen(num);
		
		while (i < len){
			if (num[i] == '1' && (num[i + 1] >= '0' && num[i + 1] <= '3')){
				score += 10;
				i += 3;
			}
			else if (num[i] == '1'){
				score++;
				f = 1;
				i += 2;
			}
			else if ('2' <= num[i] && num[i] <= '9'){
				score += (num[i] - '0');
				i += 2;
			}
		}
		if (score > 21){
			score = 0;
		}
		else if (f == 1 && score + 10 <= 21){
			score += 10;
		}
		cout << score << endl;
	}
	return (0);
}

C++: #include<stdio.h>

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

	while(0==0){
		sum=0; one=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+10<=21) sum+=10;
			printf("%d\n",sum);
		}
	}
	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)
					if (a[i][j])a[i + 1][stoi(t[i]) + j] = true;
				if (stoi(t[i]) == 1)
					if (a[i][j])a[i + 1][11 + j] = true;
				if (stoi(t[i]) >= 11)
					if (a[i][j])a[i + 1][10 + 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<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	string s;
	while (getline(cin, s), s != "0") {
		stringstream ss(s);
		int cnt = 0;
		int n;
		while (ss >> n) {
			if (n < 10)cnt += n;
			else cnt += 10;
		}
		if (cnt + 10 <= 21)cnt += 10;
		cout << (cnt > 21 ? 0 : cnt) << endl;
	}
}