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: 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) + 10 * (i+1) > 21:
            print('test', ans)
            break
        elif ans < sum(cards) + 10 * (i+1):
            print('test2', ans)
            ans = sum(cards) + 10 * (i+1)

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

Python: while 1:
    C = list(map(int,input().split()))
    if(C == [0]):
        break
    ans = [False]*22
    ans[0] = True
    for c in C:
        l = [min(c,10)]
        if(c == 1):
            l.append(11)
        ans_ = [False]*22
        for i in range(21,-1,-1):
            if not ans[i]:
                continue
            for a in l:
                if i+a > 21:
                    continue
                ans_[i+a] = True
        ans = ans_
    A = 0
    for i in range(22):
        if not ans[i]:
            continue
        A = max(A,i)
    print(A)

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0169

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    while True:
        data = [int(x) for x in input().split()]
        if len(data) == 1 and data[0] == 0:
            break

        total = 0
        for d in data:
            if d > 10:
                total += 10
            else:
                total += d

        ace = data.count(1)
        for _ in range(ace):
            if total + 10 <= 21:
                total += 10

        if total > 21:
            total = 0

        print(total)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: def solve():
    c = list(map(int, input().split()))
    c = [min(10, e) for e in c]
    
    if c == [0]:
        return 1
    if len(c) > 21:
        print(0)
        return 0
    else:
        ans = 0
        for bit in range(1 << len(c)):
            s = 0
            for i in range(len(c)):
                if c[i] != 1:
                    s += c[i]
                else:
                    if bit >> i & 1:
                        s += 11
                    else:
                        s += 1
            if s <= 21:
                ans = max(ans, s)
        print(ans)
        return 0

def main():
    while solve() == 0:
        pass

if __name__ == '__main__':
    main()

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) + 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: while 1:
    hands = list(map(int, input().split()))
    if hands[0] == 0:
        break

    for i, hand in enumerate(hands):
        if hand > 10:
            hands[i] = 10

    if 1 in hands:
        cnt = hands.count(1)
        hands.sort(reverse=True)
        score = 0
        for hand in hands:
            if hand != 1:
                score += hand
            else:
                if score + cnt > 11:
                    score += 1
                    cnt -= 1
                else:
                    score += 11
                    cnt -= 1
    else:
        score = sum(hands)
    if score > 21:
        score = 0

    print(score)

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

Python: while True:
    ans = 0
    t = list(int(x) for x in input().split())
    if t[0] == 0:
        break
    for i in t:
        if i >= 11:
            ans += 10
        else:
            ans += i
    if 1 in t:
        if ans + 10 <= 21:
            ans += 10
    if ans > 21:
        ans = 0
    print(ans)

Python: while True : 
    A = list(map(int,input().split()))
    if A[0] == 0 : break
    cnt = 0 
    S = 0 
    for i in A : 
        S += min(i, 10) 
        if i == 1 : cnt += 1
    while cnt > 0 and S + 10 <= 21 : 
        cnt -= 1
        S += 10
    if S > 21 :
        S = 0
    print(S)

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(11, 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: while True:
    n=[int(i) for i in input().split(" ")]
    if n==[0]:
        break
    for i in range(len(n)):
        if n[i]>10:
            n[i]=10
    one=n.count(1)
    score=sum(n)
    while score<=11 and one>0:
        if one>0:
            score+=10
            one-=1
    if score>21:
        score=0
    print(score)

Python: # Aizu Problem 00169: Blackjack
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def blackjack(hand):
    hand = [min(h, 10) for h in hand]
    S = sum(hand)
    if S > 21:
        return 0
    C = hand.count(1)
    if C == 0:
        return S
    for k in range(C):
        C -= 1
        S += 10
        if S > 21:
            return S - 10
    return S

    
while True:
    hand = [int(_) for _ in input().split()]
    if len(hand) == 1 and hand[0] == 0:
        break
    print(blackjack(hand))

Python: while 1:
    a=list(map(int,input().split()))
    if a[0]==0:break
    b,c=0,0
    for i in a:
        if i>=10: b+=10
        else:b+=i
        if i==1:c+=1
    while c:
        if b+10<=21:b+=10
        c-=1
    print(0 if b>21 else b)

Python: 
while True:
    c = [int(x) for x in input().split()]
    if c[0] == 0:
        break
    L = []
    for i in c:
        if i > 10:
            L.append(10)
        else:
            L.append(i)

    p = []
    for  i in range(L.count(1)+1):
        t = sum(L) + 10 *i
        if t > 21:
            t =0
        p.append(t)

    print(max(p))

Python: while True:

    input_list = [int(item) for item in input().split(" ")]

    if input_list[0] == 0:
        break

    total = 0
    count = 0

    for num in input_list:
        if 10 < num:
            num = 10
        elif num == 1:
            count += 1

        total += num

        if 21 < total:
            break

    if total <= 21:

        while total + 10 <= 21 and 0 < count:
            total += 10
            count -= 1

        print(total)
    else:
        print(0)