Buggy python submission (verdict: Time Limit Exceeded):
def check(s_i, n_i, count, i_set):
    for i in range(9):
        i_set_tmp = set(i_set)
        if i not in i_set_tmp:
            continue
        s_tmp = s_i
        n_tmp = n_i
        if s_tmp == 0 and n_tmp == 0:
            return count + 1
        elif s_tmp < 0 or n_tmp == 0:
            break
        else:
            s_tmp -= i*n_tmp
            n_tmp -= 1
            i_set_tmp.remove(i)
            count = check(s_tmp, n_tmp, count, i_set_tmp)
    return count

while True:
    try:
        n, s = map(int, input().split())
        print(check(s, n, 0, set([0,1,2,3,4,5,6,7,8,9])))
    except:
        break



Fixed submission:
s_max = [0]
for i in range(1,11):
    s = 0
    for j in range(i):
        s += (10 - j - 1)*(i - j)
    s_max.append(s)

def check(u, r, s, m):
    if r == 0:
        return s == 0
    n = 0
    for i in range(10):
        n *= 2
        if u[i]:
            n += 1
    if (n, r, s) in m:
        return m[(n, r, s)]
    if s < 0 or s > s_max[r]:
        return 0

    ans = 0
    for i in range(10):
        if not u[i]:
            u[i] = True
            ans += check(u, r - 1, s - i*r, m)
            u[i] = False
    m[(n, r, s)] = ans
    return m[(n, r, s)]

memo = {}
while True:
    try:
        n, s = map(int, input().split())
        used = [False for i in range(10)]
        ans = check(used, n, s, memo)
        print(ans)
    except:
        break

Buggy python submission (verdict: Time Limit Exceeded):
def check(s_i, n_i, count, i_set):
    for i in range(9):
        print("s:",s_i,"n:",n_i,"i:",i,"count:",count)
        i_set_tmp = set(i_set)
        if i not in i_set:
            continue
        s_tmp = s_i - i*n_i
        n_tmp = n_i - 1
        if s_tmp == 0 and n_tmp == 0:
            return count + 1
        elif s_tmp < 0 or n_tmp < 0:
            break
        else:
            i_set_tmp.remove(i)
            count = check(s_tmp, n_tmp, count, i_set_tmp)
    return count

while True:
    try:
        n, s = map(int, input().split())
        print(check(s, n, 0, set([0,1,2,3,4,5,6,7,8,9])))
    except:
        break



Fixed submission:
s_max = [0]
for i in range(1,11):
    s = 0
    for j in range(i):
        s += (10 - j - 1)*(i - j)
    s_max.append(s)

def check(u, r, s, m):
    if r == 0:
        return s == 0
    n = 0
    for i in range(10):
        n *= 2
        if u[i]:
            n += 1
    if (n, r, s) in m:
        return m[(n, r, s)]
    if s < 0 or s > s_max[r]:
        return 0

    ans = 0
    for i in range(10):
        if not u[i]:
            u[i] = True
            ans += check(u, r - 1, s - i*r, m)
            u[i] = False
    m[(n, r, s)] = ans
    return m[(n, r, s)]

memo = {}
while True:
    try:
        n, s = map(int, input().split())
        used = [False for i in range(10)]
        ans = check(used, n, s, memo)
        print(ans)
    except:
        break

Buggy python submission (verdict: Time Limit Exceeded):
def check(s_i, n_i, count, i_set):
    for i in range(9):
        i_set_tmp = set(i_set)
        if i not in i_set:
            continue
        if s_i == 0 and n_i == 0:
            return count + 1
        elif s_i < 0 or n_i < 0:
            break
        else:
            s_tmp = s_i - i*n_i
            n_tmp = n_i - 1
            i_set_tmp.remove(i)
            count = check(s_tmp, n_tmp, count, i_set_tmp)
    return count

i_list = [i for i in range(10)]
while True:
    try:
        n, s = map(int, input().split())
        ans = check(s, n, 0, set(i_list))
        print(ans)
    except:
        break



Fixed submission:
s_max = [0]
for i in range(1,11):
    s = 0
    for j in range(i):
        s += (10 - j - 1)*(i - j)
    s_max.append(s)

def check(u, r, s, m):
    if r == 0:
        return s == 0
    n = 0
    for i in range(10):
        n *= 2
        if u[i]:
            n += 1
    if (n, r, s) in m:
        return m[(n, r, s)]
    if s < 0 or s > s_max[r]:
        return 0

    ans = 0
    for i in range(10):
        if not u[i]:
            u[i] = True
            ans += check(u, r - 1, s - i*r, m)
            u[i] = False
    m[(n, r, s)] = ans
    return m[(n, r, s)]

memo = {}
while True:
    try:
        n, s = map(int, input().split())
        used = [False for i in range(10)]
        ans = check(used, n, s, memo)
        print(ans)
    except:
        break