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++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

//文字列分割
vector<int> split(string str, char del) {
	vector<int> re;
	string sub;
	for (char c : str) {
		if (c == del) {
			re.push_back(stoi(sub));
			sub.clear();
		}
		else {
			sub += c;
		}
	}
	re.push_back(stoi(sub));
	return re;
}

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

		VI a = split(s, ' ');
		int sum = 0, cnt1 = 0;
		for (auto n : a) {
			if (2 <= n && n <= 9)sum += n;
			else if (10 <= n && n <= 13)sum += 10;
			else if (n == 1 || n == 11)cnt1++;
		}
		int ans = -1;
		rep(i, cnt1 + 1) {
			int x = sum + 1 * i + 11 * (cnt1 - i);
			x = x > 21 ? 0 : x;
			ans = max(ans, x);
		}
		Cout(ans);
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

int main()
{
	string str = "";
	vector < vector <int> > hand;

	while (getline (cin, str ) ){
		if (str.length() == 1 && str[0] == '0'){
			break;
		} // end if

		int n;
		stringstream ss(str);
		vector <int> card;

		while (ss >> n){
			card.push_back (n );
		} // end while

		hand.push_back(card );

	} // end loop

	for (int i = 0; i < hand.size(); ++i){

		vector <int>::iterator it = hand[i].begin();
		int ace = 0;
		int sum = 0;

		for (; it != hand[i].end(); ++it ){
			if ((*it) == 1 ){
				++ace;
			}else if ((*it) >= 10){
				sum += 10;
			}else{
				sum += (*it);
			} // end if
		} // end for

		if (ace == 4){
			sum += 4;
		}else if (ace == 3){
			if (sum == 0){
				sum = 21;
			}else{
				sum += 3;
			} // end if
		}else if (ace == 2){
			if (sum <= 9){
				sum += 12;
			}else{
				sum += 2;
			} // end if
		}else if (ace == 1){
			if (sum <= 10){
				sum += 11;
			}else{
				sum += 1;
			} // end if
		} // end if
		
		if (sum <= 21){
 			cout << sum << endl;
		}else{
			cout << '0' << endl;
		} // end if

	} // end for

	return 0;
}

C++: #include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
/** Problem0169 : Blackjack **/
int main()
{
	int ans, one, t;
	string s;
	
	while (!cin.eof()) {
		getline(cin, s);
		if (s == "0") break;
		stringstream ss(s);
		ans=0; one=0;
		while (!ss.eof()) {
			ss >> t;
			ans += t;
			if (ans > 21 && one>0) {
				ans -= 10;
				one--;
			}
		}
		if (ans > 21) ans=0;
		cout << ans << endl;
	}
	return 0;
}

C++: #define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
using namespace std;
int main(){
	
	string s;
	
	while(1){
		getline(cin,s);
		long long n=0;
		int	count=0;
		if(s=="0")
			break;
		else{
			string a="";
			for(int i=0;i<s.size();i++){
				if(s[i]!=' '){
					a=a+s[i];
				}
				else{
					int b=stoi(a);
					if(b==1)
						count+=11;
					else if(b>=2&&b<=9)
						n+=b;
					else
						n+=10;
					a="";
				}
			}
			int b=stoi(a);
					if(b==1)
						count+=11;
					else if(b>=2&&b<=9)
						n+=b;
					else
						n+=10;
					a="";
			while(count>0){
				if(n+count>21)
					n++;
				else
					n=n+11;
				count-=11;
			}
			
			if(n>21)
				cout<<0<<endl;
			else
				cout<<n<<endl;
		}
	}
	
	
	
	

}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
vector<int>input(string s) {
	vector<int>ret;
	int k = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == ' ') {
			ret.push_back(min(k, 10));
			k = 0;
		}
		else {
			k *= 10;
			if (s[i] == '1')k += 1;
			else if (s[i] == '2')k += 2;
			else if (s[i] == '3')k += 3;
			else if (s[i] == '4')k += 4;
			else if (s[i] == '5')k += 5;
			else if (s[i] == '6')k += 6;
			else if (s[i] == '7')k += 7;
			else if (s[i] == '8')k += 8;
			else if (s[i] == '9')k += 9;
			else if (s[i] == '0')k += 0;
		}
	}
	ret.push_back(min(k, 10));
	return ret;
}
int main() {
	string s;
	while (getline(cin, s)) {
		if (s == "0")return 0;
		vector<int>v = input(s);
		int cnt1 = 0;
		int cnt = 0;
		for (int i = 0; i < v.size(); i++) {
			if (v[i] == 1)cnt1++;
			else cnt += v[i];
		}
		int ans = 0;
		cnt += cnt1;
		if (cnt <= 21)ans = cnt;
		for (int i = 0; i < cnt1; i++) {
			cnt += 10;
			if (cnt <= 21)ans = max(ans, cnt);
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){

  int n;
  char c;
  int sum = 0;
  vector<int> V;

  while(1){
    scanf("%d%c",&n,&c);
    if(n == 0) break;
    
    V.push_back(n);
    if(c == '\n'){
      int first = 0;
      for(int i = 0; i < V.size(); i++){
	if(V[i] > 10 && V[i] <= 13 ) V[i] = 10;

	if(V[i] != 1) sum += V[i];
	else first++;
      }

      if(first > 0){
	int leaves = 21;
	leaves -= sum;
	leaves -= first;
	
	for(int i = 0; i < first;i++){
	  if(leaves >= 10) leaves -= 10;
	}
	sum = 21-leaves;

      } 
      if(sum > 21) sum = 0;
    }else{
      continue;
    }
    cout << sum << endl;
    sum = 0;
    V.clear();
  }

  return 0;
}

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

using namespace std;

int main(int argc, char const* argv[])
{
	vector<int> data;
	char str[30];

	while( cin.getline( str, 30 ) && str[0] != '0' ){
		char *t;
		data.clear();
		t = strtok( str, " " );
		data.push_back( atoi( t ) );
		while( ( ( t = strtok( NULL, " " ) ) != NULL ) ){
			data.push_back( atoi( t ) );
		}

		int answer;
		int count;

		answer = 0;
		count = 0;

		for( int i = 0;i < data.size();i++ ){
			if( data[i] >= 10 ) answer += 10;
			else answer += data[i];
			if( data[i] == 1 ) count++;
		}
		if( answer > 21 ) answer = 0;
		if( answer <= 11 ){
			for( int i = 0;i < count;i++ ){
				if( answer + 10 > 21 ) break;
				answer += 10;
			}
		}
		cout << answer << endl;
	}
	return 0;
}