PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#DSU0000015. Những con đường ở Berland (Roads not only in Berland)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Những con đường ở Berland (Roads not only in Berland)

Roads not only in Berland

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Berland has nn cities and exactly n−1n-1 bidirectional roads, but the road network need not be connected. In one day, you may remove an existing road and build a new road between two cities.

Find the minimum number of days required to make all cities connected and output a valid plan.

Input

The first line contains an integer nn. Each of the next n−1n-1 lines contains two integers a,ba,b describing an existing road. Cities are numbered from 11 to nn.

Output

Print the minimum number kk of days on the first line. For each day, print four integers a,b,c,da,b,c,d: remove road (a,b)(a,b) and build road (c,d)(c,d). Any optimal valid plan is accepted.

Subtasks

  • Subtask 1 (20 points): 2≤n≤1502\le n\le 150; exactly n−1n-1 edges; 1≤a,b≤n1\le a,b\le n; a≠ba\ne b; no repeated edges.
  • Subtask 2 (30 points): 2≤n≤6002\le n\le 600; exactly n−1n-1 edges; 1≤a,b≤n1\le a,b\le n; a≠ba\ne b; no repeated edges.
  • Subtask 3 (50 points): 2≤n≤10002\le n\le 1000; exactly n−1n-1 edges; 1≤a,b≤n1\le a,b\le n; a≠ba\ne b; no repeated edges.

Examples

Input

7
1 2
2 3
3 1
4 5
5 6
6 7

Output

1
3 1 1 4

Explanation

Vertices 1,2,3 form a cycle: one edge can be removed without disconnecting its component, then used to connect the other component in one day.