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++: 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#define strtok_r strtok_s
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n)
#define REPEAT(i, k, n)     for(int i = (k); i < ((k)+(n)); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); --i)
#define FROMTO(i,f,t)       for(int i = f; i < t; i++)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define FILL(m,v)           memset(m, v, sizeof(m))
#define mp                  make_pair
#define pb                  push_back
template<class _T> _T MAX(_T p1,_T p2){return (p1>p2)?p1:p2;} 
template<class _T> _T MIN(_T p1,_T p2){return (p1<p2)?p1:p2;} 
template <class _Tv> inline string join(const _Tv &v,string sep=" "){
    ostringstream s;FOREACH(it,v){if(it!=v.begin())s<<sep;s<<*it;};return s.str();
}

typedef long long ll;
typedef unsigned long long ull;
typedef double D;
typedef complex<D> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define X real()
#define Y imag()
#define EPS (1e-9)
#define DEQ(p1,p2) (abs((p1)-(p2)) < EPS)

#ifdef _DEBUG
template<class _Tv> inline void _prfe(const char *_n,const _Tv _c,bool _p=false){
    ITER(_c) _it=_c.begin();
    if(_p){cout<<_n<<" = ["<<endl;for(;_it!=_c.end();++_it)cout<<"    "<<*_it<<endl;cout<<"]"<<endl; }
    else{cout<<_n<<" = [ "<<*_it++;for(;_it!=_c.end();++_it)cout<<", "<<*_it;cout<<" ]"<<endl; }
}
#define pf printf
#define pr(n) do{cout<<#n" = "<<(n)<<endl;}while(0)
#define prfe(n) _prfe(#n, n)
#define prfep(n) _prfe(#n, n, true)
#define dbgchk(n) do{if(n)throw;}while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#define prfe(...) /* */
#define prfep(...) /* */
#define dbgchk(...) /* */
#endif

int card[10], num[10];
ll dp[100][1001];
int k;

void solve(int m){
    FILL(dp,0);
    dp[0][0] = 1; k = 0;
    REP(i,m){
        REP(j,num[i]+1){
            int c = card[i] * j;
            REP(x,1001){
                if(dp[k][x] <= 0) continue;
                if(x+c <= 1000)
                    dp[k+1][x+c] += dp[k][x];
            }
        }
        //REP(i,50) cout << dp[k+1][i] << " "; cout << endl;
        k++;
    }
}

int main(){
    int m, g;
    while(cin >> m && m){
        REP(i,m){
            cin >> card[i] >> num[i];
        }
        solve(m);
        cin >> g;
        REP(i,g){
            int n;
            cin >> n;
            cout << dp[k][n] << endl;
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
#define M 7
using namespace std;
int m,a[M],b[M],g,n,ans;

void dfs(int x,int sum){
  if(x==m){
    if(sum==n)ans++;
    return;
  }
  for(int i=0;i<=b[x];i++)
    dfs(x+1,sum+a[x]*i);
}

int main(){
  while(1){
    cin>>m;
    if(!m)break;
    for(int i=0;i<m;i++)
      cin>>a[i]>>b[i];
    cin>>g;
    while(g--){
      cin>>n;
      ans=0;
      dfs(0,0);
      cout<<ans<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

int main(){

	int m;
	while(cin>>m&&m!=0){
		int cnts[101];
		fill(cnts,cnts+101,0);
		// dp[i][j]ツづ絞ツ氾板姪堋づ個青板篠堋づーツづつつゥツづづツづーツづつつュツづェツづゥツ古つ青板づーツ表ツつキ
		int dp[101][2001];
		for(int i = 0; i < 100; i++){
			for(int j = 0; j < 1001; j++){
				dp[i][j]=0;
			}
		}
		dp[0][0]=1;
		for(int i = 0; i < m; i++){
			int a,b;
			cin>>a>>b;
			cnts[a]+=b;
		}
		for(int i = 1; i <= 100; i++){
			if(cnts[i]!=0){
				for(int j = 0; j <= 1000; j++){
					for(int k = 0; k <= cnts[i]; k++){
						if(j-k*i>=0){
							dp[i][j]+=dp[i-1][j-k*i];
						}
						else
							break;
					}
				}
			}
			else{
				for(int j = 0; j <= 1000; j++){
					dp[i][j]=dp[i-1][j];
				}
			}
		}
		int g;
		cin>>g;
		for(int i = 0; i < g; i++){
			int n;
			cin>>n;
			cout<<dp[100][n]<<endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int m;
        cin >> m;
        if(m == 0)
            return 0;

        vector<int> a(m), b(m);
        for(int i=0; i<m; ++i)
            cin >> a[i] >> b[i];

        vector<int> num(1001, 0);
        num[0] = 1;
        for(int i=0; i<m; ++i){
            for(int j=1000; j>=0; --j){
                for(int k=1; k<=b[i]; ++k){
                    int c = j + a[i] * k;
                    if(c <= 1000)
                        num[c] += num[j];
                }
            }
        }

        int g;
        cin >> g;
        for(int i=0; i<g; ++i){
            int n;
            cin >> n;
            cout << num[n] << endl;
        }
    }
}