import std.stdio;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import core.stdc.stdio : scanf;
import std.conv;
import std.array;
import std.string;
import std.range;
import std.algorithm;

T read(T)() { return readln.chomp.to!T; }
T[] readarray(T)() { return readln.chomp.split(" ").map!(to!T).array; }

enum long INF = 1L<<40;
void solve() {
    int N;
    long K;
    readf("%d %d\n", &N, &K);
    auto A = readarray!long;
    sort(A);
    long sa = A.reduce!"a+b";
    long ans = INF;
    long s = 0;
    for (int y = 0; y < N; y++) {
        long x = max(0, ((sa - K - s + A[0] * y) + y) / (y + 1));
        ans = min(ans, x + y);
        s += A[N - 1 - y];
    }
    writeln(ans);
}

void main() {
    int T = read!int;
    foreach (t; 0 .. T) solve();
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!long;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto K = scan!long;
      auto A = scan!long(N);

      ulong[] acc = [0];
      foreach(a; A.sort!"a > b") acc ~= acc[$ - 1] + a;

      const spread = A.sum - K;
      long ans = long.max;
      long minn = A.minElement;
      foreach(i; 0..N) {
        bool isOK(long n) {
          // if (i == N - 1) [i, n, cast(ulong)n + (acc[i] - (minn - n)*i), spread].deb;
          return n + (acc[i] - (minn - n)*i) >= spread;
        }
        const x = max(0, binarySearch(&isOK, spread, -1));
        ans = min(ans, x + i);
      }

      return ans;
    }

    foreach(_; 0..QN) subSolve().writeln;
    // (10L^^9).repeat(2*10^^5).array.toAnswerString.writeln;
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

import std;

void main () {
    int tests;
    readf("%s\n", tests);

    foreach (test_idex; 0 .. tests) {
        int n;
        long k;
        readf("%s %s\n", n, k);

        int[] a = new int[n];

        k = -k;
        foreach (ref x; a)
            readf(" %s", x), k += x;
        readf("\n");
        a = sort(a).array;

        long rem = -a[0];
        int i;
        long turns;

        for (i = n - 1; i > 0 && k > 0;) {
            if (a[i] + rem >= n - i) {
                k -= a[i] + rem;
                -- i;
                ++ turns;
            } else {
                //a[i] + x >= n - i
                long x = n - i - a[i] - rem;
                long y = cast(long)ceil(cast(double)k / (n - i));

                if (x >= y) {
                    turns += y;
                    k = 0;
                    break;
                }
                k -= (n - i) * x;
                rem += x;
                turns += x;
            }
        }

        if (k <= 0) {
            writeln(turns);
            continue;
        }

        turns += cast(long)ceil(cast(double)k / n);
        writeln(turns);
    }

}
// ""

import std.algorithm, std.array, std.container, std.conv, std.math, std.numeric, std.random, std.range, std.stdio, std.string, std.typecons, core.bitop;

void main()
{
  foreach (casenum ; 1 .. readln.strip.to!int + 1) {
    long n, k;
    readf!" %d %d "(n, k);
    auto a = readln.splitter.map!(to!long).array.sort.array;
    long[] pfa = [0L];
    foreach (x ; a)
      pfa ~= pfa.back + x;
    long best = long.max;
    foreach (swapcnt ; 0 .. n) {
      long newsum = a[0] * swapcnt + pfa[cast(size_t)(n - swapcnt)];
      if (newsum <= k) {
        best = min(best, swapcnt);
      } else {
        best = min(best, swapcnt + (newsum - k + swapcnt) / (swapcnt + 1));
      }
    }
    writeln(best);
  }
}

import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint;

void read(S...)(ref S args) {
  auto input = readln.split;
  enforce(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

class RangeSum(T) {
  T[] acc;
  this(T[] data) {
    acc = data.dup;
    foreach (i; 1 .. data.length) {
      acc[i] += acc[i - 1];
    }
  }

  T query(int i, int j) {
    if (j < i) return 0;
    auto total = acc[j];
    if (i > 0) total -= acc[i - 1];
    return total;
  }
}

void main() {
  int T;
  read(T);
  while (T--) {
    long n, k;
    read(n, k);
    auto arr = list!long;
    sort(arr);

    auto r = new RangeSum!long(arr);
    auto total = r.query(0, cast(int)(n) - 1);
    if (total <= k) {
      writeln(0);
      continue;
    }

    long answer = total - k;

    foreach (i; 1 .. n) {
      auto mid = r.query(1, cast(int)(n - 1 - i));
      auto rem = k - mid;
      auto x = rem / (i + 1) - 5;
      while (mid + ((x + 1) * (i + 1)) <= k) x++;
      long d = max(0, arr[0] - x);

      answer = min(answer, d + i);
    }

    writeln(answer);
  }
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!long;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto K = scan!long;
      auto A = scan!long(N);

      long[] acc = [0];
      foreach(a; A.sort!"a > b") acc ~= acc[$ - 1] + a;

      const spread = A.sum - K;
      if (spread <= 0) return 0;

      long ans = long.max;
      long minn = A.minElement;
      foreach(i; 0..N) {
        bool isOK(long n) {
          // [i, n, n + (acc[i] - (minn - n)*i), spread].deb;
          return n + (acc[i] - (minn - n)*i) >= spread;
        }
        const x = binarySearch(&isOK, spread, -1);
        ans = min(ans, x + i);
        // [ans].deb;
      }

      return ans;
    }

    foreach(_; 0..QN) subSolve().writeln;
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!long;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto K = scan!long;
      auto A = scan!long(N);

      long[] acc = [0];
      foreach(a; A.sort!"a > b") acc ~= acc[$ - 1] + a;

      const spread = A.sum - K;
      if (spread <= 0) return 0;

      long ans = long.max;
      long minn = A.minElement;
      foreach(i; 0..N) {
        bool isOK(long n) {
          // [i, n, n + (acc[i] - (minn - n)*i), spread].deb;
          return n + (acc[i] - (minn - n)*i) >= spread;
        }
        const x = binarySearch(&isOK, spread, 0);
        ans = min(ans, x + i);
        // [ans].deb;
      }

      return ans;
    }

    foreach(_; 0..QN) subSolve().writeln;
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!long;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto K = scan!long;
      auto A = scan!long(N);

      long[] acc = [0];
      foreach(a; A.sort!"a > b") acc ~= acc[$ - 1] + a;

      const spread = A.sum - K;
      long ans = long.max;
      long minn = A.minElement;
      foreach(i; 0..N) {
        bool isOK(long n) {
          // [i, n, n + (acc[i] - (minn - n)*i), spread].deb;
          return n + (acc[i] - (minn - n)*i) >= spread;
        }
        const x = max(0, binarySearch(&isOK, spread, -1));
        ans = min(ans, x + i);
        // [ans].deb;
      }

      return ans;
    }

    foreach(_; 0..QN) subSolve().writeln;
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

void main() { runSolver(); }

