One Pass Short

Construct a directed graph with edge weights 1 or -1, no negative cycle, yet a Bellman-Ford variant that runs N-2 rounds then checks would falsely report a negative cycle; minimize the edge count and lexicographic order.

Hard9GraphShortest pathImplementationBrute forceNo attempts yetTime limit2sMemory limit512 MB

Problem

Jigui implemented the Bellman-Ford algorithm to decide whether a directed graph whose edge weights are all 11 or 1-1 has a negative cycle.

  1. Set d[v]=0d[v] = 0 for every vertex vv.
  2. One round scans every edge (s,e,w)(s, e, w) in the order given in the input and assigns min(d[e], d[s]+w)\min(d[e],\ d[s] + w) to d[e]d[e]. Each edge changes dd right away, so the next edge of the same round reads the changed values.
  3. Repeat the round N2N - 2 times. It should have been N1N - 1 times.
  4. Run one more round. If any value of dd changes during that round, report that a negative cycle exists.

Because step 3 runs one round too few, the code reports a negative cycle on a graph that has none. Build such a graph yourself and show that Jigui's code is wrong.

You are given the number of vertices NN. Print a directed graph on NN vertices whose edge weights are all 11 or 1-1, that has no negative cycle, and that the code above declares to have one. The order in which you print the edges is the order in which the code scans them, so the order is part of the answer.

Many graphs satisfy the conditions. Print the one with the smallest number of edges MM. If several graphs remain, lay the printed edges out as the sequence s1,e1,d1,s2,e2,d2,,sM,eM,dMs_1, e_1, d_1, s_2, e_2, d_2, \dots, s_M, e_M, d_M, compare the sequences number by number, and print the one that comes first.

Input

The first line contains the number of vertices NN. (50N10050 \le N \le 100)

Output

On the first line print the number of vertices NN and the number of edges MM. (0MN×(N1)0 \le M \le N \times (N - 1))

On each of the next MM lines print the start vertex ss, the end vertex ee, and the weight dd of one edge. (1s,eN1 \le s, e \le N, ses \ne e, d=1d = 1 or d=1d = -1)

Do not print the same pair (s,e)(s, e) twice.