Problem:


Combination of Number Sequences

0 から 9 までの整数を使った n 個の数の並び k1, k2, ..., kn を考えます。正の整数 n と s を読み込んで、

k1 + 2 &times; k2 + 3 &times; k3 + ... + n &times; kn = s 

となっているような n 個の数の並びが何通りあるかを出力するプログラムを作成してください。ただし、1 つの「n 個の数の並び」には同じ数が 2 回以上現われないものとします。

Input

入力は複数のデータセットからなります。各データセットとして、n (1 ≤ n ≤ 10) と s (0 ≤ s ≤ 10,000)が空白区切りで１行に与えられます。

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

Output

データセットごとに、n 個の整数の和が s になる組み合わせの個数を１行に出力します。

Sample Input

3 10
3 1

Output for the Sample Input

8
0



Sample input:
3 10
3 1


Sample output:
8
0

Submission status: Runtime Error

Solution code:
import sys
def oncount(x):
    r=0
    while x>0:
        r+=x&1
        x=x>>1
    return r

dp=[[0]*331 for i in range(1024)]
for i in range(10):
    dp[1<<i][i]=1
for i in range(1024):
    for j in range(331):
        t=oncount(i)
        for k in range(10):
            if 1&(i>>k):
                x=j-t*k
                if x>=0: dp[i][j]+=dp[i&~(1<<k)][x]
                
for a in sys.stdin
    n,s=map(int,a.split())
    ans=0
    if s<=330:
        for i in range(1024):
            if oncount(i)==n:ans+=dp[i][s]
    print ans

Submission status: Runtime Error

Solution code:
import sys


def try_sum(xk=[], xn=xn):  # x1 = n, x2 = k
    xi = 0
    for i in range(a):
        xi += xn[i] * xk[i]
    if xi == b:
        total[0] += 1


def make_k(ceng=a):
    i = 9
    while i >= 0:
        if ceng > 1:
            gg[ceng - 1] = i
            make_k(ceng - 1)
        else:
            gg[ceng - 1] = i
            if len(list(set(gg))) == a:
                try_sum(gg)
        i -= 1


for xxx in sys.stdin:
    a, b = map(int, xxx.split())
    inp = "3 10"
    a, b = inp.split()
    a, b = int(a), int(b)
    total = [0]
    xn = list(range(1, a + 1))
    gg = [0] * a
    make_k()
    print(total[0])

Submission status: Runtime Error

Solution code:
import sys


def try_sum(xk=[], xn=xn):
    xi = 0
    for i in range(a):
        xi += xn[i] * xk[i]
    if xi == b:
        total[0] += 1


def make_k(ceng=a):
    i = 9
    while i >= 0:
        if ceng > 1:
            gg[ceng - 1] = i
            make_k(ceng - 1)
        else:
            gg[ceng - 1] = i
            if len(list(set(gg))) == a:
                try_sum(gg)
        i -= 1


for xxx in sys.stdin:
    a, b = map(int, xxx.split())
    total = [0]
    xn = list(range(1, a + 1))
    gg = [0] * a
    make_k()
    print(total[0])

Submission status: Runtime Error

Solution code:
dp=[[0]*1001 for _ in range(11)]
u=[1]*10
def f(a,b):
    dp[a][b]+=1
    for i in range(10):
        if u[i]:
            u[i]=0
            f(a+1,b+i*(a+1))
            u[i]=1
f(0,0)
while 1:
    try:n,s=map(int,input().split())
    except:break
    print([dp[n][s],0][s>330])

Submission status: Runtime Error

Solution code:
import sys
dp=[[[0]*341 for i in xrange((1<<10)+1)] for j in xrange(12)]
#dp[12][1025][340]
dp[0][0][0]=1
for i in xrange(10):
    for j in xrange(1<<10):
        for c in xrange(331):
            if dp[i][j][c]==0:
                continue
            for k in xrange(10):
                if (j>>k&1)==0:
                    dp[i+1][j|(1<<k)][(i+1)*k+c]+=dp[i][j][c]
ans=[[0]*341 for unused in xrange(12)]
for i in xrange(11):
    for j in xrange(1<<10):
        for c in xrange(331):
            ans[i][c]+=dp[i][j][c]
for line in sys.stdin.readlines():
    n,s=map(int,line.strip().split())
    print ans[n][s]

Submission status: Runtime Error

