/* This code has been written by MinakoKojima, feel free to ask me question. Blog: http://www.shuizilong.com/house Template Date: 2015.10.12 Note: ... */ #pragma comment(linker, "/STACK:36777216") //#pragma GCC optimize ("O2") #define LOCAL #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include //#include //#include using namespace std; #define REP(i, n) for (int i=0;i=a;--i) #define REP_1(i, n) for (int i=1;i<=n;++i) #define FOR_1(i, a, b) for (int i=a;i<=b;++i) #define DWN_1(i, b, a) for (int i=b;i>=a;--i) #define REP_C(i, n) for (int n____=n,i=0;i=a____;--i) #define REP_N(i, n) for (i=0;i=a;--i) #define REP_1_C(i, n) for (int n____=n,i=1;i<=n____;++i) #define FOR_1_C(i, a, b) for (int b____=b,i=a;i<=b____;++i) #define DWN_1_C(i, b, a) for (int a____=a,i=b;i>=a____;--i) #define REP_1_N(i, n) for (i=1;i<=n;++i) #define FOR_1_N(i, a, b) for (i=a;i<=b;++i) #define DWN_1_N(i, b, a) for (i=b;i>=a;--i) #define REP_C_N(i, n) for (int n____=(i=0,n);i=a____;--i) #define REP_1_C_N(i, n) for (int n____=(i=1,n);i<=n____;++i) #define FOR_1_C_N(i, a, b) for (int b____=(i=a,b);i<=b____;++i) #define DWN_1_C_N(i, b, a) for (int a____=(i=b,a);i>=a____;--i) #define ECH(it, A) for (__typeof((A).begin()) it=(A).begin(); it != (A).end(); ++it) #define rECH(it, A) for (__typeof((A).rbegin()) it=(A).rbegin(); it != (A).rend(); ++it) #define REP_S(i, str) for (char*i=str;*i;++i) #define REP_L(i, hd, suc) for (int i=hd;i;i=suc[i]) #define REP_G(i, u) REP_L(i,hd[u],suc) #define REP_SS(x, s) for (int x=s;x;x=(x-1)&s) #define DO(n) for ( int ____n = n; ____n-->0; ) #define REP_2(i, j, n, m) REP(i, n) REP(j, m) #define REP_2_1(i, j, n, m) REP_1(i, n) REP_1(j, m) #define REP_3(i, j, k, n, m, l) REP(i, n) REP(j, m) REP(k, l) #define REP_3_1(i, j, k, n, m, l) REP_1(i, n) REP_1(j, m) REP_1(k, l) #define REP_4(i, j, k, ii, n, m, l, nn) REP(i, n) REP(j, m) REP(k, l) REP(ii, nn) #define REP_4_1(i, j, k, ii, n, m, l, nn) REP_1(i, n) REP_1(j, m) REP_1(k, l) REP_1(ii, nn) #define ALL(A) A.begin(), A.end() #define LLA(A) A.rbegin(), A.rend() #define CPY(A, B) memcpy(A, B, sizeof(A)) #define INS(A, P, B) A.insert(A.begin() + P, B) #define ERS(A, P) A.erase(A.begin() + P) #define LBD(A, x) (lower_bound(ALL(A), x) - A.begin()) #define UBD(A, x) (upper_bound(ALL(A), x) - A.begin()) #define CTN(T, x) (T.find(x) != T.end()) #define SZ(A) int((A).size()) #define PB push_back #define MP(A, B) make_pair(A, B) #define PTT pair #define Ts *this #define rTs return Ts #define fi first #define se second #define re real() #define im imag() #define Rush for(int ____T=RD(); ____T--;) #define Display(A, n, m) { \ REP(i, n){ \ REP(j, m-1) cout << A[i][j] << " "; \ cout << A[i][m-1] << endl; \ } \ } #define Display_1(A, n, m) { \ REP_1(i, n){ \ REP_1(j, m-1) cout << A[i][j] << " "; \ cout << A[i][m] << endl; \ } \ } typedef long long LL; //typedef long double DB; typedef double DB; typedef unsigned uint; typedef unsigned long long uLL; typedef vector VI; typedef vector VC; typedef vector VS; typedef vector VL; typedef vector VF; typedef set SI; typedef set SS; typedef map MII; typedef map MSI; typedef pair PII; typedef pair PLL; typedef vector VII; typedef vector VVI; typedef vector VVII; template inline T& RD(T &); template inline void OT(const T &); //inline int RD(){int x; return RD(x);} inline LL RD(){LL x; return RD(x);} inline DB& RF(DB &); inline DB RF(){DB x; return RF(x);} inline char* RS(char *s); inline char& RC(char &c); inline char RC(); inline char& RC(char &c){scanf(" %c", &c); return c;} inline char RC(){char c; return RC(c);} //inline char& RC(char &c){c = getchar(); return c;} //inline char RC(){return getchar();} template inline T& RDD(T &); inline LL RDD(){LL x; return RDD(x);} template inline T0& RD(T0 &x0, T1 &x1){RD(x0), RD(x1); return x0;} template inline T0& RD(T0 &x0, T1 &x1, T2 &x2){RD(x0), RD(x1), RD(x2); return x0;} template inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3){RD(x0), RD(x1), RD(x2), RD(x3); return x0;} template inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4); return x0;} template inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5); return x0;} template inline T0& RD(T0 &x0, T1 &x1, T2 &x2, T3 &x3, T4 &x4, T5 &x5, T6 &x6){RD(x0), RD(x1), RD(x2), RD(x3), RD(x4), RD(x5), RD(x6); return x0;} template inline void OT(const T0 &x0, const T1 &x1){OT(x0), OT(x1);} template inline void OT(const T0 &x0, const T1 &x1, const T2 &x2){OT(x0), OT(x1), OT(x2);} template inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3){OT(x0), OT(x1), OT(x2), OT(x3);} template inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4);} template inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5);} template inline void OT(const T0 &x0, const T1 &x1, const T2 &x2, const T3 &x3, const T4 &x4, const T5 &x5, const T6 &x6){OT(x0), OT(x1), OT(x2), OT(x3), OT(x4), OT(x5), OT(x6);} inline char& RC(char &a, char &b){RC(a), RC(b); return a;} inline char& RC(char &a, char &b, char &c){RC(a), RC(b), RC(c); return a;} inline char& RC(char &a, char &b, char &c, char &d){RC(a), RC(b), RC(c), RC(d); return a;} inline char& RC(char &a, char &b, char &c, char &d, char &e){RC(a), RC(b), RC(c), RC(d), RC(e); return a;} inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f); return a;} inline char& RC(char &a, char &b, char &c, char &d, char &e, char &f, char &g){RC(a), RC(b), RC(c), RC(d), RC(e), RC(f), RC(g); return a;} inline DB& RF(DB &a, DB &b){RF(a), RF(b); return a;} inline DB& RF(DB &a, DB &b, DB &c){RF(a), RF(b), RF(c); return a;} inline DB& RF(DB &a, DB &b, DB &c, DB &d){RF(a), RF(b), RF(c), RF(d); return a;} inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e){RF(a), RF(b), RF(c), RF(d), RF(e); return a;} inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f); return a;} inline DB& RF(DB &a, DB &b, DB &c, DB &d, DB &e, DB &f, DB &g){RF(a), RF(b), RF(c), RF(d), RF(e), RF(f), RF(g); return a;} inline void RS(char *s1, char *s2){RS(s1), RS(s2);} inline void RS(char *s1, char *s2, char *s3){RS(s1), RS(s2), RS(s3);} templateinline T0& RDD(T0&a, T1&b){RDD(a),RDD(b); return a;} templateinline T1& RDD(T0&a, T1&b, T2&c){RDD(a),RDD(b),RDD(c); return a;} template inline void RST(T &A){memset(A, 0, sizeof(A));} template inline void FLC(T &A, int x){memset(A, x, sizeof(A));} template inline void CLR(T &A){A.clear();} template inline void RST(T0 &A0, T1 &A1){RST(A0), RST(A1);} template inline void RST(T0 &A0, T1 &A1, T2 &A2){RST(A0), RST(A1), RST(A2);} template inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3){RST(A0), RST(A1), RST(A2), RST(A3);} template inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4);} template inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5);} template inline void RST(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){RST(A0), RST(A1), RST(A2), RST(A3), RST(A4), RST(A5), RST(A6);} template inline void FLC(T0 &A0, T1 &A1, int x){FLC(A0, x), FLC(A1, x);} template inline void FLC(T0 &A0, T1 &A1, T2 &A2, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x);} template inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x);} template inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x);} template inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x);} template inline void FLC(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6, int x){FLC(A0, x), FLC(A1, x), FLC(A2, x), FLC(A3, x), FLC(A4, x), FLC(A5, x), FLC(A6, x);} template inline void CLR(priority_queue &Q){while (!Q.empty()) Q.pop();} template inline void CLR(stack &S){while (!S.empty()) S.pop();} template inline void CLR(queue &Q){while (!Q.empty()) Q.pop();} template inline void CLR(T0 &A0, T1 &A1){CLR(A0), CLR(A1);} template inline void CLR(T0 &A0, T1 &A1, T2 &A2){CLR(A0), CLR(A1), CLR(A2);} template inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3){CLR(A0), CLR(A1), CLR(A2), CLR(A3);} template inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4);} template inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5);} template inline void CLR(T0 &A0, T1 &A1, T2 &A2, T3 &A3, T4 &A4, T5 &A5, T6 &A6){CLR(A0), CLR(A1), CLR(A2), CLR(A3), CLR(A4), CLR(A5), CLR(A6);} template inline void CLR(T &A, int n){REP(i, n) CLR(A[i]);} template inline bool EPT(T &a){return a.empty();} template inline T& SRT(T &A){sort(ALL(A)); return A;} template inline T& SRT(T &A, C cmp){sort(ALL(A), cmp); return A;} template inline T& RVS(T &A){reverse(ALL(A)); return A;} template inline T& UNQQ(T &A){A.resize(unique(ALL(A))-A.begin());return A;} template inline T& UNQ(T &A){SRT(A);return UNQQ(A);} template inline T& UNQ(T &A, C cmp){SRT(A, cmp);return UNQQ(A);} //} /** Constant List .. **/ //{ const int MOD = 998244353; const int INF = 0x3f3f3f3f; const LL INFF = 0x3f3f3f3f3f3f3f3fLL; const DB EPS = 1e-9; const DB OO = 1e20; const DB PI = acos(-1.0); //M_PI; const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, 1, -1}; //} /** Add On .. **/ //{ // <<= '0. Nichi Joo ., //{ template inline bool checkMin(T &a,const T b){return b < a ? a = b, 1 : 0;} template inline bool checkMax(T &a,const T b){return a < b ? a = b, 1 : 0;} template inline bool checkUpd(T& a, const T b, C c){return c(b,a) ? a = b, 1 : 0;} template inline T min(T a, T b, T c){return min(min(a, b), c);} template inline T max(T a, T b, T c){return max(max(a, b), c);} template inline T min(T a, T b, T c, T d){return min(min(a, b), min(c, d));} template inline T max(T a, T b, T c, T d){return max(max(a, b), max(c, d));} template inline T min(T a, T b, T c, T d, T e){return min(min(min(a,b),min(c,d)),e);} template inline T max(T a, T b, T c, T d, T e){return max(max(max(a,b),max(c,d)),e);} template inline T sqr(T a){return a*a;} template inline T cub(T a){return a*a*a;} template inline T ceil(T x, T y){return (x - 1) / y + 1;} template T abs(T x){return x>0?x:-x;} inline int sgn(DB x){return x < -EPS ? -1 : x > EPS;} inline int sgn(DB x, DB y){return sgn(x - y);} inline DB cos(DB a, DB b, DB c){return (sqr(a)+sqr(b)-sqr(c))/(2*a*b);} inline DB cot(DB x){return 1./tan(x);}; inline DB sec(DB x){return 1./cos(x);}; inline DB csc(DB x){return 1./sin(x);}; //} // <<= '1. Bitwise Operation ., //{ namespace BO{ inline bool _1(int x, int i){return bool(x&1<> 1) & 0x55555555) | ((x << 1) & 0xaaaaaaaa); x = ((x >> 2) & 0x33333333) | ((x << 2) & 0xcccccccc); x = ((x >> 4) & 0x0f0f0f0f) | ((x << 4) & 0xf0f0f0f0); x = ((x >> 8) & 0x00ff00ff) | ((x << 8) & 0xff00ff00); x = ((x >>16) & 0x0000ffff) | ((x <<16) & 0xffff0000); return x; } inline LL reverse_bits(LL x){ x = ((x >> 1) & 0x5555555555555555LL) | ((x << 1) & 0xaaaaaaaaaaaaaaaaLL); x = ((x >> 2) & 0x3333333333333333LL) | ((x << 2) & 0xccccccccccccccccLL); x = ((x >> 4) & 0x0f0f0f0f0f0f0f0fLL) | ((x << 4) & 0xf0f0f0f0f0f0f0f0LL); x = ((x >> 8) & 0x00ff00ff00ff00ffLL) | ((x << 8) & 0xff00ff00ff00ff00LL); x = ((x >>16) & 0x0000ffff0000ffffLL) | ((x <<16) & 0xffff0000ffff0000LL); x = ((x >>32) & 0x00000000ffffffffLL) | ((x <<32) & 0xffffffff00000000LL); return x; } template inline bool odd(T x){return x&1;} template inline bool even(T x){return !odd(x);} template inline T low_bit(T x) {return x & -x;} template inline T high_bit(T x) {T p = low_bit(x);while (p != x) x -= p, p = low_bit(x);return p;} template inline T cover_bit(T x){T p = 1; while (p < x) p <<= 1;return p;} template inline int cover_idx(T x){int p = 0; while (_1(p) < x ) ++p; return p;} inline int clz(int x){return __builtin_clz(x);} inline int clz(LL x){return __builtin_clzll(x);} inline int ctz(int x){return __builtin_ctz(x);} inline int ctz(LL x){return __builtin_ctzll(x);} inline int lg2(int x){return !x ? -1 : 31 - clz(x);} inline int lg2(LL x){return !x ? -1 : 63 - clz(x);} inline int low_idx(int x){return !x ? -1 : ctz(x);} inline int low_idx(LL x){return !x ? -1 : ctz(x);} inline int high_idx(int x){return lg2(x);} inline int high_idx(LL x){return lg2(x);} inline int parity(int x){return __builtin_parity(x);} inline int parity(LL x){return __builtin_parityll(x);} inline int count_bits(int x){return __builtin_popcount(x);} inline int count_bits(LL x){return __builtin_popcountll(x);} } using namespace BO;//} // <<= '2. Number Theory .,//{ namespace NT{ //#define gcd __gcd inline LL gcd(LL a, LL b){return b?gcd(b,a%b):a;} inline LL lcm(LL a, LL b){return a*b/gcd(a,b);} inline void INC(int &a, int b){a += b; if (a >= MOD) a -= MOD;} inline int sum(int a, int b){a += b; if (a >= MOD) a -= MOD; return a;} /* 模数两倍刚好超 int 时。 inline int sum(uint a, int b){a += b; a %= MOD;if (a < 0) a += MOD; return a;} inline void INC(int &a, int b){a = sum(a, b);} */ inline void DEC(int &a, int b){a -= b; if (a < 0) a += MOD;} inline int dff(int a, int b){a -= b; if (a < 0) a += MOD; return a;} inline void MUL(int &a, int b){a = (LL)a * b % MOD;} //inline int pdt(int a, int b){return (LL)a * b % MOD;} inline int pdt(int x,int y) { int ret; __asm__ __volatile__ ("\tmull %%ebx\n\tdivl %%ecx\n":"=d"(ret):"a"(x),"b"(y),"c"(MOD)); return ret; } inline int gcd(int m, int n, int &x, int &y){ x = 1, y = 0; int xx = 0, yy = 1, q; while (1){ q = m / n, m %= n; if (!m){x = xx, y = yy; return n;} DEC(x, pdt(q, xx)), DEC(y, pdt(q, yy)); q = n / m, n %= m; if (!n) return m; DEC(xx, pdt(q, x)), DEC(yy, pdt(q, y)); } } inline int sum(int a, int b, int c){return sum(a, sum(b, c));} inline int sum(int a, int b, int c, int d){return sum(sum(a, b), sum(c, d));} inline int pdt(int a, int b, int c){return pdt(a, pdt(b, c));} inline int pdt(int a, int b, int c, int d){return pdt(pdt(a, b), pdt(c, d));} inline int pow(int a, LL b){ int c(1); while (b){ if (b&1) MUL(c, a); MUL(a, a), b >>= 1; } return c; } template inline T pow(T a, LL b){ T c(1); while (b){ if (b&1) c = c * a; a = a * a; b >>= 1; } return c; } template inline T pow(T a, int b){ return pow(a, (LL)b); } inline int _I(int b){ int a = MOD, x1 = 0, x2 = 1, q; while (1){ q = a / b, a %= b; if (!a) return x2; DEC(x1, pdt(q, x2)); q = b / a, b %= a; if (!b) return x1; DEC(x2, pdt(q, x1)); } } inline void DIV(int &a, int b){MUL(a, _I(b));} inline int qtt(int a, int b){return pdt(a, _I(b));} } using namespace NT;//} // <<= '9. Comutational Geometry .,//{ namespace CG{ #define cPo const Po& #define cLine const Line& #define cSeg const Seg& inline DB dist2(DB x,DB y){return sqr(x)+sqr(y);} struct Po{ DB x,y;Po(DB x=0,DB y=0):x(x),y(y){} void in(){RF(x,y);}void out(){printf("(%.2f,%.2f)",x,y);} inline friend istream&operator>>(istream&i,Po&p){return i>>p.x>>p.y;} inline friend ostream&operator<<(ostream&o,Po p){return o<<"("<(cPo p)const{return!(Ts<=p);}bool operator >=(cPo p)const{return!(Ts 0 || y == 0 && x >= 0) ? 0 : 1; /*if (x > 0 && y >= 0) return 0; if (x <= 0 && y > 0) return 1; if (x < 0 && y <= 0) return 2; return 3;*/ } }; inline DB dot(DB x1,DB y1,DB x2,DB y2){return x1*x2+y1*y2;} inline DB dot(cPo a,cPo b){return dot(a.x,a.y,b.x,b.y);} inline DB dot(cPo p0,cPo p1,cPo p2){return dot(p1-p0,p2-p0);} inline DB det(DB x1,DB y1,DB x2,DB y2){return x1*y2-x2*y1;} inline DB det(cPo a,cPo b){return det(a.x,a.y,b.x,b.y);} inline DB det(cPo p0,cPo p1,cPo p2){return det(p1-p0,p2-p0);} inline DB ang(cPo p0,cPo p1){return acos(dot(p0,p1)/p0.len()/p1.len());} inline DB ang(cPo p0,cPo p1,cPo p2){return ang(p1-p0,p2-p0);} inline DB ang(cPo p0,cPo p1,cPo p2,cPo p3){return ang(p1-p0,p3-p2);} inline DB dist2(const Po &a, const Po &b){return dist2(a.x-b.x, a.y-b.y);} template inline int dett(const T1 &x, const T2 &y){return sgn(det(x, y));} template inline int dett(const T1 &x, const T2 &y, const T3 &z){return sgn(det(x, y, z));} template inline int dett(const T1 &x, const T2 &y, const T3 &z, const T4 &w){return sgn(det(x, y, z, w));} template inline int dott(const T1 &x, const T2 &y){return sgn(dot(x, y));} template inline int dott(const T1 &x, const T2 &y, const T3 &z){return sgn(dot(x, y, z));} template inline int dott(const T1 &x, const T2 &y, const T3 &z, const T4 &w){return sgn(dot(x, y, z, w));} template inline DB arg(const T1 &x, const T2 &y){DB a=ang(x,y);return~dett(x,y)?a:2*PI-a;} template inline DB arg(const T1 &x, const T2 &y, const T3 &z){DB a=ang(x,y,z);return~dett(x,y,z)?a:2*PI-a;} template inline DB arg(const T1 &x, const T2 &y, const T3 &z, const T4 &w){DB a=ang(x,y,z,w);return~dett(x,y,z,w)?a:2*PI-a;} template inline DB dist(const T1 &x, const T2 &y){return sqrt(dist2(x, y));} template inline DB dist(const T1 &x, const T2 &y, const T3 &z){return sqrt(dist2(x, y, z));} inline Po _1(Po p){return p._1();}inline Po conj(Po p){return p.conj();} inline Po lt(Po p){return p.lt();}inline Po rt(Po p){return p.rt();} inline Po rot(Po p,DB a,cPo o=Po()){return p.rot(a,o);} inline Po operator *(DB k,cPo p){return p*k;} inline Po operator /(DB k,cPo p){return conj(p)*k/p.len2();} typedef vector VP; struct Line{ Po a,b;Line(cPo a=Po(),cPo b=Po()):a(a),b(b){} Line(DB x0,DB y0,DB x1,DB y1):a(Po(x0,y0)),b(Po(x1,y1)){} Line(cLine l):a(l.a),b(l.b){} //Ax+By+C=0 Line(DB A,DB B,DB C){ C=-C;if(!::sgn(A))a=Po(0,C/B),b=Po(1,C/B); else if(!::sgn(B))a=Po(C/A,0),b=Po(C/A,1); else a=Po(0,C/B),b=Po(1,(C-A)/B); } void in(){a.in(),b.in();} inline friend istream&operator>>(istream&i,Line& p){return i>>p.a>>p.b;} inline friend ostream&operator<<(ostream&o,Line p){return o<= 0) return pb.len2(); return dist2(Line(l), p); } inline DB dist2(cSeg s,cLine l){ Po v1=s.a-l.a,v2=s.b-l.a;DB d1=det(l.d(),v1),d2=det(l.d(),v2); return sgn(d1)!=sgn(d2) ? 0 : sqr(min(fabs(d1), fabs(d2)))/l.len2(); } inline DB dist2(cSeg l1,cSeg l2){ if (~l1.sgn(l2)) return 0; else return min(dist2(l2,l1.a), dist2(l2,l1.b), dist2(l1,l2.a), dist2(l1,l2.b)); } template inline DB dist2(const T1& a, const T2& b){ return dist2(b, a); } } using namespace CG;//} //} /** I/O Accelerator Interface .. **/ //{ #define g (c=getchar()) #define d isdigit(g) #define p x=x*10+c-'0' #define n x=x*10+'0'-c #define pp l/=10,p #define nn l/=10,n template inline T& RD(T &x){ char c;while(!d);x=c-'0';while(d)p; return x; } template inline T& RDD(T &x){ char c;while(g,c!='-'&&!isdigit(c)); if (c=='-'){x='0'-g;while(d)n;} else{x=c-'0';while(d)p;} return x; } inline DB& RF(DB &x){ //scanf("%lf", &x); char c;while(g,c!='-'&&c!='.'&&!isdigit(c)); if(c=='-')if(g=='.'){x=0;DB l=1;while(d)nn;x*=l;} else{x='0'-c;while(d)n;if(c=='.'){DB l=1;while(d)nn;x*=l;}} else if(c=='.'){x=0;DB l=1;while(d)pp;x*=l;} else{x=c-'0';while(d)p;if(c=='.'){DB l=1;while(d)pp;x*=l;}} return x; } #undef nn #undef pp #undef n #undef p #undef d #undef g inline char* RS(char *s){ //gets(s); scanf("%s", s); return s; } LL last_ans; int Case; template inline void OT(const T &x){ //printf("Case #%d: ", ++Case); //printf("%lld\n", x); //printf("%I64d\n", x); //printf("%.9f\n", x); //printf("%d\n", x); cout << x << endl; //last_ans = x; } //}/* .................................................................................................................................. */ const int N = int(2e2) + 9; // <<= '7. Matrix Theory .,//{ namespace MT{ const int N = 209; int n = 0; struct matrix{ int d[N][N]; void init(int e = 0){RST(d); if(e) REP(i, n) d[i][i] = e;} matrix(int e = 0){init(e);} matrix operator *(const matrix &rhs) const{ matrix res; //REP_3(i, j, k, n, n, n) res.d[i][j] += d[i][k] * rhs.d[k][j]; REP_2(i, j, n, n){ LL tmp = 0; REP(k, n) tmp += (LL)d[i][k] * rhs.d[k][j]; res.d[i][j] = tmp % MOD; } return res; } matrix& operator *=(const matrix& rhs){return (*this) = (*this) * rhs;} inline int res(){ return d[0][n-1]; } void print() { REP(i, n) { REP(j, n) { cout << d[i][j] << " "; } cout << endl; } } }; } //using namespace MT;//} VI adj0[N]; VI adj1[N]; int n, m, k; void gao() { LL a, b; RD(a,b); if (a == b) { if (a == 1) printf("-1 -1\n"); else printf("%d %lld\n", 2, max(a, b)); return; } LL m = max(a, b); int p1 = INF, p2 = -1; for (int l = 2, t, r, t2, r2; l <= m; l = r + 1) { t = a / l, r = min(m, (t) ? (a / t) : INF); t2 = b / l, r2 = min(m, (t2) ? (b / t2) : INF); r = min(r, r2); if (t != t2 && (a - b) % (t - t2) == 0) { int tt =(a - b) / (t - t2); if (l <= tt && tt <= r) { checkMin(p1, tt); checkMax(p2, tt); } } } if (p1 == INF) p1 = -1; printf("%d %d\n", p1, p2); } int main() { #ifndef ONLINE_JUDGE freopen("/Users/minakokojima/Documents/GitHub/ACM-Training/Workspace/in.txt", "r", stdin); //freopen("/Users/minakokojima/Documents/GitHub/ACM-Training/Workspace/out.txt", "w", stdout); #endif Rush gao(); }