Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them.The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located in points (x1, y1) and (x2, y2).Igor wants to catch all mice. Igor has analysed their behavior and discovered that each mouse is moving along a straight line with constant speed, the speed of the i-th mouse is equal to (vix, viy), that means that the x coordinate of the mouse increases by vix units per second, while the y coordinates increases by viy units. The mousetrap is open initially so that the mice are able to move freely on the desk. Igor can close the mousetrap at any moment catching all the mice that are strictly inside the mousetrap.Igor works a lot, so he is busy in the dream as well, and he asks you to write a program that by given mousetrap's coordinates, the initial coordinates of the mice and their speeds determines the earliest time moment in which he is able to catch all the mice. Please note that Igor can close the mousetrap only once.

The first line contains single integer n (1 ≤ n ≤ 100 000) — the number of computer mice on the desk. The second line contains four integers x1, y1, x2 and y2 (0 ≤ x1 ≤ x2 ≤ 100 000), (0 ≤ y1 ≤ y2 ≤ 100 000) — the coordinates of the opposite corners of the mousetrap. The next n lines contain the information about mice. The i-th of these lines contains four integers rix, riy, vix and viy, (0 ≤ rix, riy ≤ 100 000,  - 100 000 ≤ vix, viy ≤ 100 000), where (rix, riy) is the initial position of the mouse, and (vix, viy) is its speed.

In the only line print minimum possible non-negative number t such that if Igor closes the mousetrap at t seconds from the beginning, then all the mice are strictly inside the mousetrap. If there is no such t, print -1. Your answer is considered correct if its absolute or relative error doesn't exceed 10 - 6.  Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if .

NoteHere is a picture of the first samplePoints A, B, C, D - start mice positions, segments are their paths.Then, at first time when all mice will be in rectangle it will be looks like this:Here is a picture of the second samplePoints A, D, B will never enter rectangle.

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 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*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");
}


You are given $$$n$$$ rectangles, each of height $$$1$$$. Each rectangle's width is a power of $$$2$$$ (i. e. it can be represented as $$$2^x$$$ for some non-negative integer $$$x$$$). You are also given a two-dimensional box of width $$$W$$$. Note that $$$W$$$ may or may not be a power of $$$2$$$. Moreover, $$$W$$$ is at least as large as the width of the largest rectangle.You have to find the smallest height of this box, such that it is able to fit all the given rectangles. It is allowed to have some empty space left in this box after fitting all the rectangles.You cannot rotate the given rectangles to make them fit into the box. Moreover, any two distinct rectangles must not overlap, i. e., any two distinct rectangles must have zero intersection area.See notes for visual explanation of sample input.

The first line of input contains one integer $$$t$$$ ($$$1 \le t \le 5 \cdot 10^3$$$) — the number of test cases. Each test case consists of two lines. For each test case:  the first line contains two integers $$$n$$$ ($$$1 \le n \le 10^5$$$) and $$$W$$$ ($$$1 \le W \le 10^9$$$); the second line contains $$$n$$$ integers $$$w_1, w_2, \dots, w_n$$$ ($$$1 \le w_i \le 10^6$$$), where $$$w_i$$$ is the width of the $$$i$$$-th rectangle. Each $$$w_i$$$ is a power of $$$2$$$; additionally, $$$\max\limits_{i=1}^{n} w_i \le W$$$.  The sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

Output $$$t$$$ integers. The $$$i$$$-th integer should be equal to the answer to the $$$i$$$-th test case — the smallest height of the box.

NoteFor the first test case in the sample input, the following figure shows one way to fit the given five rectangles into the 2D box with minimum height:  In the figure above, the number inside each rectangle is its width. The width of the 2D box is $$$16$$$ (indicated with arrow below). The minimum height required for the 2D box in this case is $$$2$$$ (indicated on the left).In the second test case, you can have a minimum height of three by keeping two blocks (one each of widths eight and two) on each of the three levels.

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(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }
void modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(ref long x, long 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 W = RD;
		auto w = RDA;

		int len;
		auto tmp = W;
		while (tmp)
		{
			++len;
			tmp /= 2;
		}
		auto cnt = new long[](len);
		foreach (i; 0..n)
		{
			int c;
			while (w[i])
			{
				++c;
				w[i] /= 2;
			}
			++cnt[c-1];
		}
		debug writeln("cnt:", cnt);

		while (true)
		{
			auto rem = W;
			foreach_reverse (i; 0..cnt.length)
			{
				if (cnt[i] == 0) continue;
				auto bit = 1L << i;
				if (rem < bit) continue;
				auto c = min(rem / bit, cnt[i]);
				rem -= bit * c;
				debug writeln("rem:", rem, " c:", c);
				cnt[i] -= c;
			}
			if (rem == W) break;
			++ans[ti];
		}
	}

	foreach (e; ans)
		writeln(e);
	stdout.flush;
	debug readln;
}