Solution code:
import itertools
dp=[[0]*286 for i in range(10)]
for i in range(1,10):
    t=range(1,1+i)
    for j in itertools.permutations(range(10),i):
        s=sum(l*k for l,k in zip(j,t))
        dp[i][s]+=1

while True:
    try:
        n,s=map(int,raw_input().split())
    except EOFError:
        break
    print dp[n][s]

Submission status: Runtime Error

Solution code:
import itertools
dp=[[0]*400 for i in range(10)]
for i in range(1,10):
    t=range(1,1+i)
    for j in itertools.permutations(range(10),i):
        s=sum(l*k for l,k in zip(j,t))
        dp[i][s]+=1

while True:
    try:
        n,s=map(int,raw_input().split())
    except EOFError:
        break
    print dp[n][s]

Submission status: Runtime Error

Solution code:
import itertools
dp=[[0]*400 for i in range(11)]
for i in range(1,10):
    t=range(1,1+i)
    for j in itertools.permutations(range(10),i):
        s=sum(l*k for l,k in zip(j,t))
        dp[i][s]+=1

while True:
    try:
        n,s=map(int,raw_input().split())
    except EOFError:
        break
    print dp[n][s]

Submission status: Runtime Error

Solution code:
import sys,itertools
for l in sys.stdin.readlines():
    n,s=map(l.split())
    ans=0
    for d in itertools.combinations(range(10),n):
        if sum(d)==s: ans+=1
    print ans

Submission status: Runtime Error

Solution code:
dp = [[0] * 1024 for i in range(12)]

def dfs(bit, d, s):
    dp[d][s] += 1
    for i in range(10):
        if bit & (1 << i):
            dfs(bit - (1 << i), d + 1, s + (i * (d + 1)))
dfs((1 << 10) - 1,0,0)

while True:
    try:
        n, s=map(int, raw_input().split())
    except EOFError:
        break
    print dp[n][s]

Submission status: Runtime Error

Solution code:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int dp[11][331];
void rec(int bit,int d,int s)
{
	dp[d][s]++;
	for(int i=0;i<10;i++)
	{
		if(bit&(1<<i))rec(bit&~(1<<i),d+1,s+i*(d+1));
	}
}
int main()
{
	int n,s;
	rec((1<<10)-1,0,0);
	while(cin >> n >> s)
	{
		if(s>330)cout << 0 << endl;
		else cout << dp[n][s] << endl;
	}
	return 0;
}

Submission status: Runtime Error

Solution code:
import sys
def f0070(A,n,s):
  if n==1:
    if s in A: f=1
    else f=0
    return f
  c=0
  A=sorted(A)
  A1=A[:n][::-1]
  A2=A[-n:]
  N=range(n)
  def f(A):
    return sum([(i+1)*A[i] for i in N])
  if f(A1)<=s<=f(A2):
    for i in range(len(A)):
      b=s-A[i]*n
      c+=f0070(A[:i]+A[i+1:],n-1,b)
  return c

for a in sys.stdin:
  n,s=map(int,a.split())
  print f0070(range(10),n,s)

Submission status: Runtime Error

Solution code:
import sys
def f0070(A,n,s):
  if n==1:return s in A
  A=sorted(A)
  A1=A[:n+1][::-1]
  A2=A[-n-1:]
  b1=0
  b2=0
  c=0
  for i in range(1,n+1):
    b1+=i*A1[i]
    b2+=i*A2[i]
  if b1<=s<=b2:
    for i in range(len(A)):
      c+=f0070(A[:i]+A[i+1:],n-1,s-A[i]*n)
  return c
for a in sys.stdin:
  n,s=map(int,a.split())
  print f0070(range(10),n,s)

Submission status: Runtime Error

