## https://yukicoder.me/problems/no/1831 from collections import deque def main(): N = int(input()) matrixs = [[-1] * (N - 1) for _ in range(2 * N - 1)] queue = deque() for n in reversed(range(1, 2 * N)): for _ in range(n): queue.append(n) for j in range(N - 1): for i in range(2 * N - 1): matrixs[i][j] = queue.popleft() a_map = [] prev_value_tuple = None for i in range(2 * N - 1): value_tuple = tuple(matrixs[i]) if prev_value_tuple != value_tuple: a_map.append([value_tuple, 1]) else: a_map[-1][1] += 1 prev_value_tuple = value_tuple answers = [] for value_tuple, cnt in a_map: v_map = {} reserve_queue = deque() while len(queue) > 0 and cnt > 0: v = queue.popleft() if v not in v_map: v_map[v] = 0 if v_map[v] < 2: v_map[v] += 1 cnt -= 1 else: reserve_queue.append(v) if cnt > 0: print("No") return while len(reserve_queue) > 0: w = reserve_queue.pop() queue.appendleft(w) for v, cnt2 in v_map.items(): for _ in range(cnt2): t = list(value_tuple) t.append(v) answers.append(t) print(len(answers)) for tuples in answers: print(" ".join(map(str, tuples))) if __name__ == "__main__": main()