Graceful Triangles
Time limit2sMemory limit1024 MB
Given n, assign distinct positive values to the n+2 vertices of a triangle strip so that edge differences cover 1 to 2n+1 exactly once, or report -1.
- Level
Medium7 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
Consider the following graph, made of equilateral triangles joined side by side from left to right.

The graph has vertices and edges. The vertices are numbered from left to right as shown in the figure.
In other words, the vertices are labeled through , and there is an edge between every pair of vertices whose labels differ by at most .
Each vertex is assigned a positive integer. Vertex has the value . The value of the edge connecting vertices and is . Assign values to all vertices so that for every integer with , exactly one edge has value . No vertex value may exceed .
Input
The first line contains a positive integer .
Output
If a solution exists for the given , print the values of vertices on one line, separated by spaces. Each value must be a positive integer not exceeding . Otherwise, print .