#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define pb push_back #define mp make_pair #define TASKNAME "" #ifdef LOCAL #define eprintf(...) fprintf(stderr,__VA_ARGS__) #else #define eprintf(...) #endif #define TIMESTAMP(x) eprintf("[" #x "] Time = %.3lfs\n",clock()*1.0/CLOCKS_PER_SEC) #ifdef linux #define LLD "%lld" #else #define LLD "%I64d" #endif #define sz(x) ((int)(x).size()) #define strstr strstr_wregthrtu using namespace std; typedef long double ld; typedef long long ll; typedef vector vll; typedef vector vi; typedef vector vvi; typedef vector vb; typedef vector vvb; typedef pair pii; typedef pair pll; //const int inf = 1e9; const double eps = 1e-9; //const double INF = inf; const double EPS = eps; const long long checkItCnt = 2000000; const long long maxMod = (ll)2e9; const long long maxT = 1000; void gcdex(ll a,ll b,ll &x,ll &y) { if (!a){ x = 0, y = 1; return; } ll x1, y1; gcdex(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; } // BEGIN ALGO //return pair(nmod,nr) //nr%mod1=r1, nr%mod2=r2 //nmod=mod1*mod2/gcd(mod1,mod2) //if input incosistent return mp(-1,-1) pll kto (ll mod1, ll r1, ll mod2, ll r2) { ll d=__gcd(mod1,mod2); if (r1%d!=r2%d) return mp(-1,-1); ll rd=r1%d; mod1/=d, mod2/=d, r1/=d, r2/=d; if (mod1