Problem:


整数の和

0 から 9 の数字から異なる n 個の数を取り出して合計が s となる組み合わせの数を出力するプログラムを作成してください。n 個の数はおのおの 0 から 9 までとし、１つの組み合わせに同じ数字は使えません。たとえば、n が 3 で s が 6 のとき、3 個の数字の合計が 6 になる組み合わせは、

1 + 2 + 3 = 6

0 + 1 + 5 = 6

0 + 2 + 4 = 6

の 3 通りとなります。

Input

複数のデータセットが与えられます。各データセットに n (1 ≤ n ≤ 9) と s (0 ≤ s ≤ 100) が１つのスペースで区切られて１行に与えられます。n と s が共に 0 のとき入力の最後とします（この場合は処理せずにプログラムを終了する）。

データセットの数は 50 を超えません。

Output

各データセットに対して、n 個の整数の和が s になる組み合わせの数を１行に出力して下さい。

Sample Input

3 6
3 1
0 0

Output for the Sample Input

3
0



Sample input:
3 6
3 1
0 0


Sample output:
3
0

Submission status: Accepted

Solution code:

def dfs(n, m, s):
  if n == N:
    return 1 if s == S else 0
  ans = 0
  for i in range(m, 10):
    ans += dfs(n + 1, i + 1, s + i)
  return ans;

while 1:
  N, S = map(int, raw_input().split())
  if not N:
    break
  print dfs(0, 0, 0)

Submission status: Accepted

Solution code:
def dfs(n, m, s):
    if n == N:
        return 1 if s == S else 0
    ans = 0
    for i in range(m, 10):
        ans += dfs(n + 1, i + 1, s + i)
    return ans;

while True:
    N, S = map(int, raw_input().split())
    if not N:
        break
    print dfs(0, 0, 0)

Submission status: Accepted

Solution code:
def dec2bin(n, base=10):
    s = format(n,'b')
    s = "0"*(10-len(s))+s
    return s
 
