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<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int main() {
	int n;
	char c;
	int s=0,o=0;
	while(scanf("%d%c",&n,&c),n){
		if(n==1)o++;
		if(n>=10)s+=10;
		else s+=n;
		if(c!=32){
			if(s>21)cout<<0<<endl;
			else{
				if(o&&s<=11)cout<<s+10<<endl;
				else cout<<s<<endl;
			}
			s=o=0;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
int t[10000],size,sum;
char ch;
int main(){
  while(cin>>t[0]&&t[0]!=0){
    size=1;
    while(1){
      scanf("%c",&ch);
      if(ch=='\n')break;
      cin>>t[size++];
    }
    sort(t,t+size);
    sum=0;
    for(int i=size-1;i>=0;i--){
      if(t[i]!=1)sum+=min(t[i],10);
      else{
	if(sum+11+i<=21)sum+=11;
	else sum++;
      }
    }
    cout<<(sum<=21?sum:0)<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int n;
string st;

int main(){
	while(getline(cin,st)){
		if(st=="0")return 0;
		int cur=0,p=0,one=0,s=0;
		while(cur<st.size()){
			if(isdigit(st[cur]))p=p*10+st[cur]-'0';
			if(st[cur]==' '){
				if(p==1)one++;
				if(p>10)s+=10;
				else s+=p;
				p=0;
			}
			cur++;
		}
		if(p==1)one++;
		if(p>10)s+=10;
		else s+=p;
		if(s>21)cout<<0<<endl;
		else{
			if(s<12&&one)cout<<s+10<<endl;
			else cout<<s<<endl;
		}
	}
}

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

int main(){
  
  while(1){
    int n=0,card[100]={};
    string str;
    getline(cin,str);
    str+=' ';
    for(int i=0,num=0;i<str.size();i++){
      if(isdigit(str[i]))num=num*10+str[i]-'0';
      else card[n++]=num,num=0;
    }
    if(card[0]==0)break;
    sort(card,card+n,greater<int>());
    int score=0;
    for(int i=0;i<n;i++){
      if(card[i]>=10)score+=10;
      else if(card[i]>1)score+=card[i];
      else if(score+11+(n-i-1)<=21)score+=11;
      else score++;

    }
    cout <<(score<=21? score:0)<<endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <utility>
#include <cctype>
#include <algorithm>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

int main() {
	for (;;) {
		int r {}, o {};
		do {
			int n;
			scanf("%d", &n);
			if (n > 1)
				r += min(10, n);
			else if (n == 1)
				o++;
			else
				return 0;
		} while (gcu() != '\n');
		if (o > 0)
			r += (r += o - 1) + 11 <= 21 ? 11 : 1;
		outl(r > 21 ? 0 : r);
	}
}

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

int main(void)
{
	char c;
	int num;

	while(true){
		int x = 0;
		int one = 0;
		int sum = 0;
		while(scanf("%d", &num)){
			if(num > 10)
				num = 10;
			if(num == 1)
				one++;
			else
				sum += num;

			scanf("%c", &c);
			if(c == '\n')
				break;
		}
		if(num == 0 && one == 0)
			break;

		if(sum > 21)
			cout << 0 << endl;
		else {
			if(one > 0){
				if(sum + 11 + (one-1) <= 21)
					cout << sum + 11 + (one-1) << endl;
				else if(sum + one <= 21)
					cout << sum + one << endl;
				else
					cout << 0 << endl;
			}
			else
				cout << sum + one << 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;
     
  }
 
}