The legend of the foundation of Vectorland talks of two integers $$$x$$$ and $$$y$$$. Centuries ago, the array king placed two markers at points $$$|x|$$$ and $$$|y|$$$ on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers at points $$$|x - y|$$$ and $$$|x + y|$$$ and conquered all the land in between (including the endpoints), which he declared to be Vectorland. He did so in such a way that the land of Arrayland was completely inside (including the endpoints) the land of Vectorland.Here $$$|z|$$$ denotes the absolute value of $$$z$$$.Now, Jose is stuck on a question of his history exam: "What are the values of $$$x$$$ and $$$y$$$?" Jose doesn't know the answer, but he believes he has narrowed the possible answers down to $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$. Now, he wants to know the number of unordered pairs formed by two different elements from these $$$n$$$ integers such that the legend could be true if $$$x$$$ and $$$y$$$ were equal to these two values. Note that it is possible that Jose is wrong, and that no pairs could possibly make the legend true.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$)  — the number of choices. The second line contains $$$n$$$ pairwise distinct integers $$$a_1, a_2, \dots, a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the choices Jose is considering.

Print a single integer number — the number of unordered pairs $$$\{x, y\}$$$ formed by different numbers from Jose's choices that could make the legend true.

NoteConsider the first sample. For the pair $$$\{2, 5\}$$$, the situation looks as follows, with the Arrayland markers at $$$|2| = 2$$$ and $$$|5| = 5$$$, while the Vectorland markers are located at $$$|2 - 5| = 3$$$ and $$$|2 + 5| = 7$$$:  The legend is not true in this case, because the interval $$$[2, 3]$$$ is not conquered by Vectorland. For the pair $$$\{5, -3\}$$$ the situation looks as follows, with Arrayland consisting of the interval $$$[3, 5]$$$ and Vectorland consisting of the interval $$$[2, 8]$$$:  As Vectorland completely contains Arrayland, the legend is true. It can also be shown that the legend is true for the pair $$$\{2, -3\}$$$, for a total of two pairs.In the second sample, the only pair is $$$\{3, 6\}$$$, and the situation looks as follows:  Note that even though Arrayland and Vectorland share $$$3$$$ as endpoint, we still consider Arrayland to be completely inside of Vectorland.

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);
	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);
}

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);
}


A function  is called Lipschitz continuous if there is a real constant K such that the inequality |f(x) - f(y)| ≤ K·|x - y| holds for all . We'll deal with a more... discrete version of this term.For an array , we define it's Lipschitz constant  as follows:  if n < 2,   if n ≥ 2,  over all 1 ≤ i < j ≤ n In other words,  is the smallest non-negative integer such that |h[i] - h[j]| ≤ L·|i - j| holds for all 1 ≤ i, j ≤ n.You are given an array  of size n and q queries of the form [l, r]. For each query, consider the subarray ; determine the sum of Lipschitz constants of all subarrays of .

The first line of the input contains two space-separated integers n and q (2 ≤ n ≤ 100 000 and 1 ≤ q ≤ 100) — the number of elements in array  and the number of queries respectively. The second line contains n space-separated integers  (). The following q lines describe queries. The i-th of those lines contains two space-separated integers li and ri (1 ≤ li < ri ≤ n).

Print the answers to all queries in the order in which they are given in the input. For the i-th query, print one line containing a single integer — the sum of Lipschitz constants of all subarrays of .

NoteIn the first query of the first sample, the Lipschitz constants of subarrays of  with length at least 2 are:       The answer to the query is their sum.

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;
import core.bitop;

