import sys
# Helper function to calculate the lexicographic index of an edge {u, v} where u < v.
# Node indices u and v are 1-based. The returned index is also 1-based.
def get_edge_index(u, v, n):
"""Calculates the 1-based lexicographical index for edge {u, v} given n nodes."""
# Ensure u < v, which is the convention for lexicographical ordering and indexing.
if u >= v:
raise ValueError("u must be less than v for edge indexing")
# Calculate the number of edges that lexicographically precede any edge starting with node u.
# This is the sum of (n-x) for x from 1 to u-1.
# The formula derived is: n*(u-1) - (u-1)*u / 2
# Uses integer division // for correctness.
edges_before_u = (u - 1) * n - (u - 1) * u // 2
# Calculate the offset of the edge {u, v} within the block of edges starting with node u.
# The edges starting with u are {u, u+1}, {u, u+2}, ..., {u, n}.
# The edge {u, v} is the (v - (u+1))-th edge after the first one {u, u+1}.
# So the 0-based offset is (v - (u+1)).
offset_within_u = v - (u + 1)
# The total index is 1 (for 1-based indexing) plus the count of preceding edges
# and the offset within the current block.
return 1 + edges_before_u + offset_within_u
# Helper function to create a node permutation dictionary.
# The dictionary maps node ID -> permuted node ID.
def get_node_perm(group_nodes, perm_type, n):
"""
Creates a dictionary representing the node permutation for the given group.
'n' is the total number of nodes in the graph (used for context, e.g., identity mapping).
'group_nodes' is a list of node IDs in the group, e.g., [L, L+1, ..., R].
'perm_type' is either 'full_cycle' or 'two_cycle'.
"""
# Initialize the permutation as an identity map for all nodes from 1 to n.
# Nodes outside the specified group remain fixed.
perm = {i: i for i in range(1, n + 1)}
# If the group is empty or contains only one node, no permutation occurs within the group.
if not group_nodes or len(group_nodes) < 2:
return perm
# Get the start (L) and end (R) nodes of the group.
L = group_nodes[0]
R = group_nodes[-1]
if perm_type == 'full_cycle':
# Create the cyclic permutation (L, L+1, ..., R)
# s(i) = i+1 for L <= i < R
for i in range(L, R):
perm[i] = i + 1
# s(R) = L, completing the cycle.
perm[R] = L
elif perm_type == 'two_cycle':
# Create the transposition (L, L+1)
# s(L) = L+1, s(L+1) = L
# This requires at least two nodes in the group (L < R), which is guaranteed
# by the check `len(group_nodes) < 2` above.
perm[L] = L + 1
perm[L + 1] = L
return perm
# Helper function to compute the edge permutation map.
# Returns an array where perm_array[i] stores the destination index for the edge with original index i.
def get_edge_permutation_array(node_perm, n):
"""
Computes the permutation of edge indices induced by the node permutation.
Returns an array representing the mapping: original_edge_index -> new_edge_index.
"""
# Calculate the total number of edges in the complete graph K_n.
num_edges = n * (n - 1) // 2
# Initialize the permutation array. Size is num_edges + 1 because indices are 1-based.
# Index 0 is unused to align with 1-based indexing.
perm_array = [0] * (num_edges + 1)
# Iterate through all unique pairs {u, v} representing edges, where u < v.
for u in range(1, n + 1):
for v in range(u + 1, n + 1):
# Get the original 1-based index of the edge {u, v}.
original_edge_idx = get_edge_index(u, v, n)
# Apply the node permutation to the endpoints u and v.
u_prime = node_perm[u]
v_prime = node_perm[v]
# Determine the canonical representation of the new edge {u', v'}
# by ordering the permuted endpoints: new_u < new_v.
new_u = min(u_prime, v_prime)
new_v = max(u_prime, v_prime)
# Calculate the 1-based index of the permuted edge {new_u, new_v}.
new_edge_idx = get_edge_index(new_u, new_v, n)
# Store the mapping: original_edge_idx maps to new_edge_idx.
perm_array[original_edge_idx] = new_edge_idx
return perm_array
# Helper function to format and print the cycle notation of a permutation.
def print_cycle_notation(perm_array):
"""
Finds disjoint cycles in the permutation represented by perm_array and prints them
according to the specified format rules:
- Cycles ordered by their smallest element (ascending).
- Each cycle starts with its smallest element.
- Fixed points (1-cycles) are omitted.
- Cycles are formatted as (e1, e2, ...) and separated by spaces.
"""
num_edges = len(perm_array) - 1
# Keep track of visited edge indices to ensure each element belongs to exactly one cycle.
visited = [False] * (num_edges + 1)
cycles = []
# Iterate through all possible edge indices from 1 to num_edges.
for i in range(1, num_edges + 1):
# Start tracing a new cycle if the current index 'i' has not been visited yet
# AND if it's not a fixed point (i.e., its mapped value is different from itself).
if not visited[i] and perm_array[i] != i:
current_cycle = []
current_idx = i
# Trace the cycle starting from index 'i'.
while not visited[current_idx]:
# Mark the current index as visited.
visited[current_idx] = True
# Add the current index to the list forming the current cycle.
current_cycle.append(current_idx)
# Move to the next index in the permutation sequence.
current_idx = perm_array[current_idx]
# If a cycle was successfully traced (list is not empty), add it to our list of cycles.
if current_cycle:
cycles.append(current_cycle)
# Sort the found cycles based on their smallest element. The cycle finding process naturally
# starts tracing from the smallest available element `i`, so `current_cycle[0]` is the minimum element.
cycles.sort(key=lambda x: x[0])
# Format the cycles into strings "(e1, e2, ...)"
output_parts = []
for cycle in cycles:
output_parts.append("(" + ", ".join(map(str, cycle)) + ")")
# Print all formatted cycles separated by spaces. If no cycles were found (only fixed points),
# this will print nothing, which is the correct behavior.
if output_parts:
print(" ".join(output_parts))
# Main function to orchestrate the process: read input, process groups, and print output.
def solve():
"""Reads group sizes, calculates permutations, and prints results."""
# Read the space-separated group sizes from the first line of input.
ns = list(map(int, sys.stdin.readline().split()))
k = len(ns) # The number of groups.
current_node_idx = 0 # Keeps track of the last node index used.
group_definitions = [] # Stores tuples of (L_i, R_i, n_i) for each group.
# Determine the node ranges [L_i, R_i] and size n_i for each group.
for i in range(k):
n_i = ns[i] # Size of the current group i.
L_i = current_node_idx + 1 # Start node ID for group i.
R_i = current_node_idx + n_i # End node ID for group i.
group_definitions.append((L_i, R_i, n_i))
# Update the tracker for the start node of the next group.
current_node_idx = R_i
# The total number of nodes in the graph is the end index of the last group.
total_n = current_node_idx
# Process each group based on the problem requirements.
for L, R, n_i in group_definitions:
# Skip groups of size less than 2, as they don't generate relevant permutations.
if n_i < 2:
continue
# Get the list of node IDs belonging to the current group.
group_nodes = list(range(L, R + 1))
# --- Generate and print permutation for the full cycle of the group ---
# Define the node permutation corresponding to the full cycle (L, L+1, ..., R).
node_perm_full = get_node_perm(group_nodes, 'full_cycle', total_n)
# Calculate the induced permutation on the edges.
edge_perm_array_full = get_edge_permutation_array(node_perm_full, total_n)
# Print the resulting cycle notation.
print_cycle_notation(edge_perm_array_full)
# --- Generate and print permutation for the 2-cycle if group size > 2 ---
# The problem requires an additional output for a 2-cycle if the group size n_i > 2.
if n_i > 2:
# Define the node permutation corresponding to the 2-cycle (L, L+1).
node_perm_two = get_node_perm(group_nodes, 'two_cycle', total_n)
# Calculate the induced permutation on the edges.
edge_perm_array_two = get_edge_permutation_array(node_perm_two, total_n)
# Print the resulting cycle notation.
print_cycle_notation(edge_perm_array_two)
# Standard boilerplate to call the main function when the script is executed.
if __name__ == '__main__':
solve()