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;
int main(){
  string s;
  while(getline(cin,s),s!="0"){
    stringstream ss(s);
    int x=0,i,ans,k;
    int si=0;
    vector<int> v;
    v.clear();
    v.push_back(0);
    
    while(ss>>x){
      si=v.size();
      vector<int> n;
      for(i=0;i<si;i++){
	
	if(x==1){
	  k=v[i];
	  n.push_back(k+11);
	  v[i]++;
	}else if(x>10){
	  v[i]+=10;
	}else {
	  v[i]+=x;
	}
	
      }
      for(i=0;i<n.size();i++) v.push_back(n[i]);
      n.clear();
    }
    
    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<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  string s;
  while(getline(cin,s),s.size()!=1||s[0]!='0'){
    vector<int>num;
    rep(i,s.size()){
      int tmp=0;
      while(s[i]!=' '){
	tmp*=10;
	tmp+=s[i]-'0';
	i++;
	if(i==s.size())break;
      }
      if(tmp)num.pb(tmp);
    }
    //cout<<num[0]<<endl;
    int sum=0;
    int one=0;
    rep(i,num.size()){
      if(num[i]>10)num[i]=10;
      if(num[i]==1)one++;
      sum+=num[i];
    }
    rep(i,one){
      if(sum+10<=21)sum+=10;
    }
    if(sum>21)sum=0;
    cout<<sum<<endl;
  }


}

C++: #include <bits/stdc++.h>

using namespace std;

int main() {
  
  while(1) {
    int card = 0;
    int save = 0;
    for(;;) {
      int add; scanf("%d", &add); if(!add) return 0;
      if(add == 1) {
	save ++;
      }
      else if(10 <= add && add <= 13) card += 10;
      else card += add;
      
      char ch; scanf("%c", &ch);
      if(ch=='\n') break;
    }
    
    card += save;
    
    if(card > 21) {
      card = 0;
    }
    else {
      for(int i=0; i<save; i++) {
	if(card+10 <= 21) card += 10;
	else break;
      }
    }
    
    if(card > 21) card = 0;
    cout << card << 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);
		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){
			ans += 11;
		}
		else{
			ans += one;
		}
		printf("%d\n",ans%22);
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#define int long long
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;
}
signed main() {
	string a;
	while (1) {
		getline(cin, a);
		if (a == "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)m += 10;
			else if (s[d] > 1)m += s[d];
			else n++;
		}
		if (m + 10 + n < 22)m += 10 + n;
		else m += n;
		if (m > 21)m = 0;
		cout << m << endl;
	}
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <stdlib.h>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;
int max_point = 0;
bool ok_flag = false;

void recursive(int sum, int pos, vector<int>& card)
{
	if(sum > 21)
	{
		return;
	}
	if(pos == card.size())
	{
		if(max_point < sum)
		{
			ok_flag = true;
			max_point = sum;
			return;
		}
	}
	recursive(sum + 1, pos + 1, card);
	recursive(sum + 11, pos + 1, card);
}

void solve()
{
	string str;
	while(getline(cin, str))
	{
		if(str == "0")
		{
			break;
		}
		max_point = 0;
		stringstream ss(str);
		string temp;
		vector<int> card;
		while(ss >> temp)
		{
			card.push_back(atoi(temp.c_str()));
		}
		sort(card.begin(), card.end(), greater<int>());
		int sum = 0;
		int one_pos = -1;
		for(int i = 0; i < card.size(); ++i)
		{
			if(card[i] >= 10)
			{
				sum += 10;
			}
			else if(card[i] >= 2)
			{
				sum += card[i];
			}
			else
			{
				one_pos = i;
				break;
			}
		}
		if(sum > 21)
		{
			cout << 0 << endl;
			continue;
		}
		if(max_point < sum && one_pos == -1)
		{
			max_point = sum;
			cout << max_point << endl;
			continue;
		}
		
		ok_flag = false;
		recursive(sum, one_pos, card);
		if(ok_flag)
		{
			cout << max_point << endl;
		}
		else
		{
			cout << 0 << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

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

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int main() {
	while (true) {
		string str;
		getline(cin, str);
		int n = count(str.c_str(), str.c_str() + str.size(), ' ') + 1;
		vector<int> card(n);
		stringstream ss(str);
		REP(i, n) ss >> card[i];
		if (card[0] == 0) break;
		
		sort(card.begin(), card.end());
		int c = count(card.begin(), card.end(), 1);
		
		int score = 0;
		FOR(i, c, n) {
			if (card[i] > 10) score += 10;
			else score += card[i];
		}
		
		while (c--) {
			if (score + 11 > 21)
				score += 1;
			else if (abs(21 - (score + 1)) > abs(21 - (score + 11))) {
				if (score + 11 <= 21 - c)
					score += 11;
				else
					score += 1;
			}
			else
				score += 1;
		}
		if (score > 21) score = 0;
		
		cout << score << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    string in;  
 
    while (getline(cin, in), in != "0") {
	stringstream s(in);
	int sum = 0, n;
	bool flg = false;
 
	while (s >> n) {
	    if (2 <= n && n <= 9) {
		sum += n;
	    } else if (n >= 10) {
		sum += 10;
	    } else {
		sum++;
		flg = true;
	    }
	}
 
	if (sum <= 11 && flg) {
	    sum += 10;
	} 
	if (sum > 21) {
	    cout << 0 << endl;
	} else {
	    cout << sum << endl;
	}
    }
    return 0;
}