Solution code:
while True:
    try:
        count = 0
        for i1 in range(10): 
            for i2 in range(10): 
                if i1 == i2:
                    continue
                for i3 in range(10):
                    if i1==i3 or i2==i3:
                        continue
                    for i4 in range(10):
                        if i1==i4 or i2==i4 or i3==i4:
                            continue
                        for i5 in range(10): 
                            if i1==i5 or i2==i5 ori3==i5 or i4==i5:
                                continue
                            for i6 in range(10):
                                if i1==i6 or i2==i6 or i3==i6 or i4==i6 or i5==i6:
                                    continue
                                for i7 in range(10): 
                                    if i1==i7 or i2==i7 or i3==i7 or i4==i7 or i5==i7:
                                        continue
                                    elif i6==i7:
                                        continue
                                    for i8 in range(10):
                                        if i1==i8 or i2==i8 or i3==i8 or i4==i8 or i5==i8:
                                            continue
                                        elif i6==i8 or i7==i8:
                                            continue
                                        for i9 in range(10):
                                            if i1==i9 or i2==i9 or i3==i9 or i4==i9 or i5==i9:
                                                continue
                                            elif i6==i9 or i7==i9 or i8==i9:
                                                continue
                                            for i10 in range(10):
                                                if i1==i10 or i2==i10 or i3==i10 or i4==i10 or i5==i10:
                                                    continue
                                                elif i6==i10 or i7==i10 or i8==i10 or i9==i10:
                                                    continue
                                                wa = i1+2*i2+3*i3+4*i4+5*i5+6*i6+7*i7+8*i8+9*i9+10*i10
                                                if s == wa:
                                                    check = ""
                                                    check += str(i1)+str(i2)+str(i3)+str(i4)+str(i5)
                                                    check += str(i6)+str(i7)+str(i8)+str(i9)+str(i10)
                                                    if check.find(0) == 11 - n:
                                                        count += 1
        print count
    except:
        break

Submission status: Runtime Error

Solution code:
import sys
d0=[0]*1024
d1=[[0 for i in range(286)]for j in range(1024)]
B=[1,2,4,8,16,32,64,128,256,512]

def init():
  global d
  for i in range(1024):
    binary=format(i,'b')
    n0=binary.count('1')
    d0[i]=n0
    if n0==1:
      d1[i][B.index(i)]=1
    else:
      for j in range(len(binary)):
        dp=n0*j
        if binary[-j-1]=='1':
          i2=i-B[j]
          for k in range(286-dp):
            d1[i][k+dp]+=d1[i2][k]
  return
  
def f0070(n,s):
  x=sum([d1[i][s] for i in range(1024) if d0[i]==n])
  return x

init()
for a in sys.stdin:
  n,s=map(int,a.split())
  print f0070(n,s)

Submission status: Runtime Error

Solution code:
import sys
d0=[0]*1024
d1=[[0 for i in range(286)]for j in range(1024)]
B=[1,2,4,8,16,32,64,128,256,512]

def init():
  global d0,d1
  for i in range(1024):
    binary=format(i,'b')
    n0=binary.count('1')
    d0[i]=n0
    if n0==1:
      d1[i][B.index(i)]=1
    else:
      for j in range(len(binary)):
        dp=n0*j
        if binary[-j-1]=='1':
          i2=i-B[j]
          for k in range(286-dp):
            d1[i][k+dp]+=d1[i2][k]
  return
  
def f0070(n,s):
  x=sum([d1[i][s] for i in range(1024) if d0[i]==n])
  return x

init()
for a in sys.stdin:
  n,s=map(int,a.split())
  print f0070(n,s)

Submission status: Runtime Error

Solution code:
import sys
K=1024
R=range(K)
B=[1,2,4,8,16,32,64,128,256,512]
C=[0]*K
D=[[0 for i in range(286)]for j in R]

def init():
  global C,D
  for i in R:
    s=format(i,'b')
    n=s.count('1')
    C[i]=n
    if n==1:D[i][B.index(i)]=1
    else:
      for j in range(len(s)):
        if s[-j-1]=='1':
          dp=n*j
          i2=i-B[j]
          for k in range(286-dp):
            D[i][k+dp]+=D[i2][k]
  return
   
init()
for a in sys.stdin:
  n,s=map(int,a.split())
  x=sum([D[i][s] for i in R if C[i]==n])
  print x

Submission status: Runtime Error

Solution code:
import sys
K=1024
R=range(K)
B=[1,2,4,8,16,32,64,128,256,512]
C=[0]*K
D=[[0 for i in range(331)]for j in R]

def init():
  global C,D
  for i in R:
    s=format(i,'b')
    n=s.count('1')
    C[i]=n
    if n==1:D[i][B.index(i)]=1
    else:
      for j in range(len(s)):
        if s[-j-1]=='1':
          dp=n*j
          i2=i-B[j]
          for k in range(331-dp):
            D[i][k+dp]+=D[i2][k]
  return
   
init()
for a in sys.stdin:
  n,s=map(int,a.split())
  x=sum([D[i][s] for i in R if C[i]==n])
  print x

Submission status: Runtime Error