x=[[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = dec2bin(i)
    s = 0
    c = B.count("1")
    j = 0
    for e in B:
        if e=="1": s+=j
        j+=1
    x[c][s]+=1

while 1:
    n, s=map(int, raw_input().split())
    if n==0 and s==0: break
    if s>=50: print 0
    else: print x[n][s]

Submission status: Accepted

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s,c = s+j, c+1
        j += 1
    x[c][s]+=1

while 1:
    n, s=map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Submission status: Accepted

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s,c = s+j,c+1
        j+=1
    x[c][s]+=1

while 1:
    n,s = map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Submission status: Accepted

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s+=j; c+=1
        j+=1
    x[c][s]+=1

while 1:
    n,s = map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Submission status: Accepted

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s+=j; c+=1
        j += 1
    x[c][s] += 1

while 1:
    n,s = map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Submission status: Accepted

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s=s+j; c=c+1
        j += 1
    x[c][s] += 1

while 1:
    n,s = map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Submission status: Accepted

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s, c = s+j, c+1
        j += 1
    x[c][s] += 1

while 1:
    n,s = map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Submission status: Accepted

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s, c = s+j, c+1
        j+=1
    x[c][s]+=1

while 1:
    n, s = map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Submission status: Accepted

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s,c = s+j, c+1
        j+=1
    x[c][s]+=1

while 1:
    n, s=map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Submission status: Accepted

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s,c = s+j, c+1
        j +=1
    x[c][s]+=1

while 1:
    n, s=map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Submission status: Accepted

Solution code:
x = [[0]*50 for i in range(11)]
for i in range(0, 2**10):
    B = format(i,'b')[::-1]
    s,c,j = 0,0,0
    for e in B:
        if e=="1": s,c = s+j, c+1
        j+= 1
    x[c][s]+=1

while 1:
    n, s=map(int, raw_input().split())
    if n==0 and s==0: break
    print 0 if s>=50 else x[n][s]

Submission status: Accepted

Solution code:
from itertools import combinations
while 1:
    n, s = map(int, raw_input().split())
    if n == s == 0:
        break
    print sum(1 for tmp in combinations(range(10), n) if s == sum(tmp))

Submission status: Accepted

Solution code:
def f(mn, n, sm):
    if n == 0 and sm == 0:
        return 1
    if mn == 10 or n == 0:
        return 0
    ct = 0
    for i in range(mn, min(10, sm + 1)):
        ct += f(i + 1, n - 1, sm - i)
    return ct

while True:
    n, sm = map(int, raw_input().split())
    if n == 0 and sm == 0:
        break
    print f(0, n, sm)

Submission status: Accepted

Solution code:
import sys

def comb(sum,c,s):
	if c>1:
		val=0
		for i in range(s,10):
			if sum-i>0:
				val+=comb(sum-i,c-1,i+1);
		return val
	else:
		return 1 if sum>=s and sum<10 else 0

while True:
	c,sum=map(int,raw_input().split(" "))
	if c:
		print comb(sum,c,0)
	else:
		break

Submission status: Accepted

Solution code:
#!/usr/bin/env python

import sys

def solve(n, s, j, a, c):
    if len(a) == n:
        if sum(a) == s:
            c += 1
    elif len(a) < n:
        for i in range(j, 10):
            c = solve(n, s, i+1, a + [i], c)
    return c

for line in sys.stdin:
    if line == "0 0\n":
        break
    else:
        nums = line.replace('\n', '').split(' ')
        n = int(nums[0])
        s = int(nums[1])
        c = solve(n, s, 0, [], 0)
        print c

Submission status: Accepted

Solution code:
def count(target, max_size, c_size, c_num, sum):
  if max_size == c_size:
    return 1 if sum == target else 0

  ans = 0
  for i in range(c_num, 10):
    ans += count(target, max_size, c_size+1, i+1, sum+i)
  return ans

import sys
for s in sys.stdin:
  max_size, target = map(int, s.split())
  if target == 0 and max_size == 0: break
  ans = count(target, max_size, 0, 0, 0)
  print ans

Submission status: Accepted

Solution code:
from itertools import combinations

while True:
    n, s = map(int, input().split())
    if n == s == 0: break

    print(sum(1 for x in combinations(range(10), n) if sum(x) == s))

Submission status: Accepted

Solution code:
import itertools

while 1:
    n , s = map(int,(input().split()))
    if n == 0 and s == 0:
        break
    l = [i for i in range(10)]
    k = list(itertools.combinations(l,n))
    c = 0
    for i in range(len(k)):
        if sum(k[i]) == s:
            c += 1

    print(c)

Submission status: Accepted

Solution code:
import itertools
def ANS(n, s):
    A = list(range(10))
    count = 0
    A_pair = list(itertools.combinations(A,n))
    for i in range(len(A_pair)):
        Sum = sum(A_pair[i])
        if Sum==s:
            count += 1
    return count

while True:
    n, s = map(int, input().split())
    if n==0 and s==0:
        break
    print(ANS(n, s))

Submission status: Accepted

Solution code:
def choice(pos, num):
    global  ans
    if pos == n:
        if len(set(l)) != n:
            return
        check = sum(l)
        if check == s:
            if set(l) not in save:
                save.append(set(l))
                ans += 1
        return
    if num == 10:
        return
    l[pos] = num
    choice(pos + 1, num+1)
    choice(pos, num+1)


number = [0,1,2,3,4,5,6,7,8,9]
n, s = map(int, input().split())
while n != 0:
    l = [0] * n
    save = []
    ans = 0
    choice(0, 0)
    print(ans)
    n, s = map(int, input().split())

Submission status: Accepted

Solution code:
from itertools import combinations
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
    N, S = map(int, readline().split())
    if N == 0:
        return False
    ans = 0
    for p in combinations(range(10), N):
        if sum(p) == S:
            ans += 1
    write("%d\n" % ans)
    return True
while solve():
    ...

Submission status: Accepted

Solution code:
from itertools import combinations
while True:
    cnt = 0
    n,s = map(int,input().split())
    if n==0 and s==0:
        break
    for i in combinations(range(10),n):
        if sum(i)==s:
            cnt=cnt+1
    print(cnt)

Submission status: Accepted

Solution code:
import itertools

while True:
    n,s=[int(i) for i in input().split(" ")]
    if n==0 and s==0:
        break
    retval=0
    for i in itertools.combinations([j for j in range(10)],n):
        if sum(i)==s:
            retval+=1
    print(retval)

Submission status: Accepted

Solution code:
import itertools

while True:
    n, s = map(int, input().split())
    if n == 0 and s == 0:
        break
    ans = 0
    for i in itertools.combinations(range(10), n):
        if sum(i) == s:
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n, s = map(int, input().split()) #与えられた値をn,sに代入
    answer = 0 #答えとなる関数
    if [n,s] == [0,0]:
        break
    else:
        for i in range(2**10): #部分集合をビット表示する
            a = [] #部分集合を表示するためのリストを作成
            for j in range(10):
                if (i >> j) & 1 == 1:
                    a += [j] #ビット表示をただのリストになおす
            if len(a) == n:
                if sum(a) == s:
                    answer += 1
        print(answer)

Submission status: Accepted

Solution code:
n=0
s=0

while 1:
    n,s=map(int,input().split())
    if not n and not s:
        break
    ans=0
    for t in range(1024):
        tt=t
        su=0
        cnt=0
        for i in range(10):
            if tt%2:
                su+=i
                cnt+=1
            tt//=2
        if cnt==n and su==s:
            ans+=1
    print(ans)

Submission status: Accepted

Solution code:
def rec(n, s, v):
    # 9までor目標の値が対象の数値でうわまらない場合
    if v == 10 or v > s:
        return 0
    # 一致ケース
    if n == 1:
        if(s < 10):
            return 1
        else:
            return 0
    sum = 0
    for i in range(v, 10):
	    sum += rec(n - 1,s - i,i + 1)
    return sum

while True:
    n, s = (int(x) for x in input().split())
    if n == 0 and s == 0:
        break
    print(rec(n, s, 0))

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

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


dp = [[0]*101 for _ in range(10)]

dp[0][0] = 1
for i in range(0,10):
    for num in range(9,0,-1):
        for tmp_sum in range(i,101):
            dp[num][tmp_sum] += dp[num-1][tmp_sum-i]

while True:
    N,S = map(int,input().split())
    if N == 0 and S == 0:
        break
    print("%d"%(dp[N][S]))

Submission status: Accepted

Solution code:
import itertools

while True:
    n, s = [int(x) for x in input().split()]
    if n == 0 and s == 0:
        break
    c = 0
    for t in itertools.combinations(range(10),n):
        if sum(t) == s:
            c += 1
    print(c)

Submission status: Accepted

Solution code:
while True:
  a, b = map(int, input().split())
  if a == 0 & b == 0:
    break
  count = 0
  for s in range(2**10):
    arr = [i for i in range(10) if s >> i & 1]
    if len(arr) == a:
      sum = 0
      for i in range(0, len(arr)):
        sum += arr[i]
      if sum == b:
        count += 1
  print(count)

Submission status: Accepted

Solution code:
def _combination(left, source, n, yields):
    if(len(left) == n):
        yields.append(left)
    else:
        for i in range(len(source)):
            _combination(left + [source[i]], source[i + 1:], n, yields)
def combination(source, n):
    yields = []
    _combination([], source, n, yields)
    return yields

printedLater = []
while True:
    n, s = [int(i) for i in input().split()]
    if((n, s) == (0, 0)):
        break
    printedLater.append(len([x for x in combination(range(10), n) if sum(x) == s]))
for line in printedLater:
    print(line)

Submission status: Accepted

Solution code:
def bit(N,S):
    global ans
    for s in range(2**10):
        a=[i for i in range(10) if s>>i & 1]
        if len(a)==N and sum(a)==S:
            ans+=1
while True:
    N,S=map(int,input().split())
    if N==0 and S==0:
        break
    ans=0
    bit(N,S)
    print(ans)

Submission status: Accepted

Solution code:
while True:
    n, s = map(int, input().split())
    if n == 0 and s == 0:
        break

    ans = 0
    for b in range(2 ** 10):
        comb = set()
        for i in range(10):
            if b >> i & 1:
                comb.add(i)
        if len(comb) == n:
            if sum(comb) == s:
                ans += 1
    print(ans)

Submission status: Accepted

Solution code:
# p: max in adder ; n: number of adders;  s: sum
def dfs(p, n, s):
    if not p:
        if n == 1 and s == 0:
            return 1
        else:return 0
    elif n == 1:
        if 0 <= s <= p:
            return 1
        else: return 0
    elif s < 0:
        return 0
    else:
        return dfs(p-1, n-1, s-p) + dfs(p-1, n, s)

while True:
    try:
        n, s = list(map(int, input().split()))
        if (not n and not s):
            break
        print(dfs(9, n, s))
    except:
        break

Submission status: Accepted

Solution code:
while True:
    n,s = map(int,input().split())
    if n==0 and s==0 :
        break
    flg = []
    for i in range(2**10):
        if str(bin(i)).count('1') ==n:
            flg.append(i)

    cnt = 0
    for f in flg:
        if sum([i for i in range(10) if f>>i&1==1]) == s:
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
n, s = map(int, input().split())
import itertools
while n != 0 or s != s:
    count = 0
    a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
    for j in itertools.combinations(a, n):
        x = 0
        for i in range(n):
            x += j[i]
        if x == s:
            count += 1
    print(count)
    n, s = map(int, input().split())

Submission status: Accepted

Solution code:
while True:
    n,s=map(int,input().split())
    cnt=0
    if n==0:
        break
    for i in range(2**10):
        a=[]
        for j in range(10):
            if i>>j & 1:
                a+=[j]
        if len(a)==n and sum(a)==s:
            cnt+=1
    print(cnt)

Submission status: Accepted

Solution code:
def dfs(depth,prev,sum):
	if depth == n:
		return sum == s
	ret = 0
	for i in range(prev + 1,10):
		ret += dfs(depth + 1,i,sum + i)
	return ret

while True:
	n,s = map(int,input().split())
	if n == 0:
		break
	print(dfs(0,-1,0))

Submission status: Accepted

Solution code:
while True:
    n, s = map(int, input().split())
    if n == 0 and s == 0:
        break
    ans = 0
    for i in range(2**10):
        now = 0
        z = 0
        for k in range(10):
            if i >> k & 1:
                z += 1
                now += k
        if z == n and now == s:
            ans += 1
    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
while True:
    n, s = map(int, input().split()) # nとsの入力
    ans = 0 #解答の初期化
    if [n, s] == [0, 0]: # 終了処理
        break
    else:
        for t in range(2 ** 10): # ビット表現で[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]の部分集合を列挙
            a = [] # 列挙のためのlistを用意し、初期化
            for i in range(10):
                if t >> i & 1:
                    a += [i]
            if len(a) == n: # 要素数がnのもののみ考察する
                if sum(a) == s:
                    ans += 1
        print(ans) #解答の出力

Submission status: Accepted

Solution code:
while(True):
    n, s = map(int, input().split())
    if n == 0: break

    def dfs(a, b, used):
        if a == n: return s == b

        ret = 0
        for i in range(used+1, 10):
            ret += dfs(a + 1, b + i, i)
        return ret

    print(dfs(0, 0, -1))

Submission status: Accepted

Solution code:
import itertools

while 1:
    n, s = map(int, input().split())
    if n == 0:
        break
    l = itertools.combinations(range(10), n)
    print(len([l for c in l if sum(c) == s]))

Submission status: Accepted

Solution code:

import itertools
for e in iter(input,'0 0'):
 n,s=map(int,e.split())
 print(sum(s==sum(p)for p in itertools.combinations(range(10),n)))

Submission status: Accepted

Solution code:
def func(i,ls):
    if i == 10:
        return len(ls) == n and sum(ls) == s
    return func(i + 1,ls) + func(i + 1,ls + [i])
 
while True:
    n,s = map(int,input().split())
    if n == 0:
        break
    print(func(0,[]))

Submission status: Accepted

Solution code:
def counter(rest, n, acc, to):
  if rest == 0:return acc == to
  if n == 10:return 0 
  return counter(rest - 1, n + 1, acc + n , to) + counter(rest, n + 1, acc, to)
 
while True:
  n, s = map(int, input().split())
  if not n:
    break
  print(counter(n, 0, 0, s))

Submission status: Accepted

Solution code:
def dfs(n, s, min):
  if min > s:
    return 0
  if min == 10:
    return 0
  if n == 1:
    if min <= s and s < 10:
      return 1
    else:
      return 0
  else:
    sum = 0
    for i in range(min, 10):
      sum += dfs(n - 1, s - i, i + 1)
    return sum
  
while True:
  n, s = map(int, input().split())
  if n + s == 0:
    break
  print(dfs(n, s, 0))

Submission status: Accepted

Solution code:
def rec_sum(n, s, piv):
  if piv == 10 or piv > s:
    return 0
  if n == 1 and s < 10:
    return 1
  else:
    counter = 0
    for i in range(piv, 10):
      counter += rec_sum(n-1, s-i, i+1)
    return counter

while True:
  n, s = map(int, input().split())
  if n == 0 and s == 0:
    break
  print(rec_sum(n, s, 0))

Submission status: Accepted

Solution code:
while True:
	n, s = map(int, raw_input().split())
	if n == 0: break
	cnt = 0
	queue = [[0, 0, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]]
	while queue != []:
		now = queue.pop(0)
		newlist = []
		for i in range(0, len(now[2])):
			newlist.append(now[2][i])
		if now[0] == n:
			if now[1] == s: cnt += 1
		elif n - now[0] <= len(now[2]):
			a = newlist.pop(0)
			queue.append([now[0]+1, now[1]+a, newlist])
			queue.append([now[0], now[1], newlist])
	print cnt

Submission status: Accepted

Solution code:
while 1:
    n,s=map(int,input().split())
    if n==s==0:break
    ans=0
    for a0 in range(2):
        for a1 in range(2):
            for a2 in range(2):
                for a3 in range(2):
                    for a4 in range(2):
                        for a5 in range(2):
                            for a6 in range(2):
                                for a7 in range(2):
                                    for a8 in range(2):
                                        for a9 in range(2):
                                            if a0+a1+a2+a3+a4+a5+a6+a7+a8+a9==n and 1*a1+2*a2+3*a3+4*a4+5*a5+6*a6+7*a7+8*a8+9*a9==s:ans+=1
    print(ans)

Submission status: Accepted

Solution code:

def dfs(p,n,s):#p以下の数からn個用いてsを作る場合の数
    if not p:
        if n == 1 and s == 0:
            return 1
        else:
            return 0
    elif n == 1:
        if 0 <= s <= p:
            return 1
        else:
            return 0
    elif s < 0:
        return 0
    else:
        return dfs(p-1,n-1,s-p)+dfs(p-1,n,s)

while True:
    try:
        n,s = map(int, input().split())
        if (not n and not s):
            break;
        print(dfs(9,n,s))
    except:
        break;

Submission status: Accepted

Solution code:
searched = set()
def search(nums, cur_comb, n, s):
    #print(searched)
    #print(cur_comb)
    if cur_comb in searched:
        return 0
    else:
        searched.add(cur_comb)
    if sum(cur_comb) > s:
        return 0
    if len(cur_comb) == n:
        if sum(cur_comb) == s:
            return 1
        else:
            return 0
    return sum([search(nums[:i]+nums[i+1:], tuple(sorted(cur_comb + (nums[i],))), n , s) for i in range(len(nums))])
    
while True:
    n, s = map(int,  input().split())
    if n == s == 0:
        break
    searched.clear()
    cnt = search(list(range(10)), (), n, s)
    print(cnt)

Submission status: Accepted

Solution code:
import itertools

while 1:
    n, s = map(int, input().split())
    if n == s == 0:
        break
    clist = itertools.combinations(range(10), n)
    cnt = 0
    for c in clist:
        if sum(c) == s:
            cnt += 1

    print(cnt)

Submission status: Accepted

Solution code:
import itertools

while 1:
    n, s = map(int, input().split())
    if n == 0: break
    ans = []
    for c in itertools.combinations(range(10), n):
        if sum(c) == s:
            ans.append(1)
    print(len(ans))

Submission status: Accepted

Solution code:
from itertools import combinations


while True:
  n, s = map(int, input().split())
  if n == 0 and s == 0:
    break
  
  count = 0
  for t in combinations(list(range(0,10)), n):
    if sum(t) == s:
      count += 1
  print(count)

Submission status: Accepted

Solution code:
from sys import stdin
from itertools import product,permutations,combinations

while(True):
    n,s = map(int, stdin.readline().split())
    if not n:
        break
    print(sum([1 for m in combinations(list(range(10)),r=n) if sum(m)==s]))

Submission status: Accepted

Solution code:
global num_lim
global tgt_sum

def dfs(cnt, num, sum):
  if cnt == num_lim:
    return sum == tgt_sum
  if num > 9:
    return 0
  return dfs(cnt + 1, num + 1, sum + num) + dfs(cnt, num + 1, sum)
    
while True:
  num_lim, tgt_sum = list(map(int, input().split()))
  if num_lim == 0 and tgt_sum == 0:
    break
  print(dfs(0, 0, 0))

Submission status: Accepted

Solution code:
class Node():
    def __init__(self, v):
        self.v = v
        self.parent = None
        self.children = []
        self.is_visited = False
    
    def add_child(self, node):
        self.children.append(node)
        node.parent = self


def construct_tree(node):
    start = -1 if node.v is None else node.v
    if node.v == 9:
        return
    for i in range(start + 1, 10):
        new_node = Node(i)
        node.add_child(new_node)
        construct_tree(new_node)

def reset_state(node):
    node.is_visited = False
    for child in node.children:
        reset_state(child)

def find_answer(node, n, s, cnt=0):
    node.is_visited = True
    
    depth, cur_sum = 0, 0
    cur = node
    while cur.parent is not None:
        cur_sum += cur.v
        depth += 1
        cur = cur.parent
    
    if cur_sum == s and depth == n:
        cnt += 1
   
    if depth < n:
        for child in node.children:
            if not child.is_visited:
                cnt = find_answer(child, n, s, cnt)
    
    return cnt

def solve():
    root = Node(None)
    construct_tree(root)
    
    while True:
        n, s = map(int, input().split())
        if n == 0 and s == 0:
            break
        
        count = find_answer(root, n, s)
        print(count)
        reset_state(root)

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def dfs(n, s, i):
    if n == 0:
        if s == 0: return 1
        else: return 0
    if i == 10:
        return 0;

    ans = 0
    ans += dfs(n, s, i + 1)
    ans += dfs(n-1, s - i, i + 1)
    return ans


def main():
    while True:
        n, s = map(int, input().split())
        if n == 0: break
        print(dfs(n, s, 0))

    return 0


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools import combinations
while True:
    n,s=map(int,input().split())
    if n==0 and s==0:
        break
    num=[i for i in range(0,s+1)]
    print(num)
    ans=0
    comb=itertools.combinations(num,n)
    for c in comb:
        if sum(c) == s:
            ans +=1
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
f = sys.stdin

while True:
    n, s = map(int, f.readline().split())
    if n == 0:
        break
    print(sum(1 for nums in itertools.combinations([i for i in range(10)], n) if sum(nums) == s))

Submission status: Runtime Error

Solution code:
def move(move_count, current, flag):
    for i in range(move_count):
        n_lis.append(num_lis[current+i])
        if flag == n:
            calculate()
            del n_lis[-1]
        else:
            move(move_count, current+i+1, flag+1)
            move_count -= 1
            del n_lis[-1]
            
def calculate():
    print n_lis
    global count
    if sum(n_lis) == s:
        count += 1

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    num_lis = [0,1,2,3,4,5,6,7,8,9]
    n_lis = []
    count = 0
    move(8,0,1)
    print count

Submission status: Runtime Error

Solution code:
def move(move_count, current, flag):
    for i in range(move_count):
        n_lis.append(num_lis[current+i])
        if flag == n:
            calculate()
            del n_lis[-1]
        else:
            move(move_count, current+i+1, flag+1)
            move_count -= 1
            del n_lis[-1]
            
def calculate():
    global count
    if sum(n_lis) == s:
        count += 1

while True:
    n, s = map(int, raw_input().split())
    if n == 0 and s == 0:
        break
    num_lis = [0,1,2,3,4,5,6,7,8,9]
    n_lis = []
    count = 0
    move(8,0,1)
    print count

Submission status: Runtime Error

Solution code:
def f(n,s,x):
  if n == s == 0:
    return 1
  elif n == 0 or x == 0:
    return 0
  else:
    a = 0
    for i in range(x):
      a += f(n-1,s-i,i)
    return a
while True:
  n,s = map(int,raw_input().split())
  if n == s == 0:
    break
  print(f(n,s,10))

Submission status: Runtime Error

Solution code:
import itertools

while 1:
    n, s = map(int, raw_input().split())
    d = [i for i in xrange(s)]
    if n == 0: break
    x = map(sum, list(itertools.combinations(d, n)))
    print x.count(s)

Submission status: Runtime Error

Solution code:
import itertools

d = [i for i in xrange(101)]
while 1:
    n, s = map(int, raw_input().split())
    if n == 0: break
    x = map(sum, list(itertools.combinations(d[0:s + 1], n)))
    print x.count(s)

Submission status: Runtime Error

Solution code:
while True:
    n = int(input())
    a = sorted(list(map(int, input().split())))
    if n == 0:
        break
    ans = 1000
    for i in range(n - 1):
        j = a[i + 1] - a[i]
        if j <= ans:
            ans = j
    print(ans)

Submission status: Runtime Error

Solution code:
while True:
    n = int(input())
    if n == 0:
        break
    a = sorted(list(map(int, input().split())))
    ans = 10000
    for i in range(n - 1):
        j = a[i + 1] - a[i]
        if j <= ans:
            ans = j
    print(ans)

Submission status: Runtime Error

Solution code:
from collections import deque


class Bt(object):
    def __init__(self):
        self.used = [False] * 10  # ?????°???????????¨?????????????????????????????°
        self.answers = []  # ?????¶???????????????????????????
        self.Q = deque()  # ????????§???????????¢??????????????°???????¨???¶??¨

    def solve(self, num, rem):
        num -= 1
        if rem < 10 and self.used[rem] == False and num == 0:
            self.Q.append(rem)
            # print('{0}'.format(self.Q))
            ans = [*self.Q]
            ans.sort()
            if not ans in self.answers:
                self.answers.append(ans)
            self.Q.pop()
            return

        try:
            min_num = self.used.index(True)
        except ValueError:
            min_num = 0

        for i in range(min_num, 10):
            if self.used[i] == False and (rem - i) >= 0:
                self.used[i] = True
                self.Q.append(i)
                self.solve(num, rem - i)
                self.used[i] = False
                self.Q.pop()


if __name__ == '__main__':
    while True:
        # ??????????????\???
        n, s = [int(x) for x in input().split(' ')]
        if n == 0 and s == 0:
            break

        # ????????????
        a = Bt()
        a.solve(n, s)

        # ???????????¨???
        print(len(a.answers))

Submission status: Runtime Error

Solution code:
from collections import deque


class Bt(object):
    def __init__(self):
        self.used = [False] * 10  # ?????°???????????¨?????????????????????????????°
        self.answers = []  # ?????¶???????????????????????????
        self.Q = deque()  # ????????§???????????¢??????????????°???????¨???¶??¨

    def solve(self, num, remain):
        num -= 1
        if remain < 10 and self.used[remain] == False and num == 0:
            self.Q.append(remain)
            # print('{0}'.format(self.Q))
            ans = [*self.Q]
            ans.sort()
            if not ans in self.answers:
                self.answers.append(ans)
            self.Q.pop()
            return

        try:
            min_num = self.used.index(True)
        except ValueError:
            min_num = 0

        for i in range(min_num, 10):
            if self.used[i] == False and (remain - i) >= 0:
                self.used[i] = True
                self.Q.append(i)
                self.solve(num, remain - i)
                self.used[i] = False
                self.Q.pop()


if __name__ == '__main__':
    while True:
        # ??????????????\???
        n, s = [int(x) for x in input().split(' ')]
        if n == 0 and s == 0:
            break

        if 0 <= s <= 45:
            # ????????????
            a = Bt()
            a.solve(n, s)

            # ???????????¨???
            print(len(a.answers))
        else:
            print(0)

Submission status: Runtime Error

Solution code:
from collections import deque


class Bt(object):
    def __init__(self):
        self.used = [False] * 10  # 0-9????????°???????????¨?????????????????????????????°
        self.answers = []  # ?????¶???????????????????????????
        self.Q = deque()  # ????????§???????????¢??????????????°???????¨???¶??¨

    def solve(self, num, remain):
        if remain < 10 and self.used[remain] == False and num == 1:
            self.Q.append(remain)
            # print('{0}'.format(self.Q))
            ans = [*self.Q]
            ans.sort()
            if not ans in self.answers:
                self.answers.append(ans)
            self.Q.pop()
            return
        elif num < 0:
            return

        try:
            min_choice = max(self.Q) + 1
        except ValueError:
            min_choice = 0

        for i in range(min_choice, 10):
            if self.used[i] == False and (remain - i) >= 0:
                self.used[i] = True
                self.Q.append(i)
                self.solve(num - 1, remain - i)
                self.used[i] = False
                self.Q.pop()


if __name__ == '__main__':
    while True:
        # ??????????????\???
        n, s = [int(x) for x in input().split(' ')]
        if n == 0 and s == 0:
            break

        if 0 <= s <= 45:
            # ????????????
            a = Bt()
            a.solve(n, s)

            # ???????????¨???
            print(len(a.answers))
        else:
            print(0)