Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

func solve(a, b, c int) int {
	if a == 1 && b >= c && b < 10 {
		return 1
	}
	if a == 1 {
		return 0
	}
	ret := 0
	for i := c; i < 10 && i < b; i++ {
		ret += solve(a-1, b-i, i+1)
	}
	return ret
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for {
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		if a == 0 {
			break
		}
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		fmt.Println(solve(a, b, 0))
	}
}

C++: #include <iostream>
#include <ostream>
#include <stack>
#include <vector>
#include <list>
#include <cstdlib>
using namespace std;

enum tag_drop_sizes { small_drop = 1, middle_drop, large_drop };

static const int MARGIN = 2;
static const int H = 10, W = 10;

const int small[5][5] = {{0,0,0,0,0},{0,0,1,0,0},{0,1,1,1,0},{0,0,1,0,0},{0,0,0,0,0}};
const int middle[5][5] = {{0,0,0,0,0},{0,1,1,1,0},{0,1,1,1,0},{0,1,1,1,0},{0,0,0,0,0}};
const int large[5][5] = {{0,0,1,0,0},{0,1,1,1,0},{1,1,1,1,1},{0,1,1,1,0},{0,0,1,0,0}};

const int small_size = 5, middle_size = 9, large_size = 13;

struct operation {
	int x;
	int y;
	int size;

	operation(int a, int b, int c) {
		x = a; y = b; size = c;
	}
};

struct cell_info {
	int x, y;
	int size;
	int n;

	cell_info(int a, int b, int c, int d) {
		x = a;
		y = b;
		size = c;
		n = d;
	}
};

int cloth[16][16];
int depth;
int total;
int num_large_drop, num_middle_drop, num_small_drop;
stack<operation> s;
list<cell_info> lst;
list<cell_info>::iterator iter;

bool add(int x, int y, const int drop_size[5][5]) {
	for(int i = 0; i < 5; i++) {
		for(int j = 0; j < 5; j++) {
			cloth[y + i][x + j] += drop_size[i][j];
		}
	}
	return true;
}

bool sub(int x, int y, const int drop_size[5][5]) {
	bool ret = true;
	for(int i = 0; i < 5; i++) {
		for(int j = 0; j < 5; j++) {
			if((cloth[y + i][x + j] -= drop_size[i][j]) < 0)
				ret = false;
		}
	}
	return ret;
}

void init() {
	depth = 0;
	for(int i = 0; i < 16; i++)
		for(int j = 0; j < 16; j++)
			cloth[i][j] = 0;
}

bool complete() {
	for(int i = 0; i < 16; i++)
		for(int j = 0; j < 16; j++)
			if(cloth[i][j])
				return false;
	return true;
}

bool solve(list<cell_info>::iterator p) {

	if(depth == 0) {
		if(complete())
			return true;
		return false;
	}

	else if(p == lst.end())
		return false;

	if(num_large_drop > 0 && p->size == large_drop && p->n > 0) {
		if(sub(p->x, p->y, large)) {
			s.push(operation(p->x,p->y,large_drop));
			num_large_drop--;
			depth--;
			p->n--;
			if(solve(p))
				return true;
			p->n++;
			depth++;
			num_large_drop++;
			s.pop();
		}
		add(p->x, p->y, large);
	}

	if(num_middle_drop > 0 && p->size == middle_drop && p->n > 0) {
		if(sub(p->x, p->y, middle)) {
			s.push(operation(p->x,p->y,middle_drop));
			num_middle_drop--;
			depth--;
			p->n--;
			if(solve(p))
				return true;
			p->n++;
			depth++;
			num_middle_drop++;
			s.pop();
		}
		add(p->x, p->y, middle);
	}

	if(num_small_drop > 0 && p->size == small_drop && p->n > 0) {
		if(sub(p->x, p->y, small)) {
			s.push(operation(p->x,p->y,small_drop));
			num_small_drop--;
			depth--;
			p->n--;
			if(solve(p))
				return true;
			p->n++;
			depth++;
			num_small_drop++;
			s.pop();
		}
		add(p->x, p->y, small);
	}

	return solve(++p);
}

int count_total() {
	int count = 0;
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			count += cloth[MARGIN + i][MARGIN + j];
		}
	}

	return count;
}

void set_num() {
	static int i = 0, j = 0;
	for(; i < depth; i++, j = 0) {
		for(; j < depth - i; j++) {
			if(4 * i + 8 * j == total - 5 * depth) {
				num_small_drop = depth - i - j;
				num_middle_drop = i;
				num_large_drop = j;

				j++;
				return;
			}
		}
	}
	// exit(1);
        return;
}