Solution code:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef vector <int> vi;
typedef vector <vi> vvi;
int K=1024,N=331,B[]={1,2,4,8,16,32,64,128,256,512},C[1024]={0};
vvi D(K,vi(N));
int init(){
	vi z(K);
	for (int i=0;i<N;i++)z[i]=0;
	for (int i=0;i<K;i++){
		D[i] = z;
		int tmp=i,tmp2=0,n=0;
		while (tmp){
			n+=tmp&1;
			tmp2++;
			tmp/=2;
		}
		C[i]=n;
		if(n==1)D[i][find(B,B+10,i)-B]=1;
		else{
			tmp = i;
			for (int j=0;j<tmp2;j++){
				if (tmp & 1){
					int dp = n*j,i2=i-B[j];
					for (int k=0;k<N-dp;k++)
						D[i][k+dp]+=D[i2][k];
				}
				tmp/=2;
			}
		}
	}
	return 0;
}
int main(){
	init();
	int n,s,i,x;
	while(1){
		cin>>n>>s;
		if(cin.eof())break;
		x=0;
		if(s<N)
			for(i=0;i<N;i++)
				if(C[i]==n)x+=D[i][s];
		cout<<x<<endl;
	}
}

Submission status: Runtime Error

Solution code:
def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else:       return 0
    elif s-mx(9-m) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

def mx(n):
    if n == 0: return 0
    else:      return (n+1)*n + mx(n-1)

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else:         print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else          : return 0
    elif s-mx(9-m) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

def mx(n):
    if n == 0: return 0
    else       : return (n+1)*n + mx(n-1)

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else            : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(9-m) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

def mx(i):
    if i == 0: return 0
    else     : return (i+1)*i + mx(i-1)

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(9-m) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

def mx(i):
    if i <= 0: return 0
    else     : return (i+1)*i + mx(i-1)

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(9-m)-1 <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

def mx(i):
    if i == 0: return 0
    else     : return (i+1)*i + mx(i-1)

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(9-m)-1 <= sm and sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

def mx(i):
    if i == 0: return 0
    else     : return (i+1)*i + mx(i-1)

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(n-m)-1 <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

def mx(i):
    if i == 0: return 0
    else     : return (i+1)*i + mx(i-1)

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(i):
    if i == 0: return 0
    else     : return (i+1)*i + mx(i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(n-m) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(i):
    if i == 0: return 0
    else     : return (i+1)*i + mx(i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(n-m+1)-1 <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(i):
    if i == 0: return 0
    else     : return (i+1)*i + mx(i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(n-m+1)-2 <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(i):
    if i == 0: return 0
    else     : return (i+1)*i + mx(i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(n-m+1)-5 <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(i):
    if i == 0: return 0
    else     : return (i+1)*i + mx(i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(n-m+2) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(ls,i):
    if i == 0: return 0
    else     : return (i+1)*ls.pop()+ mx(i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(ls,n-m+1) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(ls,i):
    if i == 0: return 0
    else     : return (i+1)*ls.pop()+ mx(i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(ls,n-m+1) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(ls,n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(ls,i):
    if i == 0: return 0
    else     : return (i+1)*ls.pop()+ mx(ls,i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(ls,n-m+1) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(ls,n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(ls,i):
    rls = ls[:]
    if i == 0: return 0
    else     : return (i+1)*rls.pop()+ mx(rls,i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(ls,n-m+1) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(ls,n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(ls,i):
    rls = ls[:]
    if i == 0 or len(rls) == 0: return 0
    else     : return (i+1)*rls.pop()+ mx(rls,i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(ls,n-m) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(ls,n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(ls,i):
    rls = ls[:]
    if i <= 0 or len(rls) == 0: return 0
    else     : return (i+1)*rls.pop()+ mx(rls,i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s-mx(ls,n-m) <= sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(ls,n): print 0
    else        : print cns(ls,0,0)

Submission status: Runtime Error

Solution code:
def mx(ls,i):
    rls = ls[:]
    if i <= 0 or len(rls) == 0: return 0
    else     : return (i+1)*rls.pop()+ mx(rls,i-1)

def cns(ls,m,sm):
    global n, s
    count = 0
    if m == n:
        if sm == s: return 1
        else      : return 0
    elif s <= sm + mx(ls,n-m) and sm <= s:
        for i in range(9-m+1):
            rls = ls[:]
            k = rls.pop(i)
            count += cns(rls,m+1,sm+(m+1)*k)
        return count
    else: return 0

ls = [0,1,2,3,4,5,6,7,8,9]
while True:
    n, s = map(int, raw_input().split())
    if s > mx(ls,n): print 0
    else        : print cns(ls,0,0)