void main ()
{
	immutable int LOG_N = 17;
	immutable int MED_N = 1 << LOG_N;
	immutable int MAX_N = MED_N << 1;

	alias Pair = Tuple !(int, q{val}, int, q{num});

	int n, q;
	while (readf (" %s %s", &n, &q) > 0)
	{
		readln ();
		auto a = readln.split.map !(to !(int)).array;
		Pair [MAX_N] t;
		t[] = Pair (-1, -1);
		foreach (i; 0..n - 1)
		{
			t[i + MED_N] = Pair (abs (a[i + 1] - a[i]), i);
		}
		foreach_reverse (i; 1..MED_N)
		{
			t[i] = max (t[i * 2 + 0], t[i * 2 + 1]);
		}

		auto lq = new int [q];
		auto rq = new int [q];
		auto v = new long [q];
		foreach (z; 0..q)
		{
			readf (" %s %s", &lq[z], &rq[z]);
			lq[z]--;
			rq[z]--;
		}

		void go (int l, int r)
		{
			if (r <= l)
			{
				return;
			}

			auto p = t[l + MED_N];
			for (int lo = l + MED_N, hi = r + MED_N;
			    lo < hi; lo >>= 1, hi >>= 1)
			{
				if (lo & 1)
				{
					p = max (p, t[lo]);
					lo++;
				}
				if (hi & 1)
				{
					hi--;
					p = max (p, t[hi]);
				}
			}

			int m = p.num;
			foreach (z; 0..q)
			{
				if (lq[z] <= m && m < rq[z])
				{
					v[z] += cast (long) (p.val) *
					    (m - max (lq[z], l) + 1) *
					    (min (rq[z], r) - m);
				}
			}
			go (l, m);
			go (m + 1, r);
		}

		go (0, n - 1);
		foreach (z; 0..q)
		{
			writeln (v[z]);
		}
	}
}


Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid line (not necessarily from border to border). The part of the paper, that touches the knife at least once, is considered cut. There is one limit not to turn the game into an infinite cycle: each move has to cut the paper, that is the knife has to touch the part of the paper that is not cut before.Obviously, the game ends when the entire sheet is cut into 1 × 1 blocks. During the game, the pieces of the sheet are not allowed to move. It is also prohibited to cut along the border. The coordinates of the ends of each cut must be integers.You are given an n × m piece of paper, somebody has already made k cuts there. Your task is to determine who will win if the players start to play on this sheet. You can consider that both players play optimally well. If the first player wins, you also need to find the winning first move.

The first line contains three integers n, m, k (1 ≤ n, m ≤ 109, 0 ≤ k ≤ 105) — the sizes of the piece of paper and the number of cuts. Then follow k lines, each containing 4 integers xbi, ybi, xei, yei (0 ≤ xbi, xei ≤ n, 0 ≤ ybi, yei ≤ m) — the coordinates of the ends of the existing cuts.  It is guaranteed that each cut has a non-zero length, is either vertical or horizontal and doesn't go along the sheet border. The cuts may intersect, overlap and even be the same. That is, it is not guaranteed that the cuts were obtained during any correct game.

If the second player wins, print "SECOND". Otherwise, in the first line print "FIRST", and in the second line print any winning move of the first player (the coordinates of the cut ends, follow input format to print them).

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);}
				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);}
				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");
		}
	}
}


Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.He has a special interest to create difficult problems for others to solve. This time, with many $$$1 \times 1 \times 1$$$ toy bricks, he builds up a 3-dimensional object. We can describe this object with a $$$n \times m$$$ matrix, such that in each cell $$$(i,j)$$$, there are $$$h_{i,j}$$$ bricks standing on the top of each other.However, Serval doesn't give you any $$$h_{i,j}$$$, and just give you the front view, left view, and the top view of this object, and he is now asking you to restore the object. Note that in the front view, there are $$$m$$$ columns, and in the $$$i$$$-th of them, the height is the maximum of $$$h_{1,i},h_{2,i},\dots,h_{n,i}$$$. It is similar for the left view, where there are $$$n$$$ columns. And in the top view, there is an $$$n \times m$$$ matrix $$$t_{i,j}$$$, where $$$t_{i,j}$$$ is $$$0$$$ or $$$1$$$. If $$$t_{i,j}$$$ equals $$$1$$$, that means $$$h_{i,j}>0$$$, otherwise, $$$h_{i,j}=0$$$.However, Serval is very lonely because others are bored about his unsolvable problems before, and refused to solve this one, although this time he promises there will be at least one object satisfying all the views. As his best friend, can you have a try?

