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)
		}
	}
}

Python: while 1:
    *C, = map(int, input().split())
    if C == [0]:
        break
    s = 0
    C.sort(reverse=1)
    one = 0
    for c in C:
        if c == 1:
            s += 1
            one += 1
        elif c > 10:
            s += 10
        else:
            s += c
    while one and s + 10 <= 21:
        s += 10
        one -= 1
    if s > 21:
        s = 0
    print(s)

Python: # AOJ 0169 Blackjack
# Python3 2018.6.19 bal4u

while True:
	cs = list(map(int, input().split()))
	if cs[0] == 0: break
	sum, ace = 0, 0
	for c in cs:
		if c == 1:
			c = 0
			ace += 1
		elif c >= 10: c = 10
		sum += c
		if sum + ace > 21: break
	if sum+ace > 21: print(0)
	elif ace > 0 and sum+ace <= 11: print(sum+ace+10)
	else: print(sum+ace)

Python: import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


while True:

    table = list(map(int,input().split()))
    if len(table) == 1 and table[0] == 0:
        break

    num_1 = 0
    tmp_sum = 0
    for tmp in table:
        if tmp >= 11:
            tmp_sum += 10
        else:
            tmp_sum += tmp

        if tmp == 1:
            num_1 += 1

    if tmp_sum > 21:
        print(0)
    else:
        if num_1 == 0:
            print(tmp_sum)
        else:
            if tmp_sum <= 11:
                print(tmp_sum+10)
            else:
                print(tmp_sum)

Python: while True:
    inp = input()
    if inp == '0': break


    inp = inp.replace('11', '10')
    inp = inp.replace('12', '10')
    inp = inp.replace('13', '10')

    cards = tuple(map(int, inp.split()))
    ans = sum(cards)

    for i in range(cards.count(1)):
        if sum(cards) + 10 * (i+1) > 21:
            break
        elif ans < sum(cards) + 10 * (i+1):
            ans = sum(cards) + 10 * (i+1)

    if ans > 21: ans = 0
    print(ans)

Python: if input() == '1':
    pass

while True:
    inp = input()
    if inp == '0': break


    inp = inp.replace('11', '10')
    inp = inp.replace('12', '10')
    inp = inp.replace('13', '10')

    cards = tuple(map(int, inp.split()))
    ans = sum(cards)

    for i in range(cards.count(1)):
        if sum(cards) + 9 * (i+1) > 21:
            print('test', ans)
            break
        elif ans < sum(cards) + 9 * (i+1):
            print('test2', ans)
            ans = sum(cards) + 9 * (i+1)

    if ans > 21: ans = 0
    print(ans)

Python: from collections import Counter

def point(lst):
  counter = Counter(lst)
  acc = 0
  for i in range(2, 10):
    acc += i * counter[i]
  for i in range(10, 14):
    acc += 10 * counter[i]
  one_num = counter[1]
  for i in range(one_num + 1):
    if i + (one_num - i) * 11 + acc <= 21:
      acc += i + (one_num - i) * 11
      break
  else:
    acc += one_num
  if acc > 21:
    return 0
  else:
    return acc

while True:
  s = input()
  if s == "0":
    break
  lst = list(map(int, s.split()))
  print(point(lst))

Python: def f(ans, n):
    if ans > 21:
        return 0
    if n == 0:
        if ans + 11 <= 21:
            return ans + 11
        elif ans + 1 > 21:
            return 0
        else:
            return ans + 1
    else:
        return max(f(ans+1, n-1), f(ans+11, n-1))



while True:
    S = input()
    if S == "0":
        break

    N = [int(i) for i in S.split()]
    N.sort()
    N.reverse()

    ans = 0
    for i in range(len(N)):
        if N[i] == 1:
            ans = f(ans, len(N)-i-1)
            break
        elif N[i] >= 10:
            ans += 10
        else:
            ans += N[i]
    if ans > 21:
        print(0)
    else:
        print(ans)

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;
		}
	}
}

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

C++: #include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int ans,cnt,a;
	while(true){
		cin>>a;
		if(a==0)break;
		cnt=0,ans=0;
		if(a==1)cnt++;
		ans+=min(a,10);
		while(cin>>a){
			if(a==1)cnt++;
			ans+=min(a,10);
		}
		while(true){
			if(cnt==0||ans>11)break;
			ans+=10;
			cnt--;
		}
		if(ans>21)ans=0;
		cout<<ans<<endl;
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<algorithm>
#include<complex>
#include<stack>
using namespace std ;
typedef vector<int> vi ;
typedef vector<vi> vvi ;
typedef vector<string> vs ;
typedef pair<int, int> pii; 
typedef long long ll ;

#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define rep(i,a) loop(i,0,a)
#define all(a) (a).begin(),(a).end()

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int main(void){
  string str;
  while(getline(cin,str),str!="0"){
    int a,b,c;  a = b = c = 0;
    sscanf(str.c_str(), "%d %d %d", &a, &b, &c);
    //cout<<a<<" "<<b<<" "<<c<<endl;
    if(10<=a)a=10;  if(10<=b)b=10;  if(10<=c)c=10;
    int sum = a + b + c;
    if(sum < 11 && (a==1 || b ==1 || c == 1)) sum += 10;

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

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(getline(cin,s)){
    stringstream ss(s);
    int x;
    int s=0;
    vector<int> v;
    v.push_back(s);
    while(ss>>x){
      if(x==0) return 0;
      s=v.size();
      for(int i=0;i<s;i++){
	if(x==1){
	  v.push_back(v[i]+11);
	  v[i]++;
	}else if(x>10) v[i]+=10;
	else v[i]+=x;
      }
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<v.size();i++){
      if(v[i]<=21) ans=v[i];
    }
    cout << ans << endl;
  }  
  return 0;
}