void problem() {
  auto QN = scan!long;

  auto solve() {
    auto subSolve() {
      auto N = scan!int;
      auto K = scan!long;
      auto A = scan!long(N);

      auto summ = A.sum;
      if (summ <= K) return 0;

      long[] acc = [0];
      foreach(a; A.sort!"a > b") acc ~= acc[$ - 1] + a;

      const spread = summ - K;
      long ans = long.max;
      long minn = A.minElement;
      foreach(i; 0..N) {
        bool isOK(long n) {
          // [i, n, n + (acc[i] - (minn - n)*i), spread].deb;
          return n + (acc[i] - (minn - n)*i) >= spread;
        }
        const x = binarySearch(&isOK, 10L^^18, 0);
        ans = min(ans, x + i);
      }

      return ans;
    }

    foreach(_; 0..QN) subSolve().writeln;
  }

  outputForAtCoder(&solve);
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric, std.traits, std.functional, std.bigint, std.datetime.stopwatch, core.time, core.bitop;
T[][] combinations(T)(T[] s, in long m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(long n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");
Point invert(Point p) { return Point(p.y, p.x); }
long[] divisors(long n) { long[] ret; for (long i = 1; i * i <= n; i++) { if (n % i == 0) { ret ~= i; if (i * i != n) ret ~= n / i; } } return ret.sort.array; }
bool chmin(T)(ref T a, T b) { if (b < a) { a = b; return true; } else return false; }
bool chmax(T)(ref T a, T b) { if (b > a) { a = b; return true; } else return false; }
string charSort(alias S = "a < b")(string s) { return (cast(char[])((cast(byte[])s).sort!S.array)).to!string; }
ulong comb(ulong a, ulong b) { if (b == 0) {return 1;}else{return comb(a - 1, b - 1) * a / b;}}
T[] compress(T)(T[] arr, T origin = T.init) { T[T] indecies; arr.dup.sort.uniq.enumerate(origin).each!((i, t) => indecies[t] = i); return arr.map!(t => indecies[t]).array; }
string toAnswerString(R)(R r) { return r.map!"a.to!string".joiner(" ").array.to!string; }
struct ModInt(uint MD) if (MD < int.max) {ulong v;this(string v) {this(v.to!long);}this(int v) {this(long(v));}this(long v) {this.v = (v%MD+MD)%MD;}void opAssign(long t) {v = (t%MD+MD)%MD;}static auto normS(ulong x) {return (x<MD)?x:x-MD;}static auto make(ulong x) {ModInt m; m.v = x; return m;}auto opBinary(string op:"+")(ModInt r) const {return make(normS(v+r.v));}auto opBinary(string op:"-")(ModInt r) const {return make(normS(v+MD-r.v));}auto opBinary(string op:"*")(ModInt r) const {return make((ulong(v)*r.v%MD).to!ulong);}auto opBinary(string op:"^^", T)(T r) const {long x=v;long y=1;while(r){if(r%2==1)y=(y*x)%MD;x=x^^2%MD;r/=2;} return make(y);}auto opBinary(string op:"/")(ModInt r) const {return this*memoize!inv(r);}static ModInt inv(ModInt x) {return x^^(MD-2);}string toString() const {return v.to!string;}auto opOpAssign(string op)(ModInt r) {return mixin ("this=this"~op~"r");}}
alias MInt1 = ModInt!(10^^9 + 7);
alias MInt9 = ModInt!(998_244_353);
void outputForAtCoder(T)(T delegate() fn) {
  static if (is(T == float) || is(T == double) || is(T == real)) "%.16f".writefln(fn());
  else static if (is(T == void)) fn();
  else static if (is(T == string)) fn().writeln;
  else static if (isInputRange!T) {
    static if (!is(string == ElementType!T) && isInputRange!(ElementType!T)) foreach(r; fn()) r.toAnswerString.writeln;
    else foreach(r; fn()) r.writeln;
  }
  else fn().writeln;
}
void runSolver() {
  enum BORDER = "==================================";
  debug { BORDER.writeln; while(!stdin.eof) { "<<< Process time: %s >>>".writefln(benchmark!problem(1)); BORDER.writeln; } }
  else problem();
}
enum YESNO = [true: "Yes", false: "No"];

// -----------------------------------------------

K binarySearch(K)(bool delegate(K) cond, K l, K r) { return binarySearch((K k) => k, cond, l, r); }
T binarySearch(T, K)(K delegate(T) fn, bool delegate(K) cond, T l, T r) {
  auto ok = l;
  auto ng = r;
  const T TWO = 2;

  bool again() {
    static if (is(T == float) || is(T == double) || is(T == real)) {
      return !ng.approxEqual(ok, 1e-08, 1e-08);
    } else {
      return abs(ng - ok) > 1;
    }
  }

  while(again()) {
    const half = (ng + ok) / TWO;
    const halfValue = fn(half);

    if (cond(halfValue)) {
      ok = half;
    } else {
      ng = half;
    }
  }

  return ok;
}

import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint;

void read(S...)(ref S args) {
  auto input = readln.split;
  enforce(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

class RangeSum(T) {
  T[] acc;
  this(T[] data) {
    acc = data.dup;
    foreach (i; 1 .. data.length) {
      acc[i] += acc[i - 1];
    }
  }

  T query(int i, int j) {
    if (j < i) return 0;
    auto total = acc[j];
    if (i > 0) total -= acc[i - 1];
    return total;
  }
}

void main() {
  int T;
  read(T);
  while (T--) {
    long n, k;
    read(n, k);
    auto arr = list!long;
    sort(arr);

    auto r = new RangeSum!long(arr);

    bool good(int dec, int change) {
      long a = arr[0] - dec;
      long b = r.query(1, cast(int)(n) - 1 - change);
      long c = change * a;
      return a + b + c <= k;
    }

    long answer = long.max;

    foreach (i; 0 .. n) {
      int b = 200000000;
      int a = 0;

      if (good(0, i.to!int)) { answer = min(answer, i); }

      while (b > a + 1) {
        int mid = (b + a) / 2;
        if (good(mid, i.to!int)) b = mid;
        else a = mid;
      }

      answer = min(answer, i + a + 1);
    }

    writeln(answer);
  }
}

import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint;

void read(S...)(ref S args) {
  auto input = readln.split;
  enforce(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

class RangeSum(T) {
  T[] acc;
  this(T[] data) {
    acc = data.dup;
    foreach (i; 1 .. data.length) {
      acc[i] += acc[i - 1];
    }
  }

  T query(int i, int j) {
    if (j < i) return 0;
    auto total = acc[j];
    if (i > 0) total -= acc[i - 1];
    return total;
  }
}

void main() {
  int T;
  read(T);
  while (T--) {
    long n, k;
    read(n, k);
    auto arr = list!long;
    sort(arr);

    auto r = new RangeSum!long(arr);

    bool good(int dec, int change) {
      long a = arr[0] - dec;
      long b = r.query(1, cast(int)(n) - 1 - change);
      long c = change * a;
      return a + b + c <= k;
    }

    long answer = long.max;

    foreach (i; 0 .. n) {
      int b = 100000000;
      int a = 0;

      if (good(0, i.to!int)) { answer = min(answer, i); }

      while (b > a + 1) {
        int mid = (b + a) / 2;
        if (good(mid, i.to!int)) b = mid;
        else a = mid;
      }

      answer = min(answer, i + a + 1);
    }

    writeln(answer);
  }
}

import std.algorithm, std.range, std.stdio, std.numeric, std.array, std.exception,
       std.container, std.typecons, std.conv, std.random, std.bigint;

void read(S...)(ref S args) {
  auto input = readln.split;
  enforce(input.length == args.length);
  foreach (i, ref arg; args) {
    arg = input[i].to!(S[i]);
  }
}

auto list(T)() { return readln.split.map!(e => e.to!T).array; }

class RangeSum(T) {
  T[] acc;
  this(T[] data) {
    acc = data.dup;
    foreach (i; 1 .. data.length) {
      acc[i] += acc[i - 1];
    }
  }

  T query(int i, int j) {
    if (j < i) return 0;
    auto total = acc[j];
    if (i > 0) total -= acc[i - 1];
    return total;
  }
}

void main() {
  int T;
  read(T);
  while (T--) {
    long n, k;
    read(n, k);
    auto arr = list!long;
    sort(arr);

    auto r = new RangeSum!long(arr);

    bool good(int dec, int change) {
      long a = arr[0] - dec;
      long b = r.query(1, cast(int)(n) - 1 - change);
      long c = change * a;
      return a + b + c <= k;
    }

    long answer = long.max;

    foreach (i; 0 .. n) {
      int b = 300000;
      int a = 0;

      if (good(0, i.to!int)) { answer = min(answer, i); }

      while (b > a + 1) {
        int mid = (b + a) / 2;
        if (good(mid, i.to!int)) b = mid;
        else a = mid;
      }

      answer = min(answer, i + a + 1);
    }

    writeln(answer);
  }
}


import std.stdio, std.algorithm, std.conv, std.string, std.array, std.range, std.math;

long digits_diff(int x1, int x2)
{
  auto s1 = to!string(x1).split("").reverse;
  auto s2 = to!string(x2).split("").reverse;
  size_t minl = min(s1.length, s2.length);
  long result = abs(cast(long)s1.length - cast(long)s2.length);
  for (int i = 0; i < minl; i++)
    if (s1[i] != s2[i])
      result += 1;
  return result;
}

long solvex(int l, int r)
{
  long result = 0;
  while ((l < r) && (l % 10 != 0)) {
    result += digits_diff(l, l + 1);
    l += 1;
  }

  while (l < r && r % 10 != 0) {
    result += digits_diff(r, r - 1);
    r -= 1;
  }

  if (l == r)
    return result;

  if ((l % 10 == 0) && (r % 10 == 0)) {
    return result + solvex(l / 10, r / 10) + (r - l);
  }

  while (l < r) {
    result += digits_diff(l, l + 1);
    l++;
  }

  return result;
}

void main()
{
  int t;
  readf!" %d "(t);
  while (t--) {
    int l, r;
    readf!" %d %d "(l, r);
    writeln(solvex(l, r));
  }
}

// code by cutx64

module main;

import std.string, std.array, std.container, std.typecons;
import std.stdio, std.format, std.file;
import std.algorithm, std.conv, std.functional, std.range, core.bitop;
// import std.bigint, std.complex, std.bitmanip;
// import std.math, std.mathspecial, std.numeric;

void main() {

  int ask(int x, int d) {
    int pw10 = 10 ^^ d;
    int pre = x / pw10;
    int suf = x % pw10;
    return pre + (suf == pw10 - 1);
  }
  int tests;
  readf!"%s\n"(tests);
  foreach(per_test; 0 .. tests) {
    int l, r;
    readf!"%s %s\n"(l, r);
    int ans = r - l;
    foreach(i; 1 .. 10) {
      ans += (ask(r - 1, i) - ask(l - 1, i));
    }
    ans.writeln;
  }

} // main


import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	foreach (test; 0..readln.strip.to !(int))
	{
		int rows, cols;
		readf !(" %s %s") (rows, cols);
		readln;
		int [] [] board;
		foreach (row; 0..rows)
		{
			board ~= readln.splitter.map !(to !(int)).array;
		}
		auto moves = min (rows - board.map !(any).sum, cols -
		    cols.iota.map !(i => board.transversal (i)).map !(any).sum);
		writeln ((moves & 1) ? "Ashish" : "Vivek");
	}
}

import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto t = RD!int;
	auto ans = new long[](t);
	foreach (ti; 0..t)
	{
		auto n = RD!int;
		auto m = RD!int;
		auto a = new long[][](n);
		foreach (i; 0..n)
		{
			a[i] = RDA;
		}

		long x, y;
		foreach (i; 0..n)
		{
			bool ok = true;
			foreach (j; 0..m)
			{
				if (a[i][j] == 1)
				{
					ok = false;
					break;
				}
			}
			if (ok)
				++x;
		}
		foreach (i; 0..m)
		{
			bool ok = true;
			foreach (j; 0..n)
			{
				if (a[j][i] == 1)
				{
					ok = false;
					break;
				}
			}
			if (ok)
				++y;
		}
		ans[ti] = min(x, y) % 2;
	}

	foreach (e; ans)
		writeln(e ? "Ashish" : "Vivek");
	stdout.flush;
	debug readln;
}


import core.bitop;
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.exception;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

immutable real infinity = 1E100;
immutable real eps = 1E-14;

real solve (int n)
{
	real xlo, ylo, xhi, yhi;
	readf (" %s %s %s %s", &xlo, &ylo, &xhi, &yhi);
	auto x = new real [n];
	auto y = new real [n];
	auto vx = new real [n];
	auto vy = new real [n];
	foreach (i; 0..n)
	{
		readf (" %s %s %s %s", &x[i], &y[i], &vx[i], &vy[i]);
	}

	real tlo = 0;
	real thi = infinity;

	void processCoord (real lo, real hi, real c, real v)
	{
		if (v == 0)
		{
			if (lo < c && c < hi)
			{
				return;
			}
			tlo = +infinity;
			thi = -infinity;
			return;
		}
		real a = (lo - c) / v;
		real b = (hi - c) / v;
		debug {writeln (a, " ", b);}
		a = max (a, 0);
		b = max (b, 0);
		if (a > b)
		{
			swap (a, b);
		}
		tlo = max (tlo, a);
		thi = min (thi, b);
	}

	foreach (i; 0..n)
	{
		processCoord (xlo, xhi, x[i], vx[i]);
		processCoord (ylo, yhi, y[i], vy[i]);
	}
	debug {writeln (">", tlo, " ", thi);}

	if (thi - tlo > eps)
	{
		return tlo;
	}
	return -1;
}

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		writefln ("%.20g", solve (n));
	}
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//------------------------------------------program beginning--------------------------

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n;
loop:while(read(n))
	{
		lint x1,y1,x2,y2;
		read(x1,y1,x2,y2);
		long l=0,vl=1,r=int.max,vr=1;
		foreach(i;0..n)
		{
			long rx,ry,vx,vy;
			read(rx,ry,vx,vy);
			if(vx==0)
			{
				if(rx<=x1 || rx>=x2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vx<0)
				{
					r1=max(x1-rx,x2-rx);
					r2=min(x1-rx,x2-rx);
				}
				else
				{
					r2=max(x1-rx,x2-rx);
					r1=min(x1-rx,x2-rx);
				}
				if(vx*r2<=0)
				{
					r2=r1;
				}
				if((rx-x1)*(rx-x2)<0)r1=0;
				if(vx*r2<=0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vx=abs(vx);
				if(l*vx<r1*vl)
				{
					l=r1;
					vl=vx;
				}
				if(r*vx>r2*vr)
				{
					r=r2;
					vr=vx;
				}
			}
			if(vy==0)
			{
				if(ry<=y1 || ry>=y2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vy<0)
				{
					r1=max(y1-ry,y2-ry);
					r2=min(y1-ry,y2-ry);
				}
				else
				{
					r2=max(y1-ry,y2-ry);
					r1=min(y1-ry,y2-ry);
				}
				if(vy*r2<=0)
				{
					r2=r1;
				}
				if((ry-y1)*(ry-y2)<0)r1=0;
				if(vy*r2<=0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vy=abs(vy);
				if(l*vy<r1*vl)
				{
					l=r1;
					vl=vy;
				}
				if(r*vy>r2*vr)
				{
					r=r2;
					vr=vy;
				}
			}
		}
		if(l*vr>=r*vl)writeln("-1");
		else writefln("%.10f",(1.00000000*l)/vl);
	}

	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//------------------------------------------program beginning--------------------------

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n;
loop:while(read(n))
	{
		lint x1,y1,x2,y2;
		read(x1,y1,x2,y2);
		long l=0,vl=1,r=int.max,vr=1;
		foreach(i;0..n)
		{
			long rx,ry,vx,vy;
			read(rx,ry,vx,vy);
			if(vx==0)
			{
				if(rx<x1 || rx>x2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vx<0)
				{
					r1=max(x1-rx,x2-rx);
					r2=min(x1-rx,x2-rx);
				}
				else
				{
					r2=max(x1-rx,x2-rx);
					r1=min(x1-rx,x2-rx);
				}
				if(vx*r2<0)
				{
					r2=r1;
				}
				if((rx-x1)*(rx-x2)<=0)r1=0;
				if(vx*r1<0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vx=abs(vx);
				if(l*vx<r1*vl)
				{
					l=r1;
					vl=vx;
				}
				if(r*vx>r2*vr)
				{
					r=r2;
					vr=vx;
				}
			}
			if(vy==0)
			{
				if(ry<y1 || ry>y2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vy<0)
				{
					r1=max(y1-ry,y2-ry);
					r2=min(y1-ry,y2-ry);
				}
				else
				{
					r2=max(y1-ry,y2-ry);
					r1=min(y1-ry,y2-ry);
				}
				if(vy*r2<0)
				{
					r2=r1;
				}
				if((ry-y1)*(ry-y2)<=0)r1=0;
				if(vy*r1<0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vy=abs(vy);
				if(l*vy<r1*vl)
				{
					l=r1;
					vl=vy;
				}
				if(r*vy>r2*vr)
				{
					r=r2;
					vr=vy;
				}
			}
		}
		if(l*vr>r*vl)writeln("-1");
		else writefln("%.10f",(1.00000000*l)/vl);
	}

	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//------------------------------------------program beginning--------------------------

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n;
loop:while(read(n))
	{
		lint x1,y1,x2,y2;
		read(x1,y1,x2,y2);
		long l=0,vl=1,r=int.max,vr=1;
		foreach(i;0..n)
		{
			long rx,ry,vx,vy;
			long l0=-1,vl0=1,r0=int.max,vr0=1;
			read(rx,ry,vx,vy);
			if(vx==0)
			{
				if(rx<x1 || rx>x2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vx<0)
				{
					r1=max(x1-rx,x2-rx);
					r2=min(x1-rx,x2-rx);
				}
				else
				{
					r2=max(x1-rx,x2-rx);
					r1=min(x1-rx,x2-rx);
				}
				if(vx*r2<0)
				{
					r2=r1;
				}
				if((rx-x1)*(rx-x2)<=0)r1=0;
				if(vx*r1<0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vx=abs(vx);
				if(l0*vx<r1*vl0)
				{
					l0=r1;
					vl0=vx;
				}
				if(r0*vx<r2*vr0)
				{
					r0=r2;
					vr0=vx;
				}
			}
			if(vy==0)
			{
				if(ry<y1 || ry>y2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vy<0)
				{
					r1=max(y1-ry,y2-ry);
					r2=min(y1-ry,y2-ry);
				}
				else
				{
					r2=max(y1-ry,y2-ry);
					r1=min(y1-ry,y2-ry);
				}
				if(vy*r2<0)
				{
					r2=r1;
				}
				if((ry-y1)*(ry-y2)<=0)r1=0;
				if(vy*r1<0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vy=abs(vy);
				if(l0*vy<r1*vl0)
				{
					l0=r1;
					vl0=vy;
				}
				if(r0*vy<r2*vr0)
				{
					r0=r2;
					vr0=vy;
				}
			}
			if(l*vl0<l0*vl && l0!=-1)
			{
				l=l0;
				vl=vl0;
			}
			if(r*vr0>r0*vr && r0!=int.max)
			{
				r=r0;
				vr=vr0;
			}
		}
		if(l*vr>r*vl)writeln("-1");
		else writefln("%.10f",(1.00000000*l)/vl);
	}

	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//------------------------------------------program beginning--------------------------

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n;
loop:while(read(n))
	{
		lint x1,y1,x2,y2;
		read(x1,y1,x2,y2);
		long l=0,vl=1,r=int.max,vr=1;
		foreach(i;0..n)
		{
			long rx,ry,vx,vy;
			long l0=-1,vl0=1,r0=int.max,vr0=1;
			read(rx,ry,vx,vy);
			if(vx==0)
			{
				if(rx<x1 || rx>x2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vx<0)
				{
					r1=max(x1-rx,x2-rx);
					r2=min(x1-rx,x2-rx);
				}
				else
				{
					r2=max(x1-rx,x2-rx);
					r1=min(x1-rx,x2-rx);
				}
				if((rx-x1)*(rx-x2)<=0)r1=0;
				if(vx*r1<0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vx=abs(vx);
				if(l0*vx<r1*vl0)
				{
					l0=r1;
					vl0=vx;
				}
				if(r0*vx<r2*vr0)
				{
					r0=r2;
					vr0=vx;
				}
			}
			if(vy==0)
			{
				if(ry<y1 || ry>y2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vy<0)
				{
					r1=max(y1-ry,y2-ry);
					r2=min(y1-ry,y2-ry);
				}
				else
				{
					r2=max(y1-ry,y2-ry);
					r1=min(y1-ry,y2-ry);
				}
				if((ry-y1)*(ry-y2)<=0)r1=0;
				if(vy*r1<0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vy=abs(vy);
				if(l0*vy<r1*vl0)
				{
					l0=r1;
					vl0=vy;
				}
				if(r0*vy<r2*vr0)
				{
					r0=r2;
					vr0=vy;
				}
			}
			if(l*vl0<l0*vl && l0!=-1)
			{
				l=l0;
				vl=vl0;
			}
			if(r*vr0>r0*vr && r0!=int.max)
			{
				r=r0;
				vr=vr0;
			}
		}
		if(l*vr>r*vl)writeln("-1");
		else writefln("%.10f",(1.00000000*l)/vl);
	}

	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//------------------------------------------program beginning--------------------------

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n;
loop:while(read(n))
	{
		lint x1,y1,x2,y2;
		read(x1,y1,x2,y2);
		long l=0,vl=1,r=int.max,vr=1;
		foreach(i;0..n)
		{
			long rx,ry,vx,vy;
			read(rx,ry,vx,vy);
			if(vx==0)
			{
				if(rx<=x1 || rx>=x2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vx<0)
				{
					r1=max(x1-rx,x2-rx);
					r2=min(x1-rx,x2-rx);
				}
				else
				{
					r2=max(x1-rx,x2-rx);
					r1=min(x1-rx,x2-rx);
				}
				if(vx*r2<=0)
				{
					r2=r1;
				}
				if((rx-x1)*(rx-x2)<0)r1=0;
				if(vx*r2<=0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vx=abs(vx);
				if(l*vx<r1*vl)
				{
					l=r1;
					vl=vx;
				}
				if(r*vx>r2*vr)
				{
					r=r2;
					vr=vx;
				}
			}
			if(vy==0)
			{
				if(ry<=y1 || ry>=y2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vy<0)
				{
					r1=max(y1-ry,y2-ry);
					r2=min(y1-ry,y2-ry);
				}
				else
				{
					r2=max(y1-ry,y2-ry);
					r1=min(y1-ry,y2-ry);
				}
				if(vy*r2<=0)
				{
					r2=r1;
				}
				if((ry-y1)*(ry-y2)<0)r1=0;
				if(vy*r2<=0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vy=abs(vy);
				if(l*vy<r1*vl)
				{
					l=r1;
					vl=vy;
				}
				if(r*vy>r2*vr)
				{
					r=r2;
					vr=vy;
				}
			}
		}
		if(l*vr>r*vl)writeln("-1");
		else writefln("%.10f",(1.00000000*l)/vl);
	}

	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//------------------------------------------program beginning--------------------------

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n;
loop:while(read(n))
	{
		lint x1,y1,x2,y2;
		read(x1,y1,x2,y2);
		long l=0,vl=1,r=int.max,vr=1;
		foreach(i;0..n)
		{
			long rx,ry,vx,vy;
			long l0=-1,vl0=1,r0=int.max,vr0=1;
			read(rx,ry,vx,vy);
			if(vx==0)
			{
				if(rx<x1 || rx>x2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				lint x;
				if((rx-x1)*(rx-x2)<=0)x=0;
				else if(abs(x1-rx)<abs(x2-rx))x=x1-rx;
				else x=x2-rx;
				if(x*vx<0)
				{
					writeln("-1");
					return;
				}
				x=abs(x);
				if(x*vl0>l0*abs(vx))
				{
					l0=x;
					vl0=abs(vx);
				}
				if((x1-rx)*vx>(x2-rx)*vx)x=abs(x1-rx);
				else x=abs(x2-rx);
				if(x*vr0<r0*abs(vx))
				{
					vr0=abs(vx);
					r0=x;
				}
			}
			if(vy==0)
			{
				if(ry<y1 || ry>y2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				lint y;
				if((ry-y1)*(ry-y2)<=0)y=0;
				else if(abs(y1-ry)<abs(y2-ry))y=y1-ry;
				else y=y2-ry;
				if(y*vy<0)
				{
					writeln("-1");
					return;
				}
				y=abs(y);
				if(y*vl0>l0*abs(vy))
				{
					l0=y;
					vl0=abs(vy);
				}
				if((y1-ry)*vy>(y2-ry)*vy)y=abs(y1-ry);
				else y=abs(y2-ry);
				if(y*vr0<r0*abs(vy))
				{
					vr0=abs(vy);
					r0=y;
				}
			}
			if(l*vl0<l0*vl && l0!=-1)
			{
				l=l0;
				vl=vl0;
			}
			if(r*vr0>r0*vr && r0!=int.max)
			{
				r=r0;
				vr=vr0;
			}
		}
		if(l*vr>r*vl)writeln("-1");
		else writefln("%.10f",(1.00000000*l)/vl);
	}

	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//------------------------------------------program beginning--------------------------

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n;
loop:while(read(n))
	{
		lint x1,y1,x2,y2;
		read(x1,y1,x2,y2);
		long l=0,vl=1,r=int.max,vr=1;
		foreach(i;0..n)
		{
			long rx,ry,vx,vy;
			read(rx,ry,vx,vy);
			if(vx==0)
			{
				if(rx<x1 || rx>x2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vx<0)
				{
					r1=max(x1-rx,x2-rx);
					r2=min(x1-rx,x2-rx);
				}
				else
				{
					r2=max(x1-rx,x2-rx);
					r1=min(x1-rx,x2-rx);
				}
				if(vx*r2<=0)
				{
					r2=r1;
				}
				if((rx-x1)*(rx-x2)<0)r1=0;
				else if(vx*r1<=0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vx=abs(vx);
				if(l*vx<r1*vl)
				{
					l=r1;
					vl=vx;
				}
				if(r*vx>r2*vr)
				{
					r=r2;
					vr=vx;
				}
			}
			if(vy==0)
			{
				if(ry<y1 || ry>y2)
				{
					writeln("-1");
					return;
				}

			}
			else
			{
				long r1,r2;
				if(vy<0)
				{
					r1=max(y1-ry,y2-ry);
					r2=min(y1-ry,y2-ry);
				}
				else
				{
					r2=max(y1-ry,y2-ry);
					r1=min(y1-ry,y2-ry);
				}
				if(vy*r2<=0)
				{
					r2=r1;
				}
				if((ry-y1)*(ry-y2)<0)r1=0;
				else if(vy*r1<=0)
				{
					writeln(-1);
					return;
				}
				r1=abs(r1);
				r2=abs(r2);
				vy=abs(vy);
				if(l*vy<r1*vl)
				{
					l=r1;
					vl=vy;
				}
				if(r*vy>r2*vr)
				{
					r=r2;
					vr=vy;
				}
			}
		}
		if(l*vr>r*vl)writeln("-1");
		else writefln("%.10f",(1.00000000*l)/vl);
	}

	//debug system("pause");
}

import std.bigint,std.container,std.array,std.algorithm,std.conv,
	std.functional,std.math,std.numeric,std.string,std.range,std.complex,
	std.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,
	core.stdc.stdio : freopen;
import core.stdc.stdlib : system;
//import core.stdc.stdio;
alias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;
alias pair(X,Y)=Tuple!(X,"fi",Y,"se");alias long lint;immutable int mod=1000000007;
alias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;
alias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;
pure nothrow
{
	T lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}
	pair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,"fi",Y,"se")(x_,y_);}
	big gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}
	@property X sqr(X)(in X a_) {return a_*a_;}
	@property X cub(X)(in X a_) {return a_*a_*a_;}
	int sz(T)(T a) if(hasLength!T){return cast(int)a.length;}
	size_t lowb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		size_t l=0,r=a.length;
		while(r-l>1)
		{
			auto m=(l+r)>>1;
			if(!(a[m]<g))r=m;
			else l=m;
		}
		return (!(a[l]<g))?l:r;
	}
	size_t upb(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		if(pos==a.length)return pos;
		else return a[pos]==g?pos+1:pos;
	}
	size_t binf(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		auto pos=lowb(a,g);
		return (g==a[pos])?pos:a.length;
	}
	bool binary_search(T,X)(in T a,auto ref X g)
	 if(isRandomAccessRange!T && hasLength!T && is(typeof(g<a[0])==bool))
	{
		return binf(a,g)!=a.length;
	}
}
void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}
void putarr(X)(in X a,in size_t n=a.length,in size_t m=a.front.length)
{
	foreach(i;0..n)
	{
		foreach(j;0..m)write(a[i][j],' ');
		writeln;
	}
}
bool getarr(X)(X a,in size_t n)
{bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}
bool input(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	return s==ptrs.length;
}
bool read(T...)(auto ref T ptrs) if (ptrs.length > 0)
{
	size_t s=0;
	foreach(ref e;ptrs)
	{
		if(isSomeChar!(Unqual!(typeof(e))))s+=readf(" %c",&e);
		else s+=readf(" %s",&e);
	}
	readln;
	return s==ptrs.length;
}
nothrow auto inf(in char* name) {return freopen(name,"r",core.stdc.stdio.stdin);}
nothrow auto ouf(in char* name) {return freopen(name,"w",core.stdc.stdio.stdout);}
@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}
//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold schwartzSort multiSort partialSort heapify join filter
//------------------------------------------program beginning--------------------------

void main()
{
	version(ONLINE_JUDGE){}
	else
	{
		assert(freopen("input.txt","r",core.stdc.stdio.stdin));
		assert(freopen("output.txt","w",core.stdc.stdio.stdout));
	}
	int n;
loop:while(read(n))
	{
		lint x1,y1,x2,y2;
		read(x1,y1,x2,y2);
		long l=0,vl=1,r=int.max,vr=1;
		foreach(i;0..n)
		{
			long rx,ry,vx,vy;
			read(rx,ry,vx,vy);
			if(vx==0)
			{
				if(rx<x1 || rx>x2)
				{
					writeln(-1);
					return;
				}

			}
			else
			{
				lint x;
				if((rx-x1)*(rx-x2)<=0)x=0;
				else if(abs(x1-rx)<abs(x2-rx))x=x1-rx;
				else x=x2-rx;
				if(x*vx<0)
				{
					writeln(-1);
					return;
				}
				if(x*vl>l*vx)
				{
					l=x;
					vl=vx;
				}
				if((x1-rx)*vx>(x2-rx)*vx)x=x1-rx;
				else x=x2-rx;
				if(x*vr<r*vx)
				{
					vr=vx;
					r=x;
				}
			}
			if(vy==0)
			{
				if(ry<y1 || ry>y2)
				{
					writeln(-1);
					return;
				}

			}
			else
			{
				lint y;
				if((ry-y1)*(ry-y2)<=0)y=0;
				else if(abs(y1-ry)<abs(y2-ry))y=y1-ry;
				else y=y2-ry;
				if(y*vy<0)
				{
					writeln(-1);
					return;
				}
				if(y*vl>l*vy)
				{
					l=y;
					vl=vy;
				}
				if((y1-ry)*vy>(y2-ry)*vy)y=y1-ry;
				else y=y2-ry;
				if(y*vr<r*vy)
				{
					vr=vy;
					r=y;
				}
			}
		}
		if(l*vr>r*vl)writeln(-1);
		else writeln((1.00000000*l)/vl);
	}

	//debug system("pause");
}


module _;
void main() {
	import std.stdio, std.algorithm;
	int n;
	readf("%s ", &n);
	long[] ps;
	long[] ns;
	foreach(i; 0..n) {
		long x;
		readf("%s ", &x);
		if (x < 0) {
			ns ~= -x;
		} else {
			ps ~= x;
		}
	}

	auto sns = ns.sort;
	auto sps = ps.sort;

	long ans = 0;
	// both > 0
	foreach(i; 0..sps.length) {
		auto c = sps.lowerBound(2UL*sps[i]+1UL);
		debug writeln(c, c.length - i - 1);
		ans += cast(long)(c.length - i - 1);
	}

	// both < 0
	foreach(i; 0..sns.length) {
		auto c = sns.lowerBound(2UL*sns[i]+1UL);
		debug writeln(c.length - i - 1);
		ans += cast(long)(c.length - i - 1);
	}

	// x > 0, y < 0, |x| < |y|
	// |x-y| = |y|+|x|, |x+y| = |y|-|x|
	// |y|-|x| <= |x|, |x| < |y| <= 2*|x|
	foreach(i; 0..sps.length) {
		auto c = sns.lowerBound(2UL*sps[i]+1UL).upperBound(sps[i]);
		debug writeln(c.length);
		ans += cast(long)c.length;
	}

	// x < 0, y > 0, |x| < |y|
	foreach(i; 0..sns.length) {
		auto c = sps.lowerBound(2UL*sns[i]+1UL).upperBound(sns[i]);
		debug writeln(c.length);
		ans += cast(long)c.length;
	}

	// |x| == |y|
	// |x|-|y| = 0, |x|+|y| = 2|x|
	foreach(i; 0..sps.length) {
		if (sns.contains(sps[i])) {
			ans++;
		}
	}
	writeln(ans);
}

import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;

void main ()
{
	int n;
	while (readf (" %s", &n) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).map !(abs).array;
		sort (a);

		long res = 0;
		int j = 0;
		foreach (i; 0..n)
		{
			while (a[j] * 2 < a[i])
			{
				j += 1;
			}
			res += i - j;
		}

		writeln (res);
	}
}

//prewritten code: https://github.com/antma/algo
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.traits;

class InputReader {
  private:
  ubyte[] p;
  ubyte[] buffer;
  size_t cur;
  public:
  this () {
    buffer = uninitializedArray!(ubyte[])(16<<20);
    p = stdin.rawRead (buffer);
  }
  final ubyte skipByte (ubyte lo) {
    while (true) {
      auto a = p[cur .. $];
      auto r = a.find! (c => c >= lo);
      if (!r.empty) {
        cur += a.length - r.length;
        return p[cur++];
      }
      p = stdin.rawRead (buffer);
      cur = 0;
      if (p.empty) return 0;
    }
  }
  final ubyte nextByte () {
    if (cur < p.length) {
       return p[cur++];
    }
    p = stdin.rawRead (buffer);
    if (p.empty) return 0;
    cur = 1;
    return p[0];
  }

  template next(T) if (isSigned!T) {
    final T next ()  {
      T res;
      ubyte b = skipByte (45);
      if (b == 45) {
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 - (b - 48);
        }
      } else {
        res = b - 48;
        while (true) {
          b = nextByte ();
          if (b < 48 || b >= 58) {
            return res;
          }
          res = res * 10 + (b - 48);
        }
      }
    }
  }
  template next(T) if (isUnsigned!T) {
    final T next () {
      T res = skipByte (48) - 48;
      while (true) {
        ubyte b = nextByte ();
        if (b < 48 || b >= 58) {
          break;
        }
        res = res * 10 + (b - 48);
      }
      return res;
    }
  }
  final T[] nextA(T) (int n) {
    auto a = uninitializedArray!(T[]) (n);
    foreach (i; 0 .. n) {
      a[i] = next!T;
    }
    return a;
  }
}

void main() {
  auto r = new InputReader;
  immutable int n = r.next!int;
  auto a = r.nextA!int (n);
  auto b = a.map!"abs(a)".array;
  sort (b);
  int i, j;
  ulong res;
  for (i = 0; i < n; ++i) {
    int x = b[i];
    while (j < n && b[j] - x <= x) ++j;
    debug stderr.writefln ("i = %d, j = %d", i, j);
    res += max (0, j - i - 1);
  }
  writeln (res);
}

module _;
void main() {
	import std.stdio, std.algorithm;
	int n;
	readf("%s ", &n);
	int[] ps;
	int[] ns;
	foreach(i; 0..n) {
		int x;
		readf("%s ", &x);
		if (x < 0) {
			ns ~= -x;
		} else {
			ps ~= x;
		}
	}

	auto sns = ns.sort;
	auto sps = ps.sort;

	int ans = 0;
	// both > 0
	foreach(i; 0..sps.length) {
		auto c = sps.lowerBound(2*sps[i]+1);
		debug writeln(c, c.length - i - 1);
		ans += c.length - i - 1;
	}

	// both < 0
	foreach(i; 0..sns.length) {
		auto c = sns.lowerBound(2*sns[i]+1);
		debug writeln(c.length - i - 1);
		ans += c.length - i - 1;
	}

	// x > 0, y < 0, |x| < |y|
	// |x-y| = |y|+|x|, |x+y| = |y|-|x|
	// |y|-|x| <= |x|, |x| < |y| <= 2*|x|
	foreach(i; 0..sps.length) {
		auto c = sns.lowerBound(2*sps[i]+1).upperBound(sps[i]);
		debug writeln(c.length);
		ans += c.length;
	}

	// x < 0, y > 0, |x| < |y|
	foreach(i; 0..sns.length) {
		auto c = sps.lowerBound(2*sns[i]+1).upperBound(sns[i]);
		debug writeln(c.length);
		ans += c.length;
	}
	writeln(ans);
}

module _;
void main() {
	import std.stdio, std.algorithm;
	int n;
	readf("%s ", &n);
	long[] ps;
	long[] ns;
	foreach(i; 0..n) {
		long x;
		readf("%s ", &x);
		if (x < 0) {
			ns ~= -x;
		} else {
			ps ~= x;
		}
	}

	auto sns = ns.sort;
	auto sps = ps.sort;

	long ans = 0;
	// both > 0
	foreach(i; 0..sps.length) {
		auto c = sps.lowerBound(2UL*sps[i]+1UL);
		debug writeln(c, c.length - i - 1);
		ans += cast(long)(c.length - i - 1);
	}

	// both < 0
	foreach(i; 0..sns.length) {
		auto c = sns.lowerBound(2UL*sns[i]+1UL);
		debug writeln(c.length - i - 1);
		ans += cast(long)(c.length - i - 1);
	}

	// x > 0, y < 0, |x| < |y|
	// |x-y| = |y|+|x|, |x+y| = |y|-|x|
	// |y|-|x| <= |x|, |x| < |y| <= 2*|x|
	foreach(i; 0..sps.length) {
		auto c = sns.lowerBound(2UL*sps[i]+1UL).upperBound(sps[i]);
		debug writeln(c.length);
		ans += cast(long)c.length;
	}

	// x < 0, y > 0, |x| < |y|
	foreach(i; 0..sns.length) {
		auto c = sps.lowerBound(2UL*sns[i]+1UL).upperBound(sns[i]);
		debug writeln(c.length);
		ans += cast(long)c.length;
	}
	writeln(ans);
}

module _;
void main() {
	import std.stdio, std.algorithm;
	int n;
	readf("%s ", &n);
	long[] ps;
	long[] ns;
	foreach(i; 0..n) {
		long x;
		readf("%s ", &x);
		if (x < 0) {
			ns ~= -x;
		} else {
			ps ~= x;
		}
	}

	auto sns = ns.sort;
	auto sps = ps.sort;

	long ans = 0;
	// both > 0
	foreach(i; 0..sps.length) {
		auto c = sps.lowerBound(2UL*sps[i]+1UL);
		debug writeln(c, c.length - i - 1);
		ans += cast(long)(c.length - i - 1);
	}

	// both < 0
	foreach(i; 0..sns.length) {
		auto c = sns.lowerBound(2UL*sns[i]+1UL);
		debug writeln(c.length - i - 1);
		ans += cast(long)(c.length - i - 1);
	}

	// x > 0, y < 0, |x| <= |y|
	// |x-y| = |y|+|x|, |x+y| = |y|-|x|
	// |y|-|x| <= |x|, |x| <= |y| <= 2*|x|
	foreach(i; 0..sps.length) {
		auto c = sns.lowerBound(2UL*sps[i]+1UL).upperBound(sps[i]-1);
		debug writeln(c.length);
		ans += cast(long)c.length;
	}

	// x < 0, y > 0, |x| <= |y|
	foreach(i; 0..sns.length) {
		auto c = sps.lowerBound(2UL*sns[i]+1UL).upperBound(sns[i]-1);
		debug writeln(c.length);
		ans += cast(long)c.length;
	}
	writeln(ans);
}


import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

immutable int NA = -1;

alias Tuple !(int, "xb", int, "yb", int, "xe", int, "ye") segment;

bool is_horizontal (ref segment a)
{
	return a.yb == a.ye;
}

alias Tuple !(int, "x1", int, "x2") pair;

bool less (ref pair p, ref pair q)
{
	return p.x1 < q.x1;
}

int get_len (pair [] b)
{
	int len = 0;
	int cur = 0;
	foreach (now; b)
	{
		if (cur < now.x1)
		{
			len += now.x1 - cur;
		}
		cur = max (cur, now.x2);
	}
	debug {writefln ("get_len = %s", len);}
	return len;
}

int process (ref pair [] [int] a, int n, int m)
{
	int res;
	int num = m - 1;
	foreach (i, ref b; a)
	{
		b ~= pair (n, n);
		sort !(less) (b);
		int len = get_len (b);
		debug {writefln ("%s: %s", i, len);}
		res ^= len;
		num--;
	}
	if (num > 0)
	{
		foreach (i; 1..m)
		{
			if (i !in a)
			{
				a[i] = new pair [0];
				a[i] ~= pair (n, n);
				break;
			}
		}
	}
	if (num & 1)
	{
		res ^= n;
	}
	return res;
}

int move (pair [] b, int res)
{
	int len = get_len (b);
	int todo = res ^ len;
	debug {writefln ("%s %s %s %s", b, res, len, todo);}
	if (todo > len)
	{
		return NA;
	}
	int cur = 0;
	foreach (now; b)
	{
		if (cur < now.x1)
		{
			int next = todo - (now.x1 - cur);
			if (next <= 0)
			{
				debug {writefln ("now.x1 = %s, next = %s",
				       now.x1, next);}
				debug {writefln ("%s %s %s", cur, todo,
				                 cur + todo);}
				return cur + todo;
			}
			todo = next;
		}
		cur = max (cur, now.x2);
	}
	assert (false);
}

pair moves (pair [] [int] a, int n, int m, int res)
{
	foreach (c, b; a)
	{
		int x = move (b, res);
		if (x != NA)
		{
			return pair (x, c);
		}
	}
	return pair (NA, NA);
}

void main ()
{
	int n, m, k;
	while (readf (" %s %s %s", &n, &m, &k) > 0)
	{
		pair [] [int] h;
		pair [] [int] v;
		foreach (i; 0..k)
		{
			segment a;
			readf (" %s %s %s %s", &a.xb, &a.yb, &a.xe, &a.ye);
			if (a.xb > a.xe)
			{
				swap (a.xb, a.xe);
			}
			if (a.yb > a.ye)
			{
				swap (a.yb, a.ye);
			}
			if (is_horizontal (a))
			{
				h[a.yb] ~= pair (a.xb, a.xe);
			}
			else
			{
				v[a.xb] ~= pair (a.yb, a.ye);
			}
		}
		int s = process (h, n, m);
		int t = process (v, m, n);
		int res = s ^ t;
		if (res)
		{
			writefln ("FIRST");
			auto p = moves (h, n, m, res);
			if (p[0] != NA)
			{
				writefln ("%s %s %s %s", p[0], p[1], n, p[1]);
				continue;
			}
			auto q = moves (v, m, n, res);
			if (q[0] != NA)
			{
				writefln ("%s %s %s %s", q[1], q[0], q[1], m);
				continue;
			}
			assert (false);
		}
		else
		{
			writefln ("SECOND");
		}
	}
}

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

immutable int NA = -1;

alias Tuple !(int, "xb", int, "yb", int, "xe", int, "ye") segment;

bool is_horizontal (ref segment a)
{
	return a.yb == a.ye;
}

alias Tuple !(int, "x1", int, "x2") pair;

bool less (ref pair p, ref pair q)
{
	return p.x1 < q.x1;
}

int get_len (pair [] b)
{
	int len = 0;
	int cur = 0;
	foreach (now; b)
	{
		if (cur < now.x1)
		{
			len += now.x1 - cur;
		}
		cur = max (cur, now.x2);
	}
	debug {writefln ("get_len = %s", len);}
	return len;
}

int process (ref pair [] [int] a, int n, int m)
{
	int res;
	int num = m - 1;
	foreach (i, ref b; a)
	{
		b ~= pair (n, n);
		sort !(less) (b);
		int len = get_len (b);
		debug {writefln ("%s: %s", i, len);}
		res ^= len;
		num--;
	}
	if (num > 0)
	{
		foreach (i; 1..m)
		{
			if (i !in a)
			{
				a[i] = new pair [0];
				a[i] ~= pair (n, n);
				break;
			}
		}
	}
	if (num & 1)
	{
		res ^= n;
	}
	return res;
}

int move (pair [] b, int res)
{
	int len = get_len (b);
	int todo = res ^ len;
	debug {writefln ("%s %s %s %s", b, res, len, todo);}
	if (todo > len)
	{
		return NA;
	}
	int cur = 0;
	foreach (now; b)
	{
		if (cur < now.x1)
		{
			int next = todo - (now.x1 - cur);
			if (next <= 0)
			{
				debug {writefln ("now.x1 = %s, next = %s",
				       now.x1, next);}
				debug {writefln ("%s %s %s", cur, todo,
				                 cur + todo);}
				return cur + todo;
			}
			todo = next;
		}
		cur = max (cur, now.x2);
	}
	assert (false);
}

pair moves (pair [] [int] a, int n, int m, int res)
{
	foreach (c, b; a)
	{
		int x = move (b, res);
		if (x != NA)
		{
			return pair (x, c);
		}
	}
	return pair (NA, NA);
}

void main ()
{
	int n, m, k;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		pair [] [int] h;
		pair [] [int] v;
		foreach (i; 0..k)
		{
			segment a;
			scanf (" %d %d %d %d", &a.xb, &a.yb, &a.xe, &a.ye);
			if (a.xb > a.xe)
			{
				swap (a.xb, a.xe);
			}
			if (a.yb > a.ye)
			{
				swap (a.yb, a.ye);
			}
			if (is_horizontal (a))
			{
				h[a.yb] ~= pair (a.xb, a.xe);
			}
			else
			{
				v[a.xb] ~= pair (a.yb, a.ye);
			}
		}
		int s = process (h, n, m);
		int t = process (v, m, n);
		int res = s ^ t;
		if (res)
		{
			writefln ("FIRST");
			auto p = moves (h, n, m, res);
			if (p[0] != NA)
			{
				writefln ("%s %s %s %s", p[0], p[1], n, p[1]);
				continue;
			}
			auto q = moves (v, m, n, res);
			if (q[0] != NA)
			{
				writefln ("%s %s %s %s", q[1], q[0], q[1], m);
				continue;
			}
			assert (false);
		}
		else
		{
			writefln ("SECOND");
		}
	}
}

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

immutable int NA = -1;

alias Tuple !(int, "xb", int, "yb", int, "xe", int, "ye") segment;

bool is_horizontal (ref segment a)
{
	return a.yb == a.ye;
}

alias Tuple !(int, "x1", int, "x2") pair;

bool less (ref pair p, ref pair q)
{
	return p.x1 < q.x1;
}

int get_len (pair [] b)
{
	int len = 0;
	int cur = 0;
	foreach (now; b)
	{
		if (cur < now.x1)
		{
			len += now.x1 - cur;
		}
		cur = max (cur, now.x2);
	}
	debug {writefln ("get_len = %s", len);}
	return len;
}

int process (ref pair [] [int] a, int n, int m)
{
	int res;
	int num = m - 1;
	foreach (i, ref b; a)
	{
		b ~= pair (n, n);
		sort !(less) (b);
		int len = get_len (b);
		debug {writefln ("%s: %s", i, len);}
		res ^= len;
		num--;
	}
	if (num > 0)
	{
		foreach (i; 1..m)
		{
			if (i !in a)
			{
				a[i] = new pair [0];
				a[i] ~= pair (n, n);
				break;
			}
		}
	}
	if (num & 1)
	{
		res ^= n;
	}
	return res;
}

int move (pair [] b, int res)
{
	int len = get_len (b);
	int todo = res ^ len;
	debug {writefln ("%s %s %s %s", b, res, len, todo);}
	if (todo > len)
	{
		return NA;
	}
	int cur = 0;
	foreach (now; b)
	{
		if (cur < now.x1)
		{
			int next = todo - (now.x1 - cur);
			if (next <= 0)
			{
				debug {writefln ("now.x1 = %s, next = %s",
				       now.x1, next);}
				return cur - next;
			}
			todo = next;
		}
		cur = max (cur, now.x2);
	}
	assert (false);
}

pair moves (pair [] [int] a, int n, int m, int res)
{
	foreach (c, b; a)
	{
		int x = move (b, res);
		if (x != NA)
		{
			return pair (x, c);
		}
	}
	return pair (NA, NA);
}

void main ()
{
	int n, m, k;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		pair [] [int] h;
		pair [] [int] v;
		foreach (i; 0..k)
		{
			segment a;
			scanf (" %d %d %d %d", &a.xb, &a.yb, &a.xe, &a.ye);
			if (a.xb > a.xe)
			{
				swap (a.xb, a.xe);
			}
			if (a.yb > a.ye)
			{
				swap (a.yb, a.ye);
			}
			if (is_horizontal (a))
			{
				h[a.yb] ~= pair (a.xb, a.xe);
			}
			else
			{
				v[a.xb] ~= pair (a.yb, a.ye);
			}
		}
		int s = process (h, n, m);
		int t = process (v, m, n);
		int res = s ^ t;
		if (res)
		{
			writefln ("FIRST");
			auto p = moves (h, n, m, res);
			if (p[0] != NA)
			{
				writefln ("%s %s %s %s", 0, p[1], p[0], p[1]);
				continue;
			}
			auto q = moves (v, m, n, res);
			if (q[0] != NA)
			{
				writefln ("%s %s %s %s", q[1], 0, q[1], q[0]);
				continue;
			}
			assert (false);
		}
		else
		{
			writefln ("SECOND");
		}
	}
}

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

alias Tuple !(int, "xb", int, "yb", int, "xe", int, "ye") segment;

bool is_horizontal (ref segment a)
{
	return a.yb == a.ye;
}

alias Tuple !(int, "x1", int, "x2") seg2;

bool less (ref seg2 p, ref seg2 q)
{
	return p.x1 < q.x1;
}

int process (seg2 [] [int] a, int n, int m, out int x, out int y)
{
	int res;
	int num = m - 1;
	y = 0;
	foreach (i, b; a)
	{
		sort !(less) (b);
		int len = 0;
		int cur = 0;
		foreach (now; b)
		{
			if (cur < now.x1)
			{
				len += now.x1 - cur;
			}
			cur = max (cur, now.x2);
		}
		len += n - cur;
		len = n - len;
		if (y < len)
		{
			y = len;
			x = i;
		}
		debug {writefln ("%s: %s", i, len);}
		res ^= len;
		num--;
	}
	if (num > 0)
	{
		foreach (i; 1..m)
		{
			if (i !in a)
			{
				y = n;
				x = i;
				break;
			}
		}
	}
	if (num & 1)
	{
		res ^= n;
	}
	return res;
}

int move (seg2 [] [int] a, int n, int m, int x, int y, int res)
{
	int todo = res ^ y;
	debug {writefln ("%s %s %s", res, y, todo);}
//	assert (todo <= y);
	debug {writefln ("%s %s", a, x);}
	seg2 [] b;
	if (y < n)
	{
		b ~= a[x];
	}
	b ~= seg2 (n, n);
	sort !(less) (b);
	int cur = 0;
	foreach (now; b)
	{
		if (cur < now.x1)
		{
			int next = todo - (now.x1 - cur);
			if (next <= 0)
			{
				debug {writefln ("now.x1 = %s, next = %s",
				       now.x1, next);}
				return cur - next;
			}
			todo = next;
		}
		cur = max (cur, now.x2);
	}
	assert (false);
}

void main ()
{
	int n, m, k;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		seg2 [] [int] h;
		seg2 [] [int] v;
		foreach (i; 0..k)
		{
			segment a;
			scanf (" %d %d %d %d", &a.xb, &a.yb, &a.xe, &a.ye);
			if (a.xb > a.xe)
			{
				swap (a.xb, a.xe);
			}
			if (a.yb > a.ye)
			{
				swap (a.yb, a.ye);
			}
			if (is_horizontal (a))
			{
				h[a.yb] ~= seg2 (a.xb, a.xe);
			}
			else
			{
				v[a.xb] ~= seg2 (a.yb, a.ye);
			}
		}
		int si, sp;
		int s = process (h, n, m, si, sp);
		debug {writefln ("%s %s", si, sp);}
		int ti, tp;
		int t = process (v, m, n, ti, tp);
		debug {writefln ("%s %s", ti, tp);}
		int res = s ^ t;
		if (res)
		{
			writefln ("FIRST");
			if ((res ^ sp) <= sp)
			{
				int pos = move (h, n, m, si, sp, res);
				writefln ("%s %s %s %s", 0, si, pos, si);
			}
			else
			{
				int pos = move (v, m, n, ti, tp, res);
				writefln ("%s %s %s %s", ti, 0, ti, pos);
			}
		}
		else
		{
			writefln ("SECOND");
		}
	}
}

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

alias Tuple !(int, "xb", int, "yb", int, "xe", int, "ye") segment;

bool is_horizontal (ref segment a)
{
	return a.yb == a.ye;
}

alias Tuple !(int, "x1", int, "x2") seg2;

bool less (ref seg2 p, ref seg2 q)
{
	return p.x1 < q.x1;
}

int process (seg2 [] [int] a, int n, int m, out int x, out int y)
{
	int res;
	int num = m - 1;
	y = 0;
	foreach (i, b; a)
	{
		sort !(less) (b);
		int len = 0;
		int cur = 0;
		foreach (now; b)
		{
			if (cur < now.x1)
			{
				len += now.x1 - cur;
			}
			cur = max (cur, now.x2);
		}
		len += n - cur;
		len = n - len;
		if (y < len)
		{
			y = len;
			x = i;
		}
		debug {writefln ("%s: %s", i, len);}
		res ^= len;
		num--;
	}
	if (num > 0)
	{
		foreach (i; 1..m)
		{
			if (i !in a)
			{
				y = n;
				x = i;
				break;
			}
		}
	}
	if (num & 1)
	{
		res ^= n;
	}
	return res;
}

int move (seg2 [] [int] a, int n, int m, int x, int y, int res)
{
	int todo = res ^ y;
	debug {writefln ("%s %s %s", res, y, todo);}
	assert (todo <= y);
	debug {writefln ("%s %s", a, x);}
	seg2 [] b;
	if (y < n)
	{
		b ~= a[x];
	}
	b ~= seg2 (n, n);
	sort !(less) (b);
	int cur = 0;
	foreach (now; b)
	{
		if (cur < now.x1)
		{
			int next = todo - (now.x1 - cur);
			if (next <= 0)
			{
				debug {writefln ("now.x1 = %s, next = %s",
				       now.x1, next);}
				return cur - next;
			}
			todo = next;
		}
		cur = max (cur, now.x2);
	}
	assert (false);
}

void main ()
{
	int n, m, k;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		seg2 [] [int] h;
		seg2 [] [int] v;
		foreach (i; 0..k)
		{
			segment a;
			scanf (" %d %d %d %d", &a.xb, &a.yb, &a.xe, &a.ye);
			if (a.xb > a.xe)
			{
				swap (a.xb, a.xe);
			}
			if (a.yb > a.ye)
			{
				swap (a.yb, a.ye);
			}
			if (is_horizontal (a))
			{
				h[a.yb] ~= seg2 (a.xb, a.xe);
			}
			else
			{
				v[a.xb] ~= seg2 (a.yb, a.ye);
			}
		}
		int si, sp;
		int s = process (h, n, m, si, sp);
		debug {writefln ("%s %s", si, sp);}
		int ti, tp;
		int t = process (v, m, n, ti, tp);
		debug {writefln ("%s %s", ti, tp);}
		int res = s ^ t;
		if (res)
		{
			writefln ("FIRST");
			if (sp >= tp)
			{
				int pos = move (h, n, m, si, sp, res);
				writefln ("%s %s %s %s", 0, si, pos, si);
			}
			else
			{
				int pos = move (v, m, n, ti, tp, res);
				writefln ("%s %s %s %s", ti, 0, ti, pos);
			}
		}
		else
		{
			writefln ("SECOND");
		}
	}
}

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

alias Tuple !(int, "xb", int, "yb", int, "xe", int, "ye") segment;

bool is_horizontal (ref segment a)
{
	return a.yb == a.ye;
}

alias Tuple !(int, "x1", int, "x2") seg2;

bool less (ref seg2 p, ref seg2 q)
{
	return p.x1 < q.x1;
}

int process (seg2 [] [int] a, int n, int m, out int x, out int y)
{
	int res;
	int num = m - 1;
	y = 0;
	foreach (i, b; a)
	{
		sort !(less) (b);
		int len = 0;
		int cur = 0;
		foreach (now; b)
		{
			if (cur < now.x1)
			{
				len += now.x1 - cur;
			}
			cur = max (cur, now.x2);
		}
		len += n - cur;
		len = n - len;
		if (y < len)
		{
			y = len;
			x = i;
		}
		debug {writefln ("%s: %s", i, len);}
		res ^= len;
		num--;
	}
	if (num > 0)
	{
		foreach (i; 1..m)
		{
			if (i !in a)
			{
				y = n;
				x = i;
				break;
			}
		}
	}
	if (num & 1)
	{
		res ^= n;
	}
	return res;
}

int move (seg2 [] [int] a, int n, int m, int x, int y, int res)
{
	int todo = res ^ y;
	debug {writefln ("%s %s %s", res, y, todo);}
//	assert (todo <= y);
	debug {writefln ("%s %s", a, x);}
	seg2 [] b;
	if (y < n)
	{
		b ~= a[x];
	}
	b ~= seg2 (n, n);
	sort !(less) (b);
	int cur = 0;
	foreach (now; b)
	{
		if (cur < now.x1)
		{
			int next = todo - (now.x1 - cur);
			if (next <= 0)
			{
				debug {writefln ("now.x1 = %s, next = %s",
				       now.x1, next);}
				return cur - next;
			}
			todo = next;
		}
		cur = max (cur, now.x2);
	}
	assert (false);
}

void main ()
{
	int n, m, k;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		seg2 [] [int] h;
		seg2 [] [int] v;
		foreach (i; 0..k)
		{
			segment a;
			scanf (" %d %d %d %d", &a.xb, &a.yb, &a.xe, &a.ye);
			if (a.xb > a.xe)
			{
				swap (a.xb, a.xe);
			}
			if (a.yb > a.ye)
			{
				swap (a.yb, a.ye);
			}
			if (is_horizontal (a))
			{
				h[a.yb] ~= seg2 (a.xb, a.xe);
			}
			else
			{
				v[a.xb] ~= seg2 (a.yb, a.ye);
			}
		}
		int si, sp;
		int s = process (h, n, m, si, sp);
		debug {writefln ("%s %s", si, sp);}
		int ti, tp;
		int t = process (v, m, n, ti, tp);
		debug {writefln ("%s %s", ti, tp);}
		int res = s ^ t;
		if (res)
		{
			writefln ("FIRST");
			if (sp >= tp)
			{
				int pos = move (h, n, m, si, sp, res);
				writefln ("%s %s %s %s", 0, si, pos, si);
			}
			else
			{
				int pos = move (v, m, n, ti, tp, res);
				writefln ("%s %s %s %s", ti, 0, ti, pos);
			}
		}
		else
		{
			writefln ("SECOND");
		}
	}
}

import std.algorithm;
import std.container;
import std.exception;
import std.math;
import std.stdio;
import std.string;
import std.typecons;

alias Tuple !(int, "xb", int, "yb", int, "xe", int, "ye") segment;

bool is_horizontal (ref segment a)
{
	return a.yb == a.ye;
}

alias Tuple !(int, "x1", int, "x2") seg2;

bool less (ref seg2 p, ref seg2 q)
{
	return p.x1 < q.x1;
}

int process (seg2 [] [int] a, int n, int m, out int x, out int y)
{
	int res;
	int num = m - 1;
	y = 0;
	foreach (i, b; a)
	{
		sort !(less) (b);
		int len = 0;
		int cur = 0;
		foreach (now; b)
		{
			if (cur < now.x1)
			{
				len += now.x1 - cur;
			}
			cur = max (cur, now.x2);
		}
		len += n - cur;
		if (y < len)
		{
			y = len;
			x = i;
		}
		debug {writefln ("%s: %s", i, len);}
		res ^= len;
		num--;
	}
	if (num > 0)
	{
		foreach (i; 1..m)
		{
			if (i !in a)
			{
				y = n;
				x = i;
				break;
			}
		}
	}
	if (num & 1)
	{
		res ^= n;
	}
	return res;
}

int move (seg2 [] [int] a, int n, int m, int x, int y, int res)
{
	int todo = res ^ y;
//	assert (todo <= y);
	debug {writefln ("%s %s", a, x);}
	seg2 [] b;
	if (y < n)
	{
		b ~= a[x];
	}
	b ~= seg2 (n, n);
	sort !(less) (b);
	int cur = 0;
	foreach (now; b)
	{
		if (cur < now.x1)
		{
			int next = todo - (now.x1 - cur);
			if (next <= 0)
			{
				debug {writefln ("now.x1 = %s, next = %s",
				       now.x1, next);}
				return cur - next;
			}
			todo = next;
		}
		cur = max (cur, now.x2);
	}
	return n;
//	assert (false);
}

void main ()
{
	int n, m, k;
	while (scanf (" %d %d %d", &n, &m, &k) > 0)
	{
		seg2 [] [int] h;
		seg2 [] [int] v;
		foreach (i; 0..k)
		{
			segment a;
			scanf (" %d %d %d %d", &a.xb, &a.yb, &a.xe, &a.ye);
			if (a.xb > a.xe)
			{
				swap (a.xb, a.xe);
			}
			if (a.yb > a.ye)
			{
				swap (a.yb, a.ye);
			}
			if (is_horizontal (a))
			{
				h[a.yb] ~= seg2 (a.xb, a.xe);
			}
			else
			{
				v[a.xb] ~= seg2 (a.yb, a.ye);
			}
		}
		int si, sp;
		int s = process (h, n, m, si, sp);
		debug {writefln ("%s %s", si, sp);}
		int ti, tp;
		int t = process (v, m, n, ti, tp);
		debug {writefln ("%s %s", ti, tp);}
		if (s ^ t)
		{
			writefln ("FIRST");
			if (sp >= tp)
			{
				int pos = move (h, n, m, si, sp, s ^ t);
				writefln ("%s %s %s %s", 0, si, pos, si);
			}
			else
			{
				int pos = move (v, m, n, ti, tp, s ^ t);
				writefln ("%s %s %s %s", ti, 0, ti, pos);
			}
		}
		else
		{
			writefln ("SECOND");
		}
	}
}