1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
n,s = map(int, input().split())

all_sets = [set() for _ in range(n+1)]

for i in range(1, n+1):
    for j in range(i, n+1, i):
        all_sets[i].add(j)

B = set(map(int, input().split()))

path = list()
queue = list()

if B != all_sets[-1]:
    queue = [(B, -1, [], False), (all_sets[1] - B, -2, ["3 -1"], True)]

#print(queue)

####
while queue:

    target, node, path, is_reversed = queue.pop(0)

    if len(target) == 0 and not is_reversed:
        break

    can_sum_to_target = list()
    can_union_to_target = list()

    for x in range(1, n+1):
        #print(all_sets[x], target)
        if all_sets[x] <= target:
            can_sum_to_target.append((len(all_sets[x]), x))
        """if all_sets[x] >= target:
            can_union_to_target.append(x)"""
    
    #print(can_sum_to_target)

    new_target = set()

    """if len(can_union_to_target) >= 2:
        #print("Target:", target)
        path = path + ["2 {} {}".format(*can_union_to_target[:2])]
        break"""

    can_sum_to_target.sort(reverse=True)
    summation = list()

    for _, x in can_sum_to_target:
        if len(new_target | all_sets[x]) > len(new_target):
            new_target.update(all_sets[x])
            summation.append(x)

    new_target = target - new_target

    #print(target, node, summation, new_target, path)

    if len(new_target) == 0:
        if len(summation) == 0:
            continue
        if len(summation) == 1 and node == -1:
                queue.append((new_target, node-1, [f"1 {summation[0]} {summation[0]}"], False))
        else:
            path += ["1 {} {}".format(node - j, i) for j, i in enumerate(summation[2:])]
            path += ["1 {} {}".format(*summation[:2])]
            queue.append((new_target, node - len(summation), path, False))
    else:
        queue.append((new_target, node - len(summation), path + ["1 {} {}".format(node - j, i) for j, i in enumerate(summation)], False))
        queue.append((all_sets[1] - new_target, node - len(summation) - 1, path + ["1 {} {}".format(node - j, i) for j, i in enumerate(summation)] + [f"3 {node-len(summation)}"], True))
    
#print(path)

m = len(path)

path = path[::-1]

for i in range(m):
    line = list(map(int, path[i].split()))
    if line[1] < 0:
        line[1] = line[1] + m+n
    path[i] = " ".join(map(str, line))

print(m)

for x in path:
    print(x)

###