The first line contains three positive space-separated integers $$$n, m, h$$$ ($$$1\leq n, m, h \leq 100$$$) — the length, width and height. The second line contains $$$m$$$ non-negative space-separated integers $$$a_1,a_2,\dots,a_m$$$, where $$$a_i$$$ is the height in the $$$i$$$-th column from left to right of the front view ($$$0\leq a_i \leq h$$$). The third line contains $$$n$$$ non-negative space-separated integers $$$b_1,b_2,\dots,b_n$$$ ($$$0\leq b_j \leq h$$$), where $$$b_j$$$ is the height in the $$$j$$$-th column from left to right of the left view. Each of the following $$$n$$$ lines contains $$$m$$$ numbers, each is $$$0$$$ or $$$1$$$, representing the top view, where $$$j$$$-th number of $$$i$$$-th row is $$$1$$$ if $$$h_{i, j}>0$$$, and $$$0$$$ otherwise. It is guaranteed that there is at least one structure satisfying the input.

Output $$$n$$$ lines, each of them contains $$$m$$$ integers, the $$$j$$$-th number in the $$$i$$$-th line should be equal to the height in the corresponding position of the top view. If there are several objects satisfying the views, output any one of them.

Note  The graph above illustrates the object in the first example.    The first graph illustrates the object in the example output for the second example, and the second graph shows the three-view drawing of it.

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto H = s[2];
    auto A = readln.split.map!(to!int).array;
    auto B = readln.split.map!(to!int).array;
    auto C = N.iota.map!(_ => readln.split.map!(to!int).array).array;

    auto ans = new int[][](N, M);

    foreach (i; 0..N) {
        foreach (j; 0..M) {
            if (C[i][j] == 0) continue;
            ans[i][j] = min(A[j], B[i]);
        }
    }

    ans.each!(a => a.map!(to!string).join(" ").writeln);
}

import std.stdio, std.conv, std.string;
import std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

int DEBUG_LEVEL = 0;
void print()(){ writeln(""); }
void print(T, A ...)(T t, lazy A a){ write(t), print(a); }
void print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }

const long mod = 1_000_000_007;

