Go: package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		m, _ := strconv.Atoi(scanner.Text())
		if m == 0 {
			break
		}
		ab := make([][]int, 0)
		for i := 0; i < m; i++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			buf := make([]int, len(input))
			for j := range buf {
				buf[j], _ = strconv.Atoi(input[j])
			}
			ab = append(ab, buf)
		}
		dp := make([][]int, 8)
		for i := range dp {
			dp[i] = make([]int, 1001)
		}
		dp[0][0] = 1
		for i := 1; i < m+1; i++ {
			for j := 0; j < 1001; j++ {
				if dp[i-1][j] == 0 {
					continue
				}
				s := j
				for k := ab[i-1][1]; k > -1; k-- {
					if s < 1001 {
						dp[i][s] += dp[i-1][j]
					}
					s += ab[i-1][0]
				}
			}
		}
		scanner.Scan()
		g, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < g; i++ {
			scanner.Scan()
			n, _ := strconv.Atoi(scanner.Text())
			fmt.Println(dp[m][n])
		}
	}
}

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


int main(int argc, const char * argv[]) {
    
    while(true){
        int m;
        cin >> m;
        if(m == 0){
            break;
        }
        
        int a[7] = {0}, b[7] = {0};
        
        for(int i=0;i<m;i++){
            cin >> a[i] >> b[i];
        }
        
        int g;
        cin >> g;
        
        for(int i=0;i<g;i++){
            int n;
            cin >> n;
            int count[8] = {0};
            int win =0;
            while(true){
                count[0]++;
                
                for(int j=0;j<m;j++){
                    if(count[j] > b[j]){
                        count[j] = 0;
                        count[j+1]++;
                        continue;
                    }
                    else{
                        break;
                    }
                }
                
                if(count[m] > 0){
                    break;
                }
                
                int sum = 0;
                for(int j=0;j<m;j++){
                    sum += count[j] * a[j];
                }
                
                if(sum == n) win++;
                
            }
            
            cout << win << endl;
            
        }
        
        
    }
    
    return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

#define MAX 1001
#define f first
#define s second
typedef pair<int, int> P;

int main(){
  int m;
  while(cin >> m, m){
    vector<P> card(m);
    for(int i = 0 ; i < m ; i++){
      cin >> card[i].f >> card[i].s;
    }
    
    int dp[8][MAX] = {0};
    dp[0][0] = 1;
    for(int i = 0 ; i < m ; i++){
      for(int j = 0 ; j < MAX ; j++){
	for(int k = 0 ; k <= card[i].s ; k++){
	  if(card[i].f*k+j < MAX){
	    dp[i+1][card[i].f*k+j] += dp[i][j];
	  }
	}
      }
    }
    int g, ng;
    cin >> g;
    while(g--){
      cin >> ng; 
      cout << dp[m][ng] << endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int c[7];
int d[7];
int dp[8][1001];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			scanf("%d%d",c+i,d+i);
		}
		for(int i=0;i<8;i++)
			for(int j=0;j<1001;j++)
				dp[i][j]=0;
		dp[0][0]=1;
		for(int i=0;i<a;i++){
			for(int j=0;j<1001;j++){
				if(dp[i][j]){
					for(int k=0;k<=d[i];k++){
						if(j+k*c[i]>1000)break;
						dp[i+1][j+k*c[i]]+=dp[i][j];
					}
				}
			}
		}
		int b;
		scanf("%d",&b);
		for(int i=0;i<b;i++){
			int e;
			scanf("%d",&e);
			printf("%d\n",dp[a][e]);
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(void){

	int m,g,n,a[8],b[8],dp[9][1000];
	
	while(cin >> m,m){
		
		fill(a,a+8,0);
		fill(b,b+8,0);
		
		for(int i=1;i<=m;i++){
			cin >> a[i] >> b[i];
		}
		
		fill(dp[0],dp[8],0);
		
		dp[0][0]=1;
		for(int i=0;i<=m;i++){
			for(int j=0;j<1000;j++){
				for(int k=0;k<=b[i];k++){
					if(j-k*a[i]<1001)dp[i+1][j]+=dp[i][j-k*a[i]];
				}
			}
		}

		cin >> g;
		while(g--){
			cin >> n;
			cout << dp[m+1][n] << endl;
		}
			
	}
	
return 0;
}

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

typedef pair<int, int> C;

int m, g;
vector<C> cs;

int solve(int n, int index) {
    //cout << n << endl;
    if (n < 0) return 0;
    if (index == cs.size()) {
        if (n == 0) return 1;
        return 0;
    }
    int ans = 0;
    for (int i = 0; i <= cs[index].second; i++) {
        cs[index].second -= i;
        ans += solve(n - cs[index].first * i, index+1);
        cs[index].second += i;
    }
    return ans;
}

int main() {
    while (cin >> m, m) {
        cs.clear(); cs.resize(m);
        for (int i = 0; i < m; i++) cin >> cs[i].first >> cs[i].second;
        //for (int i = 0; i < m; i++) cout << cs[i].first << ' ' << cs[i].second << endl;
        cin >> g;
        for (int i = 0; i < g; i++) {
            int n; cin >> n;
            cout << solve(n, 0) << endl;
        }
        //cout << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int n;
    while (cin >> n, n) {
        vi data(n), num(n);
        rep(i, n) {
            cin >> data[i] >> num[i];
        }
        vvi dp(n+1, vi(70200, 0));
        dp[0][0] = 1;
        rep(i, n) {
            rep(j, 70200) {
                dp[i+1][j] += dp[i][j];
            }
            Rep(j, num[i]+1) {
                for (int k = 70100; k >= 0; k--) {
                    if (dp[i][k]) {
                        dp[i+1][k+data[i]*j] += dp[i][k];
                    }
                }
            }
        }
        Int(g);
        while (g--) {
            Int(tmp);
            cout << dp[n][tmp] << endl;
        }
    }

    return 0;
}

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

int main(){
	int m;
	while( cin >> m , m ){
		vector<int> a(m), b(m);
		for(int i=0 ; i < m ; i++ ){
			cin >> a[i] >> b[i];
		}
		
		// dp[i][j] := a[0..i] までのカードを使ったとき,和が j になる組合せ数
		int dp[10][1001] = {0};
		dp[0][0] = 1;
		for(int i=0 ; i < a.size() ; i++ ){
			for(int j=0 ; j < 1001 ; j++ ){
				for(int k=0 ; k <= b[i] ; k++ ){
					// k := a[i] のカードを使う枚数
					if( j+a[i]*k < 1001 ){
						dp[i+1][j+a[i]*k] += dp[i][j];
					}
				}
			}
		}
		
		int g;
		cin >> g;
		for(int i=0 ; i < g ; i++ ){
			int n;
			cin >> n;
			cout << dp[m][n] << endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int a[7],b[7];
int N;
int dfs(int U,int id)
{
	if(id==N)return U==0;
	int ret=0;
	for(int k=0;k<=b[id];k++)
	{
		if(U<k*a[id])break;
		ret+=dfs(U-k*a[id],id+1);
	}
	return ret;
}
main()
{
	while(cin>>N,N)
	{
		for(int i=0;i<N;i++)cin>>a[i]>>b[i];
		int Q;cin>>Q;
		for(;Q--;)
		{
			int g;cin>>g;cout<<dfs(g,0)<<endl;
		}
	}
}