import java.util.*; public class segmentdrawing_xiaowuc1 { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] x = new int[n]; int[] y = new int[n]; Fraction[] lhs = new Fraction[n]; Fraction[] rhs = new Fraction[n]; for(int i = 0; i < n; i++) { x[i] = sc.nextInt(); y[i] = sc.nextInt(); lhs[i] = new Fraction(sc.nextInt(), 1); rhs[i] = new Fraction(sc.nextInt(), 1); } // to the right int[] stack = new int[n]; int stacksz = 0; for(int i = 0; i < n; i++) { while(stacksz > 0) { int curr = stack[stacksz-1]; if(y[curr] > y[i]) break; if(y[curr] == y[i]) { if(x[i] < x[curr]) stop(); stacksz--; continue; } Fraction xcand = null; if(x[curr] == x[i]) { xcand = new Fraction(x[i], 1); } else { Fraction slope = new Fraction(y[curr] - y[i], x[curr] - x[i]); xcand = new Fraction(x[i], 1).sub(new Fraction(y[i], 1).div(slope)); } if(xcand.compareTo(lhs[i]) > 0) lhs[i] = xcand; stacksz--; } stack[stacksz++] = i; } stacksz = 0; for(int i = n-1; i >= 0; i--) { while(stacksz > 0) { int curr = stack[stacksz-1]; if(y[curr] > y[i]) break; if(y[curr] == y[i]) { if(x[i] > x[curr]) stop(); stacksz--; continue; } Fraction xcand = null; if(x[curr] == x[i]) { xcand = new Fraction(x[i], 1); } else { Fraction slope = new Fraction(y[curr] - y[i], x[curr] - x[i]); xcand = new Fraction(x[i], 1).sub(new Fraction(y[i], 1).div(slope)); } if(xcand.compareTo(rhs[i]) < 0) rhs[i] = xcand; stacksz--; } stack[stacksz++] = i; } for(int i = 0; i < n; i++) if(lhs[i].compareTo(rhs[i]) > 0) stop(); double ret = 0; for(int i = 0; i < n; i++) { double lhsx = lhs[i].approx(); double rhsx = rhs[i].approx(); if(lhsx <= x[i] && x[i] <= rhsx) ret += y[i]; else { double mindist = Math.min(Math.abs(lhsx-x[i]), Math.abs(rhsx-x[i])); ret += Math.sqrt(y[i]*(long)y[i]+mindist*mindist); } } System.out.printf("%.39f\n", ret); } public static void stop() { System.out.println(-1); System.exit(0); } public static long gcd(long a, long b) { if(b==0) return a; return gcd(b, a%b); } static class Fraction { long n, d; public Fraction(long a, long b) { if(b == 0) throw new RuntimeException(); long g = gcd(a, b); a /= g; b /= g; if(b < 0) { a *= -1; b *= -1; } n = a; d = b; } public double approx() { return n / (double)d; } public Fraction add(Fraction f) { return new Fraction(n*f.d + d*f.n, d*f.d); } public Fraction sub(Fraction f) { return new Fraction(n*f.d - d*f.n, d*f.d); } public Fraction mul(Fraction f) { return new Fraction(n*f.n, d*f.d); } public Fraction div(Fraction f) { return new Fraction(n*f.d, d*f.n); } public int compareTo(Fraction f) { long ret = n * f.d - d * f.n; return (ret>0?1:0)-(ret<0?1:0); } public String toString() { return n + "/" + d; } } }