This page is still under construction.

Parts of this page are still being built. What you see may change.

The course Mirko wins

Time limit3sMemory limit128 MB

Summary
Find the directed cycle where Mirko beats Slavko with the fewest roads, breaking ties by the largest time difference.
Level

Medium7 of 10

Topics
Shortest path, Graph, Dynamic programming
Solved
No attempts yet

Problem

Mirko and Slavko are the only two contestants in the Dabrovina Donja Grand Prix. The race runs through nearby villages, and the villages are connected by one way roads. For road ii we know MiM_i, the time Mirko needs to cross it, and SiS_i, the time Slavko needs.

A course starts in some village and returns to that same village. Mirko's time on a course is the sum of MiM_i over its roads, and Slavko's time is the sum of SiS_i. Mirko wins the course when his time is smaller than Slavko's, and the difference between the two times is Mirko's advantage.

The course is not decided yet. Mirko has bribed the organisers, so they will pick a course that Mirko wins with as few roads as possible. If several courses use that number of roads, the organisers pick one where Mirko's advantage is largest.

Input

The first line contains two integers NN and MM, the number of villages and the number of roads. (2≤N≤3002 \le N \le 300, 2≤M≤N(N−1)2 \le M \le N(N-1))

Each of the next MM lines contains four integers AiA_i, BiB_i, MiM_i, SiS_i describing one road. (1≤Ai,Bi≤N1 \le A_i, B_i \le N, Ai≠BiA_i \ne B_i, 0≤Mi,Si≤1060 \le M_i, S_i \le 10^6) The road runs one way from village AiA_i to village BiB_i, Mirko needs MiM_i time to cross it and Slavko needs SiS_i. No two roads connect the same pair of villages in the same direction.

At least one course that Mirko wins exists.

Output

Print, on one line separated by a space, the number of roads on the course the organisers pick and Mirko's advantage on that course.

Examples2

  1. Example 1

    Input
    3 4
    1 2 3 0
    2 3 3 0
    3 1 0 100
    2 1 0 4
    
    Expected output
    2 1
    
  2. Example 2

    Input
    5 7
    1 2 4 1
    2 3 5 1
    3 1 1 6
    1 3 15 5
    2 4 7 5
    4 5 1 4
    5 3 1 0
    
    Expected output
    5 2