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

int calc(int card[5], int score=0, int cnt=0) {
  static int max;
  if(cnt == 0) max = -1;

  if(cnt == 5) {
    if(score > 21) score = 0;
    if(score > max) max = score;
    return 0;
  }

  if(card[cnt] == 1) {
    calc(card, score+1, cnt+1);
    calc(card, score+11, cnt+1);
  } else if(card[cnt] > 11) {
    calc(card, score+10, cnt+1);
  } else {
    calc(card, score+card[cnt], cnt+1);
  }

  if(cnt == 0) return max;
}

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

    stringstream sin;
    sin << str;
    int card[5];
    fill(&card[0], &card[4]+1, 0);
    int num;
    for(int i = 0; i < 5; i++) {
      if(!(sin >> card[i])) {
	num = i;
	break;
      }
      if(i+1 == 5) {
	num = 5;
	break;
      }
    }

    cout << calc(card) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main(){
  

  char n,m;
  int a,c = 0,sum = 0,sw = 0;

  while(1){  
    while(1){
      scanf("%c",&n);
      if(n == '0' && sw == 0) break;
      if(n != ' ' && sw != 1 && n != '\n'){
	sw = 1;
	a = atoi(&n);
	continue;
      }
      else if(n!=' ' && sw == 1 && n !='\n'){
	sw = 0;
	a = a * 10 + atoi(&n);
	continue;
      }
      else if(n == ' '){
	sw = 0;
      }
  
      // cout << "a = " << a << endl;    

      if(a >= 2 && a <= 9) sum += a;
      if(a >= 10 && a <= 13 ) sum += 10;
      if(a == 1) {
	sum += a;
	c++;
      }
      if(n == '\n') break; 
    }
    if(n == '0' && sw == 0) break;

    for(int j = 0;j < c; j++){
      if(sum + 10 <= 21) sum += 10;
      else break;
    }

    if(sum <= 21) cout << sum << endl;
    else cout << '0' << endl;
    c=0;
    sum=0;
    sw = 0;
     
  }
 
}

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;

int main(){
  int n;
  char c;
  int ans,ace;
 
 while(1){
    ans = 0;
    ace = 0;
 
    while(1){
      c = getchar();
      if(c=='0')goto Loop;
      if(c=='\n')break;
      else if(c!=' '){
    n = c-'0';
    if(n==1){
      c = getchar();
      if(c=='\n'){
        ans += 1;
        ace = 1;
        break;
      }else if(c!=' '){
        ans += 10;
      }else{
        ans += 1;
        ace = 1;
      }
    }else{
      ans += n;
    }
      }
    }
 
    if(ans<12 && ace)ans+=10;
    if(ans>21)ans = 0;
    cout << ans << endl;
  }
 Loop:return 0;
}

C++: #include <iostream>
using namespace std;
int main()
{
	int n, p, t, i;
	while (1)
	{
		p = 0;
		t = 0;
		while (1)
		{
			cin >> n;
			if (n == 0) return 0;
			if (2 <= n && n <= 9)
				p += n;
			else if (n >= 10)
				p += 10;
			else
			{
				t++;
				p++;
			}
			if (cin.get() == '\n')
				break;
		}
		for (i = 0; i < t; i++)
		{
			if (p + 10 <= 21)
				p += 10;
		}
		if (p > 21)
		{
			p = 0;
		}
		cout << p << endl;
	}
}

C++: #include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;

int main(){
  

  char n,m;
  int a,c = 0,sum = 0,sw = 0;

  while(1){  
    while(1){
      scanf("%c",&n);
      if(n == '0' && sw == 0) break;
      if(n != ' ' && sw != 1 && n != '\n'){
	sw = 1;
	a = atoi(&n);
	continue;
      }
      else if(n!=' ' && sw == 1 && n !='\n'){
	sw = 0;
	a = a * 10 + atoi(&n);
	continue;
      }
      else if(n == ' '){
	sw = 0;
      }
  
      cout << "a = " << a << endl;    

      if(a >= 2 && a <= 9) sum += a;
      if(a >= 10 && a <= 13 ) sum += 10;
      if(a == 1) {
	sum += a;
	c++;
      }
      if(n == '\n') break; 
    }
    if(n == '0' && sw == 0) break;

    for(int j = 0;j < c; j++){
      if(sum + 10 <= 21) sum += 10;
      else break;
    }

    if(sum <= 21) cout << sum << endl;
    else cout << '0' << endl;
    c=0;
    sum=0;
    sw = 0;
     
  }
 
}

C++: #include<stdio.h>
#include<iostream>
using namespace std;
int main(){
  int n,c,m;
  char w;
  while(1){
    m=0;
    c=0;
    while(1){
      scanf("%d%c",&n,&w);

	if(n==1){
	  m+=1;
	  c+=11;
	}
	else if(n>10)c+=10;
	else c+=n;
      if(w=='\n')break;
    }

    while(m!=0){
      if(c>21){
	m--;
	c-=10;
      }
      else break;
    }
    if(c<22)cout << c << endl;
    else cout<< "0"<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
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;
}
int main() {
	string a;
	while (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++;
		}
		int f = ((21 - m) - n) / 10;
		if (f > n)f = n;
		m += f * 11 + (n - f);
		if (m > 21)m = 0;
		cout << m << endl;
	}
}

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

using namespace std;

vector<int> nums;

vector<string> split(string str, string delim)
{
	int pos = 0;
	vector<string> vec;
	while((pos=str.find_first_of(delim)) != str.npos)
	{
		if(pos > 0)
		{
			vec.push_back(str.substr(0, pos));
		}
		str = str.substr(pos + 1);
	}

	if(str.length() > 0)
	{
		vec.push_back(str);
	}

	return vec;
}

void solve()
{
	int sum = 0;
	int c = 0;
	for(int i=0; i<nums.size(); i++)
	{
		if(nums[i]>=10) sum += 10;
		else if(nums[i] != 1) sum += nums[i];
		else sum += 11, c++; 
	}

	for(int i=0; i<c; i++)
	{
		if(sum > 21) sum -= 10;
		else break;
	}
	sum = sum > 21 ? 0 : sum;
	cout << sum << endl;
}

int main(int argc, char** argv)
{
	string s;
	vector<string> vec;
	while(getline(cin, s) && s!="0")
	{
		vec = split(s, " ");
		nums.clear();
		for(int i=0; i<vec.size(); i++)
		{
			nums.push_back(atoi(vec[i].c_str()));
		}
		solve();
	}
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

vector<int> split(string s){
    if(s.size()==1) return vector<int>(1,stoi(s));
    vector<int> ret;
    int x = -1;
    REP(i,s.size()){
	if(s[i] == ' '){
	    ret.PB(stoi(s.substr(x+1,i-x-1)));
	    x = i;
	}
    }
    ret.PB(stoi(s.substr(x+1,s.size()-x)));
    return ret;
}

int main(){
    while(true){
	string s;
	getline(cin,s);
	if(s == "0") break;
	vector<int> c = split(s);
	int ans = 0;
	bool flg = false;
	REP(i,c.size()){
	    if(c[i] >= 10) ans += 10;
	    else ans += c[i];
	    if(c[i]==1) flg = true;
	}
	if(ans <= 11 && flg) ans += 10;
	if(ans > 21) ans = 0;
	cout << ans << endl;
    }
    return 0;
}