Problem: Berland Government decided to improve relations with neighboring countries. First of all, it was decided to build new roads so that from each city of Berland and neighboring countries it became possible to reach all the others. There are n cities in Berland and neighboring countries in total and exactly n - 1 two-way roads. Because of the recent financial crisis, the Berland Government is strongly pressed for money, so to build a new road it has to close some of the existing ones. Every day it is possible to close one existing road and immediately build a new one. Your task is to determine how many days would be needed to rebuild roads so that from each city it became possible to reach all the others, and to draw a plan of closure of old roads and building of new ones.

Input

The first line contains integer n (2 ≤ n ≤ 1000) — amount of cities in Berland and neighboring countries. Next n - 1 lines contain the description of roads. Each road is described by two space-separated integers ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi) — pair of cities, which the road connects. It can't be more than one road between a pair of cities. No road connects the city with itself.

Output

Output the answer, number t — what is the least amount of days needed to rebuild roads so that from each city it became possible to reach all the others. Then output t lines — the plan of closure of old roads and building of new ones. Each line should describe one day in the format i j u v — it means that road between cities i and j became closed and a new road between cities u and v is built. Cities are numbered from 1. If the answer is not unique, output any.

Examples

Input

2
1 2


Output

0


Input

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


Output

1
3 1 3 7

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
// import java.nio.charset.StandardCharsets;

// remember to check if n=0, n=1 are special cases 

public class D {
    static Writer wr;

    public static void main(String[] args) throws Exception {
        // String testString = "";
        // InputStream stream = new ByteArrayInputStream(testString.getBytes(StandardCharsets.UTF_8));
        // Reader in = new Reader(stream);
        // long startTime = System.nanoTime();
        // long elapsedTime = System.nanoTime() - startTime;
        // double seconds = (double)elapsedTime / 1000000000.0;
        // System.out.println(seconds);

        wr = new Writer();

        Reader in = new Reader();
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        int N = in.nextInt();

        DisjointSet ds = new DisjointSet(N);

        for(int i=1; i<=N-1; i++) {
            int a = in.nextInt();
            int b = in.nextInt();

            ds.add_pair_and_union(a, b);
        }
        ArrayList<Integer[]> deletion_candidates = ds.deletion_candidates;
        ArrayList<Integer> components = ds.get_components();

        int days = components.size()-1;
        
        out.write(days + "\n");

        for(int i=0;i<days;i++) {
            // wr.writePink(" " + components.get(i));
            out.write(deletion_candidates.get(i)[0] 
                        + " " + deletion_candidates.get(i)[1] 
                        + " " + components.get(i) 
                        + " " + components.get(i+1)
                        + "\n");
        }

        out.flush();
    }
}

class DisjointSet {
    Writer wr;
    int[] parent;
    int[] arr;
    int N, stick1, MAX_N;
    HashMap<Integer, Integer> dict;
    public ArrayList<Integer[]> deletion_candidates;

    public DisjointSet(int _N) {
        wr = new Writer();
        stick1 = 0;
        N = 1000;
        MAX_N = _N;
        parent = new int[N];
        arr = new int[N];
        dict = new HashMap<>();
        Arrays.fill(parent, -1);

        deletion_candidates = new ArrayList<>();
    }

    public int find_representative(int x) {
        if(parent[x]!=x) {
            parent[x] = find_representative(parent[x]);
        }
        return parent[x];
    }

    public int add(int x) {
        if(dict.get(x)==null) {
            arr[stick1] = x;
            dict.put(x, stick1);
            parent[stick1] = stick1;
            stick1++;
            return stick1-1;
        }
        return dict.get(x);
    }

    public void add_pair_and_union(int x, int y) {
        int pos_x = add(x);
        int pos_y = add(y);

        int rep_x = find_representative(pos_x);
        int rep_y = find_representative(pos_y);

        if(rep_x != rep_y) {
            parent[rep_y] = rep_x; //union
        }
        else {
            //candidate for deletion
            deletion_candidates.add(new Integer[]{x, y});
            // wr.writeRed(Arrays.toString(new Integer[]{x, y}));
        }

        // wr.writeBlue(Arrays.toString(Arrays.copyOfRange(parent, 0, 4)));
    }

    public ArrayList<Integer> get_components() {
        ArrayList<Integer> ans = new ArrayList<>();
        // System.out.println(MAX_N);
        for(int i=1; i<=MAX_N;i++) {

            if(dict.get(i)==null) {
                // System.out.println("->"+i);
                ans.add(i);
            }
            else {
                // System.out.println(i);
                int pos_i = dict.get(i);
                if(parent[pos_i]==pos_i) {
                    ans.add(i);
                }    
            }
            
            
        }
        return ans;
    }

}

class Writer {
    public void writeRed(String x) {
        System.out.println((char)27 + "[31m" + (char)27 + "[40m" + x + (char)27 + "[0m");
    }
    public void writeBlue(String x) {
        System.out.println((char)27 + "[34m" + (char)27 + "[3m" + x + (char)27 + "[0m");
    }
    public void writeGreen(String x) {
        System.out.println((char)27 + "[32m" + (char)27 + "[3m" + x + (char)27 + "[0m");
    }
    public void writePink(String x) {
        System.out.println((char)27 + "[30m" + (char)27 + "[45m" + x + (char)27 + "[0m");
    }
}

class Reader {
    final private int BUFFER_SIZE = 1 << 16;private DataInputStream din;private byte[] buffer;private int bufferPointer, bytesRead;
    public Reader(){din=new DataInputStream(System.in);buffer=new byte[BUFFER_SIZE];bufferPointer=bytesRead=0;}
    public Reader(InputStream stream){din=new DataInputStream(stream);buffer=new byte[BUFFER_SIZE];bufferPointer=bytesRead=0;}
    public String readLine()throws IOException{byte[] buf=new byte[1024];int cnt=0,c;
        while((c=read())!=-1){if(c=='\n')break;buf[cnt++]=(byte)c;}return new String(buf,0,cnt);}
    public char nextChar()throws IOException{byte c=read();while(c<=' ')c=read();return (char)c;}
    public int nextInt()throws IOException{int ret=0;byte c=read();while(c<=' ')c=read();boolean neg=(c=='-');
        if(neg)c=read();do{ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');if(neg)return -ret;return ret;} 
    public long nextLong()throws IOException{long ret=0;byte c=read();while(c<=' ')c=read();boolean neg=(c=='-');
        if(neg)c=read();do{ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');if(neg)return -ret;return ret;}
    public double nextDouble()throws IOException{double ret=0,div=1;byte c=read();while(c<=' ')c=read();boolean neg=(c=='-');if(neg)c = read();do {ret=ret*10+c-'0';}while((c=read())>='0'&&c<='9');
        if(c=='.')while((c=read())>='0'&&c<='9')ret+=(c-'0')/(div*=10);if(neg)return -ret;return ret;}
    private void fillBuffer()throws IOException{bytesRead=din.read(buffer,bufferPointer=0,BUFFER_SIZE);if(bytesRead==-1)buffer[0]=-1;}
    private byte read()throws IOException{if(bufferPointer==bytesRead)fillBuffer();return buffer[bufferPointer++];}
    public void close()throws IOException{if(din==null) return;din.close();}
}