void make_lst() {
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			cell_info tmp_s(i, j, small_drop, 0), tmp_m(i, j, middle_drop, 0), tmp_l(i, j, large_drop, 0);
			int tmp[16][16];

			for(int i_ = 0; i_ < 16; i_++)
				for(int j_ = 0; j_ < 16; j_++)
					tmp[i_][j_] = cloth[i_][j_];

			while(sub(i, j, large)) {
				tmp_s.n++; tmp_m.n++; tmp_l.n++;
			}
			add(i, j, large);
			while(sub(i, j, middle)) {
				tmp_s.n++; tmp_m.n++;
			}
			add(i, j, middle);
			while(sub(i, j, small)) {
				tmp_s.n++;
			}
			add(i, j, small);

			// restore
			for(int i_ = 0; i_ < 16; i_++)
				for(int j_ = 0; j_ < 16; j_++)
					cloth[i_][j_] = tmp[i_][j_];

			if(tmp_l.n != 0) lst.push_back(tmp_l);
			if(tmp_m.n != 0) lst.push_back(tmp_m);
			if(tmp_s.n != 0) lst.push_back(tmp_s);
		}
	}
}

int main() {
	init();
	cin >> depth;
	for(int i = 0; i < 10; i++) {
		for(int j = 0; j < 10; j++) {
			cin >> cloth[i + MARGIN][j + MARGIN];
		}
	}

	total = count_total();
	make_lst();

	while(1) {
		set_num();
		if(solve(lst.begin())) {
			while(!s.empty()) {
				operation tmp = s.top();
				cout << tmp.x << " " << tmp.y << " " << tmp.size << endl;
				s.pop();
			}
			break;
		}
	}
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

void dfs(int n,int s,int k);

int ans=0;

int main(){
	int n,sum;
	while(cin>>n>>sum , n||sum){
		ans=0;
		dfs(n,sum,0);
		cout<<ans<<endl;
	}
}

void dfs(int n,int sum,int k){
	if(n<0){
		return ;
	}
	if(n==0){
		if(sum==0){
			ans++;
		}
	}
	else{
		if(9<k){
			return ;
		}
		for(int i=k;i<=9 && sum-i>=0 ;i++){
			//cout<<"n="<<n-1<<" sum="<<sum-i<<" k="<<i+1<<endl;
			printf("n=%02d sum=%03d k=%02d\n",n-1,sum-i,i+1);
			dfs(n-1,sum-i,i+1);
		}
	}
}

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

void doSum( int a, int b, int n, int s, int sum, int* count ){
	for ( int i = a; i < b; ++i ){
		int tsum = sum + i;
		if ( !n ){
			if ( tsum == s ) *count += 1;
		}else{
			doSum( i+1, b+1, n-1, s, tsum, count );
		}
	}
}

int main(){
	int n, s, count;

	while ( cin >> n >> s ){
		if ( !n && !s ) break;

		count = 0;
		doSum( 0, 10-n+1, n-1, s, 0, &count );

		cout << count << endl;
	}

	return 0;
}

C++: #include<stdio.h>
int solve(int a,int b,int c){
    if(a==1&&b>=c&&b<10){
        return 1;
    }
    if(a==1)return 0;
    int ret=0;
    for(int i=c;i<10&&i<b;i++){
        ret+=solve(a-1,b-i,i+1);
    }
    return ret;
}
int main(){
    int a,b;
    while(1){
        scanf("%d%d",&a,&b);
        if(a==0)return 0;
        printf("%d\n",solve(a,b,0));
    }
}

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

int visit(int n, int s, int x){
    int sum=0;
    if(n==0 && s==0)    return 1;
    if(n>0){
        for(int i=x; i<10; i++){
            if(s-i>=0)  sum+=visit(n-1, s-i, i+1);
        }
    }
    return sum;
}

int main(void){
    int n, s;
    while(cin >> n >> s){
        if(n==0 && s==0)    break;
        cout << visit(n, s, 0) << endl;
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int _s,a,b;
int solve(int c,int n,int s){
      if(!n) return s==_s;
      if(c>=10) return 0;
      return solve(c+1,n-1,s+c) + solve(c+1,n,s);
}
int main(){
      for(;;){
      cin >> a >> _s;
      if(!a)break;
      cout <<solve(0,a,0)<< endl;
      }
}

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

int res;
const int d[10]={0,1,2,3,4,5,6,7,8,9};

bool dfs(int now,int idx,int n,int sum,int s){
	
	
	if(now==n) {
		if(sum==s){
			res++;
		}
		return true;
	}
	
	if(idx<=9){
	
		if(dfs(now,idx+1,n,sum,s)) return true;
	
		if(dfs(now+1,idx+1,n,sum+d[idx],s)) return true;
	}
	
	return false;
}

int main(){
	int n,s;
	
	while(cin>>n>>s,n||s){
		res=0;
		dfs(0,0,n,0,s);
		cout<<res<<endl;
	}
	
	return 0;
}

C++: #include <stdio.h>

int n, s, cnt;

void dfs(int i, int sum, int n){
    if(sum==s&&!n){
        cnt++;
        return;
    }
    if(i==10||!n) return;
    dfs(i+1,sum,n);
    dfs(i+1,sum+i,n-1);
}

int main(){
	while(1){
		scanf("%d%d",&n,&s);
		if(n==0&&s==0){
			break;
		}
		cnt=0;
		dfs(0,0,n);
		printf("%d\n",cnt);
	}

    return 0;
}