Under construction

Still being built. Things may change

One Pass Short

Time limit2sMemory limit512 MB

Summary
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.
Level

Hard9 of 10

Topics
Graph, Shortest path, Implementation, Brute force
Solved
No attempts yet

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 N−2N - 2 times. It should have been N−1N - 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. (50≤N≤10050 \le N \le 100)

Output

On the first line print the number of vertices NN and the number of edges MM. (0≤M≤N×(N−1)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. (1≤s,e≤N1 \le s, e \le N, s≠es \ne e, d=1d = 1 or d=−1d = -1)

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

Examples2

  1. Example 1

    Input
    50
    
    Expected output
    50 49
    1 2 -1
    3 1 -1
    4 3 -1
    5 4 -1
    6 5 -1
    7 6 -1
    8 7 -1
    9 8 -1
    10 9 -1
    11 10 -1
    12 11 -1
    13 12 -1
    14 13 -1
    15 14 -1
    16 15 -1
    17 16 -1
    18 17 -1
    19 18 -1
    20 19 -1
    21 20 -1
    22 21 -1
    23 22 -1
    24 23 -1
    25 24 -1
    26 25 -1
    27 26 -1
    28 27 -1
    29 28 -1
    30 29 -1
    31 30 -1
    32 31 -1
    33 32 -1
    34 33 -1
    35 34 -1
    36 35 -1
    37 36 -1
    38 37 -1
    39 38 -1
    40 39 -1
    41 40 -1
    42 41 -1
    43 42 -1
    44 43 -1
    45 44 -1
    46 45 -1
    47 46 -1
    48 47 -1
    49 48 -1
    50 49 -1
    
  2. Example 2

    Input
    51
    
    Expected output
    51 50
    1 2 -1
    3 1 -1
    4 3 -1
    5 4 -1
    6 5 -1
    7 6 -1
    8 7 -1
    9 8 -1
    10 9 -1
    11 10 -1
    12 11 -1
    13 12 -1
    14 13 -1
    15 14 -1
    16 15 -1
    17 16 -1
    18 17 -1
    19 18 -1
    20 19 -1
    21 20 -1
    22 21 -1
    23 22 -1
    24 23 -1
    25 24 -1
    26 25 -1
    27 26 -1
    28 27 -1
    29 28 -1
    30 29 -1
    31 30 -1
    32 31 -1
    33 32 -1
    34 33 -1
    35 34 -1
    36 35 -1
    37 36 -1
    38 37 -1
    39 38 -1
    40 39 -1
    41 40 -1
    42 41 -1
    43 42 -1
    44 43 -1
    45 44 -1
    46 45 -1
    47 46 -1
    48 47 -1
    49 48 -1
    50 49 -1
    51 50 -1