void main(string[] args){
	if(args.length > 1 && args[1] == "-debug"){
		if(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;
		else DEBUG_LEVEL = 1;
	}

	int n = read.to!int;
	int m = read.to!int;
	int h = read.to!int;

	int[] as;
	foreach(j; 0 .. m) as ~= read.to!int;

	int[] bs;
	foreach(i; 0 .. n) bs ~= read.to!int;

	int[][] cs = new int[][](n, m);
	foreach(i; 0 .. n) foreach(j; 0 .. m) cs[i][j] = read.to!int;

	int[][] ans = new int[][](n, m);

	X[] xs;
	foreach(i; 0 .. n) xs ~= new X(true, i, bs[i]);
	foreach(j; 0 .. m) xs ~= new X(false, j, as[j]);

	xs.sort!"a.value > b.value"();

	int[] has = new int[](m);
	int[] hbs = new int[](n);

	foreach(x; xs){
		if(x.isRow){
			int i = x.number;
			int v = x.value;
			if(hbs[i] == v) continue;
			foreach(j; 0 .. m) if(as[j] >= v && cs[i][j]){
				cs[i][j] = 0;
				ans[i][j] = v;
				if(hbs[i] < v) hbs[i] = v;
				if(has[j] < v) has[j] = v;
				break;
			}
		}
		else{
			int j = x.number;
			int v = x.value;
			if(has[j] == v) continue;
			foreach(i; 0 .. n) if(bs[i] >= v && cs[i][j]){
				cs[i][j] = 0;
				ans[i][j] = v;
				if(hbs[i] < v) hbs[i] = v;
				if(has[j] < v) has[j] = v;
				break;
			}
		}
	}

	foreach(i; 0 .. n) foreach(j; 0 .. m) if(cs[i][j] && ! ans[i][j]) ans[i][j] = 1;

	foreach(i; 0 .. n) ans[i].map!(to!string).array.join(" ").writeln;

}

class X{
	bool isRow;
	int number;
	int value;
	this(bool isRow, int number, int value){
		this.isRow = isRow;
		this.number = number;
		this.value = value;
	}
}

/*

greedy.
taller column or row will be dealt earlier, then shorter ones.

at end, fill unused cells with height 1.

*/

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

string FMT_F = "%.10f";

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; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
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; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD!uint;
	auto M = RD!uint;
	auto H = RD;
	auto a = RDR.ARR;
	auto b = RDR.ARR;
	auto aa = a.dup;
	auto bb = b.dup;
	auto c = new long[][](N, M);
	auto ans = new long[][](N, M);
	foreach (i; 0..N)
	{
		c[i] = RDR.ARR;
		ans[i] = c[i].dup;
	}

	long cnt_a, cnt_b;
	foreach (x; 0..M)
	{
		if (a[x] != 0) ++cnt_a;
	}
	foreach (y; 0..N)
	{
		if (b[y] != 0) ++cnt_b;
	}

	long last_ca, last_cb;
	while (cnt_a != 0 || cnt_b != 0)
	{
		foreach (x; 0..M)
		{
			if (a[x] == 0) continue;

			long cnt;
			uint last;
			foreach (y; 0..N)
			{
				if (c[y][x] == 1)
				{
					++cnt;
					last = y;
				}
				else if (ans[y][x] == a[x])
				{
					foreach (y2; 0..N)
					{
						c[y2][x] = 0;
					}
					a[x] = 0;
					--cnt_a;
					cnt = -1;
					break;
				}
			}
			if (cnt == 1)
			{
				ans[last][x] = a[x];
				c[last][x] = 0;
				a[x] = 0;
				--cnt_a;
			}
			else if (cnt == 0)
			{
				foreach (y; 0..N)
				{
					if (ans[y][x] == 1)
					{
						ans[y][x] = a[x];
						c[y][x] = 0;
						a[x] = 0;
						--cnt_a;
						break;
					}
				}
			}
		}
		foreach (y; 0..N)
		{
			if (b[y] == 0) continue;

			long cnt;
			uint last;
			foreach (x; 0..M)
			{
				if (c[y][x] == 1)
				{
					++cnt;
					last = x;
				}
				else if (ans[y][x] == b[y])
				{
					foreach (x2; 0..M)
					{
						c[y][x2] = 0;
					}
					b[y] = 0;
					--cnt_b;
					cnt = -1;
					break;
				}
			}
			if (cnt == 1)
			{
				ans[y][last] = b[y];
				c[y][last] = 0;
				b[y] = 0;
				--cnt_b;
			}
			else if (cnt == 0)
			{
				foreach (x; 0..M)
				{
					if (ans[y][x] == 1)
					{
						ans[y][x] = b[y];
						c[y][x] = 0;
						b[y] = 0;
						--cnt_b;
						break;
					}
				}
			}
		}
		if (cnt_a == last_ca && cnt_b == last_cb)
			break;
		last_ca = cnt_a;
		last_cb = cnt_b;
	}

	debug writeln(a);
	debug writeln(b);
	//while (cnt_a != 0 || cnt_b != 0)
	{
		foreach (x; 0..M)
		{
			if (a[x] != 0)
			{
				foreach (y; 0..N)
				{
					if (ans[y][x] == 1 && bb[y] >= a[x])
					{
						ans[y][x] = a[x];
						a[x] = 0;
						--cnt_a;
						break;
					}
				}
			}
		}
		foreach (y; 0..N)
		{
			if (b[y] != 0)
			{
				foreach (x; 0..M)
				{
					if (ans[y][x] == 1 && aa[x] >= b[y])
					{
						ans[y][x] = b[y];
						b[y] = 0;
						--cnt_b;
						break;
					}
				}
			}
		}
	}

	debug writeln(a);
	debug writeln(b);

	foreach (y; 0..N)
	{
		write(ans[y][0]);
		foreach (x; 1..M)
		{
			write(" ", ans[y][x]);
		}
		writeln();
	}

	stdout.flush();
	debug readln();
}