# Python program for OEIS A061310
# Michael S. Branicky, Feb 08 2023

# A061310		Numbers which cannot be reached in the Countdown Numbers Game starting from (1,2,3,4,5,6): the game allows brackets and the operations + - x and / and not all numbers need be used, while the result of each partial calculation must be an integer.		0
data = [284, 307, 309, 314, 317, 379, 394, 398, 403, 411, 417, 423, 429, 431, 433, 435, 436, 437, 439, 441, 442, 443, 445, 446, 447, 449, 451, 453, 454, 457, 458, 459, 461, 463, 464, 466, 467, 469, 471, 473, 474, 487, 489, 491, 493, 494, 496, 499, 502, 506, 509]

# (Python)
from collections import Counter
def canmake(v):
    n, vc = len(v), Counter(v)
    R = dict() # index of each reachable subset is [card(s)-1][s]
    for i in range(n): R[i] = dict()
    for i in range(n): R[0][(v[i], )] = {v[i]}
    reach = set(v)
    for j in range(1, n):
        for i in range((j+1)//2):
            for s1 in R[i]:
                for s2 in R[j-1-i]:
                    s12c = Counter(s1 + s2)
                    if all(s12c[e] <= vc[e] for e in s12c):
                        s12 = tuple(sorted(s1 + s2))
                        if s12 not in R[len(s12)-1]:
                            R[len(s12)-1][s12] = set()
                        for a in R[i][s1]:
                            for b in R[j-1-i][s2]:
                                allowed = [a+b, a*b, a-b, b-a]
                                if a!=0 and b%a==0: allowed.append(b//a)
                                if b!=0 and a%b==0: allowed.append(a//b)
                                R[len(s12)-1][s12].update(allowed)
                                reach.update(allowed)
    return reach

R = canmake((1,2,3,4,5,6)) # reachable set
assert max(R) == 1080

ans = sorted(set(range(1081)) - R)

print(ans)
assert ans[:len(data)] == data

with open('b061310.txt', 'w') as bfile:
    for n, an in enumerate(ans, 1):
        bfile.write(f"{n} {an}\n")