malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   const int mod = 1000000007;   const int seed = 131;   char s[100005], t[1000005];   int hshv[1000005];   int powm(int a, int b) {     int ret = 1;     while (b) {       if (b & 1) ret = 1LL * ret * a % mod;       a = 1LL * a * a % mod;       b >>= 1;     }     return ret;   }   void gethash(char* s) {     int len = strlen(s), now;     now = 0;     for (int i = 0; i < len; i++) {       now = (1LL * now * seed + s[i]) % mod;       hshv[i] = now;     }   }   int get(int s, int t) {     int a, b;     if (s == 0)       a = 0;     else       a = 1LL * hshv[s - 1] * powm(seed, t - s + 1) % mod;     b = hshv[t];     return (b - a + mod) % mod;   }   int main() {     int cnt0, cnt1, lens, lent, len0, len1, hsh0, hsh1, p, ans;     bool f;     scanf( %s , s);     scanf( %s , t);     lens = strlen(s);     lent = strlen(t);     if (s[0] ==  1 )       for (int i = 0; i < lens; i++) s[i] = ((s[i] -  0 ) ^ 1) +  0 ;     cnt0 = 0;     cnt1 = 0;     for (int i = 0; i < lens; i++)       if (s[i] ==  0 )         cnt0++;       else         cnt1++;     ans = 0;     gethash(t);     for (int i = 1; cnt0 * i < lent; i++) {       if ((lent - cnt0 * i) % cnt1 != 0) continue;       len0 = i;       len1 = (lent - cnt0 * len0) / cnt1;       hsh0 = -1;       hsh1 = -1;       p = 0;       f = true;       for (int j = 0; j < lens; j++) {         if (s[j] ==  0 ) {           if (hsh0 == -1)             hsh0 = get(p, p + len0 - 1);           else if (get(p, p + len0 - 1) != hsh0) {             f = false;             break;           }           p += len0;         } else {           if (hsh1 == -1)             hsh1 = get(p, p + len1 - 1);           else if (get(p, p + len1 - 1) != hsh1) {             f = false;             break;           }           p += len1;         }       }       if (f && hsh0 != hsh1) ans++;     }     printf( %d n , ans);   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   template <typename T>   void ckmn(T& a, T b) {     a = min(a, b);   }   template <typename T>   void ckmx(T& a, T b) {     a = max(a, b);   }   void rd(int& x) { scanf( %i , &x); }   void rd(long long& x) { scanf( %lld , &x); }   void rd(char* x) { scanf( %s , x); }   void rd(double& x) { scanf( %lf , &x); }   void rd(string& x) { scanf( %s , &x); }   template <typename T1, typename T2>   void rd(pair<T1, T2>& x) {     rd(x.first);     rd(x.second);   }   template <typename T>   void rd(vector<T>& x) {     for (T& i : x) rd(i);   }   template <typename T, typename... A>   void rd(T& x, A&... args) {     rd(x);     rd(args...);   }   template <typename T>   void rd() {     T x;     rd(x);     return x;   }   int ri() {     int x;     rd(x);     return x;   }   template <typename T>   vector<T> rv(int n) {     vector<T> x(n);     rd(x);     return x;   }   template <typename T>   void ra(T a[], int n, int st = 1) {     for (int i = 0; i < n; ++i) rd(a[st + i]);   }   template <typename T1, typename T2>   void ra(T1 a[], T2 b[], int n, int st = 1) {     for (int i = 0; i < n; ++i) rd(a[st + i]), rd(b[st + i]);   }   template <typename T1, typename T2, typename T3>   void ra(T1 a[], T2 b[], T3 c[], int n, int st = 1) {     for (int i = 0; i < n; ++i) rd(a[st + i]), rd(b[st + i]), rd(c[st + i]);   }   void re(vector<int> E[], int m, bool dir = 0) {     for (int i = 0, u, v; i < m; ++i) {       rd(u, v);       E[u].push_back(v);       if (!dir) E[v].push_back(u);     }   }   template <typename T>   void re(vector<pair<int, T>> E[], int m, bool dir = 0) {     for (int i = 0, u, v; i < m; ++i) {       T w;       rd(u, v, w);       E[u].push_back({v, w});       if (!dir) E[v].push_back({u, w});     }   }   int main() {     for (int t = ri(); t--;) {       int n = ri();       vector<int> a(n + 1, 0);       vector<vector<int>> ids(n + 1, vector<int>());       for (int i = 1; i <= n; i++) {         rd(a[i]);         ids[a[i]].push_back(i);       }       vector<vector<int>> dp(n + 1, vector<int>(n + 1, 0));       vector<vector<bool>> was(n + 1, vector<bool>(n + 1, false));       function<int(int, int)> Solve = [&](int l, int r) {         if (l > r) return 0;         if (was[l][r]) return dp[l][r];         was[l][r] = 1;         if (l == r) return dp[l][r] = 1;         dp[l][r] = Solve(l + 1, r) + 1;         for (int i : ids[a[l]])           if (i > l && i <= r) {             ckmn(dp[l][r], Solve(l + 1, i - 1) + Solve(i, r));           }         return dp[l][r];       };       printf( %i n , Solve(1, n) - 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, q;   int p[100001];   int sz[100001];   int bc[100001];   int top[100001];   int newi[100001];   int sr[100001];   vector<int> c[100001];   pair<int, int> zero = {0, -1e9};   pair<int, int> f(pair<int, int> x, pair<int, int> y) {     return {x.first + y.first, max(y.second, x.second + y.first)};   }   pair<int, int> info[262144];   bool tag[262144];   int lazy[262144];   void put(int id, int l, int r, int v) {     tag[id] = true;     lazy[id] = v;     info[id] = {v * (r - l + 1), max(v * (r - l + 1), v)};   }   void push(int id, int l, int r) {     if (!tag[id]) return;     int mid = (l + r) / 2;     put(id * 2, l, mid, lazy[id]);     put(id * 2 + 1, mid + 1, r, lazy[id]);     tag[id] = false;   }   void upd1(int id, int l, int r, int ql, int qr, int v) {     if (ql > r || qr < l) return;     if (ql <= l && r <= qr) {       put(id, l, r, v);       return;     }     push(id, l, r);     int mid = (l + r) / 2;     upd1(id * 2, l, mid, ql, qr, v);     upd1(id * 2 + 1, mid + 1, r, ql, qr, v);     info[id] = f(info[id * 2], info[id * 2 + 1]);   }   void upd2(int id, int l, int r, int pos, int v) {     if (l == r) {       info[id] = {info[id].first + v, info[id].second + v};       return;     }     push(id, l, r);     int mid = (l + r) / 2;     if (pos <= mid)       upd2(id * 2, l, mid, pos, v);     else       upd2(id * 2 + 1, mid + 1, r, pos, v);     info[id] = f(info[id * 2], info[id * 2 + 1]);   }   pair<int, int> qry(int id, int l, int r, int ql, int qr) {     if (ql > r || qr < l) return zero;     if (ql <= l && r <= qr) return info[id];     push(id, l, r);     int mid = (l + r) / 2;     return f(qry(id * 2, l, mid, ql, qr), qry(id * 2 + 1, mid + 1, r, ql, qr));   }   int g(int id) {     pair<int, int> res = zero;     while (id != 0) {       res = f(qry(1, 1, n, newi[top[id]], newi[id]), res);       id = p[top[id]];     }     return res.second;   }   void dfs(int id) {     sz[id] = 1;     for (auto cur : c[id]) {       dfs(cur);       sz[id] += sz[cur];       if (sz[bc[id]] < sz[cur]) bc[id] = cur;     }   }   int ptr = 0;   void dfs2(int id) {     newi[id] = ++ptr;     sr[id] = ptr;     if (c[id].empty()) return;     top[bc[id]] = top[id];     dfs2(bc[id]);     sr[id] = sr[bc[id]];     for (auto cur : c[id]) {       if (cur != bc[id]) {         top[cur] = cur;         dfs2(cur);         sr[id] = sr[cur];       }     }   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> q;     for (int i = 2; i <= n; i++) {       cin >> p[i];       c[p[i]].push_back(i);     }     dfs(1);     top[1] = 1;     dfs2(1);     upd1(1, 1, n, 1, n, -1);     for (int i = 1; i <= q; i++) {       int t, u;       cin >> t >> u;       if (t == 1)         upd2(1, 1, n, newi[u], 1);       else if (t == 2) {         upd1(1, 1, n, newi[u], sr[u], -1);         int num = g(u);         if (num >= 0) upd2(1, 1, n, newi[u], -num - 1);       } else {         int num = g(u);         if (num >= 0)           cout <<  black n ;         else           cout <<  white n ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   int ch[300010][26];   int ans[300010], maxdep = 0;   int N;   int merge(vector<int> now) {     int res = now.size() - 1;     vector<int> next;     for (int i = 0; i < 26; i++) {       next.clear();       for (int j = 0; j < now.size(); j++)         if (ch[now[j]][i]) next.push_back(ch[now[j]][i]);       if (next.size() <= 1) continue;       res += merge(next);     }     return res;   }   void dfs(int x, int dep) {     vector<int> now;     now.clear();     maxdep = max(maxdep, dep);     for (int i = 0; i < 26; i++) {       if (!ch[x][i]) continue;       now.push_back(ch[x][i]);     }     int res = merge(now) + 1;     ans[dep] += res;     for (int i = 0; i < 26; i++) {       if (ch[x][i]) dfs(ch[x][i], dep + 1);     }   }   int main() {     scanf( %d , &N);     for (int i = 1; i < N; i++) {       int u, v;       char s[5];       scanf( %d%d , &u, &v);       scanf( %s , s);       ch[u][s[0] -  a ] = v;     }     memset(ans, 0, sizeof(ans));     dfs(1, 1);     int maxres = 0, mp;     for (int i = 1; i <= maxdep; i++)       if (maxres < ans[i]) {         maxres = ans[i];         mp = i;       }     printf( %d n%d n , N - maxres, mp);   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5e5 + 10;   int par[maxn], sub[maxn], col[maxn];   vector<pair<int, int>> parHis, colHis, subHis;   bool bad[maxn];   int c[maxn];   int root(int x) {     while (x != par[x]) {       x = par[x];     }     return x;   }   int getCol(int x) {     int res = 0;     while (x != par[x]) {       res ^= col[x];       x = par[x];     }     return res;   }   void save(int x, int y) {     parHis.emplace_back(x, par[x]);     subHis.emplace_back(y, sub[y]);     colHis.emplace_back(x, col[x]);   }   void join(int x, int y, bool rollback = false) {     int rx = root(x);     int ry = root(y);     int dif = (getCol(x) == getCol(y));     if (sub[rx] > sub[ry]) swap(rx, ry);     if (rollback) save(rx, ry);     par[rx] = ry;     sub[ry] += sub[rx];     col[rx] = dif;   }   bool check(int p, int q) {     if (root(p) == root(q) && getCol(p) == getCol(q)) return false;     return true;   }   int main() {     int n, m, k;     scanf( %d %d %d , &n, &m, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &c[i]);     }     map<pair<int, int>, vector<pair<int, int>>> cont;     for (int i = 1; i <= m; i++) {       int p, q;       scanf( %d %d , &p, &q);       if (c[p] > c[q]) swap(p, q);       cont[make_pair(c[p], c[q])].emplace_back(p, q);     }     for (int i = 1; i <= n; i++) {       par[i] = i;       col[i] = 0;       sub[i] = 1;     }     int active = k;     for (int i = 1; i <= k; i++) {       auto v = cont[make_pair(i, i)];       for (auto j : v) {         int p = j.first;         int q = j.second;         if (check(p, q)) {           join(p, q);         } else {           bad[i] = true;           active -= 1;           break;         }       }     }     long long ans = (1LL * active * (active - 1)) / 2;     for (auto i : cont) {       if (i.first.first == i.first.second) continue;       if (bad[i.first.first] || bad[i.first.second]) continue;       auto v = i.second;       for (auto j : v) {         int p = j.first;         int q = j.second;         if (check(p, q)) {           join(p, q, true);         } else {           ans -= 1;           break;         }       }       while (not parHis.empty()) {         auto ph = parHis.back();         auto ch = colHis.back();         auto sh = subHis.back();         parHis.pop_back();         colHis.pop_back();         subHis.pop_back();         par[ph.first] = ph.second;         col[ch.first] = ch.second;         sub[sh.first] = sh.second;       }     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using Int = long long;   constexpr static int mod = 1e9 + 7;   constexpr static int inf = (1 << 30) - 1;   constexpr static Int infll = (1LL << 61) - 1;   int Competitive_Programming =       (ios_base::sync_with_stdio(false), cin.tie(nullptr),        cout << fixed << setprecision(15), 0);   #pragma GCC target( avx2 )   #pragma GCC optimize( O3 )   #pragma GCC optimize( unroll-loops )   int main() {     Int N, D, M;     cin >> N >> D >> M;     vector<Int> a(N);     vector<Int> low, high;     for (int i = 0; i < N; i++) {       cin >> a[i];       if (a[i] > M)         high.push_back(a[i]);       else         low.push_back(a[i]);     }     sort(low.rbegin(), low.rend());     sort(high.rbegin(), high.rend());     vector<Int> lowsum(low.size() + 1), highsum(high.size() + 1);     for (int i = 0; i < low.size(); i++) lowsum[i + 1] = lowsum[i] + low[i];     for (int i = 0; i < high.size(); i++) highsum[i + 1] = highsum[i] + high[i];     Int ans = 0, hsz = highsum.size(), lsz = lowsum.size();     for (int i = 0; i < lsz; i++)       ans = max(ans, highsum[min(hsz - 1, (N - i + D) / (D + 1))] + lowsum[i]);     cout << ans <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 500001;   const int sqN = 708;   int ans[N];   int fre[N];   int v[N];   int block[sqN];   int answer = 0;   struct query {     int l;     int r;     int idx;   } Q[N];   bool comp(query &q1, query &q2) {     if (q1.l / sqN != q2.l / sqN) {       return q1.l < q2.l;     }     if ((q1.l / sqN) & 1) {       return q1.r < q2.r;     }     return q1.r > q2.r;   }   inline void add(int idx) {     int val = v[idx];     fre[val]++;     if (fre[val] == 1) {       answer++;       block[val / sqN]++;     }     if (fre[val] == 2) {       answer--;       block[val / sqN]--;     }   }   inline void rem(int idx) {     int val = v[idx];     fre[val]--;     if (fre[val] == 1) {       answer++;       block[val / sqN]++;     }     if (fre[val] == 0) {       answer--;       block[val / sqN]--;     }   }   inline int solve() {     if (answer == 0) {       return 0;     }     for (int i = 0; i < sqN; i++) {       if (block[i] > 0) {         for (int j = i * sqN; j < i * sqN + sqN; j++) {           if (fre[j] == 1) {             return j;           }         }       }     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     for (int i = 0; i < n; i++) {       cin >> v[i];     }     int q, l, r;     cin >> q;     for (int i = 0; i < q; i++) {       cin >> l >> r;       l--;       r--;       Q[i].l = l;       Q[i].r = r;       Q[i].idx = i;     }     sort(Q, Q + q, comp);     l = 0, r = -1;     for (int i = 0; i < q; i++) {       int L = Q[i].l;       int R = Q[i].r;       while (l < L) {         rem(l);         l++;       }       while (l > L) {         l--;         add(l);       }       while (r < R) {         r++;         add(r);       }       while (r > R) {         rem(r);         r--;       }       ans[Q[i].idx] = solve();     }     for (int i = 0; i < q; i++) {       cout << ans[i] <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5000;   long long cumulative[N + 10], arr[N + 10][3];   signed main() {     ios ::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long n, q;     cin >> n >> q;     vector<pair<long long, long long> > pi;     for (long long i = 0; i < q; i++) {       long long a, b;       cin >> a >> b;       cumulative[a] += 1;       cumulative[b + 1] -= 1;       pi.push_back({a, b});     }     for (long long i = 1; i <= n; i++) {       cumulative[i] += cumulative[i - 1];     }     for (long long i = 1; i <= n; i++) {       for (long long j = 0; j < 3; j++) {         if (cumulative[i] == j) {           arr[i][j] += (arr[i - 1][j] + 1);         } else {           arr[i][j] += arr[i - 1][j];         }       }     }     long long sz = pi.size();     sort(pi.begin(), pi.end());     long long ans = 0;     for (long long i = 0; i < sz - 1; i++) {       long long x = pi[i].first;       long long y = pi[i].second;       for (long long j = i + 1; j < sz; j++) {         long long two = 0;         long long a = pi[j].first;         long long b = pi[j].second;         if (a <= y) {           long long ax = max(x, a);           long long by = min(y, b);           two = (arr[by][2] - arr[ax - 1][2]);         }         long long zero = (arr[n][0] - arr[0][0]);         long long one = (arr[y][1] - arr[x - 1][1]) + (arr[b][1] - arr[a - 1][1]);         long long total = one + two + zero;         long long res = n - total;         ans = max(ans, res);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     long long int test = 1;     for (int loop = 0; loop < test; loop++) {       long long int num, val;       cin >> num >> val;       vector<long long int> arr;       long long int temp;       for (int i = 0; i < num; i++) {         cin >> temp;         arr.push_back(temp);       }       long long int count = 0;       for (int i = 0; i < num; i++) {         for (int j = 0; j < num; j++) {           if (abs(arr[i] - arr[j]) <= val && i != j) count++;         }       }       cout << count <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const int MOD = 1e9 + 7;   const int dx[4] = {0, 0, -1, 1};   const int dy[4] = {-1, 1, 0, 0};   const int N = 101;   int n, m, a[N][N], psum[N][N], T;   bool Check_1() {     if (psum[1][m] == 0) return true;     if (psum[n][1] == 0) return true;     if (psum[n][m] - psum[n - 1][m] == 0) return true;     if (psum[n][m] - psum[n][m - 1] == 0) return true;     return false;   }   bool Check_2() {     if (a[1][1] == 0 || a[1][m] == 0 || a[n][1] == 0 || a[n][m] == 0) return true;     for (int i = 2; i < n; i++) {       if (psum[i][m] - psum[i - 1][m] == 0) return true;     }     for (int i = 2; i < m; i++) {       if (psum[n][i] - psum[n][i - 1] == 0) return true;     }     return false;   }   bool Check_3() {     for (int i = 2; i < n; i++) {       if (a[i][1] == 0 || a[i][m] == 0) return true;     }     for (int i = 2; i < m; i++) {       if (a[1][i] == 0 || a[n][i] == 0) return true;     }     return false;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> T;     while (T--) {       cin >> n >> m;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           char c;           cin >> c;           int x = 0;           if (c ==  P ) x = 1;           psum[i][j] = psum[i - 1][j] + psum[i][j - 1] - psum[i - 1][j - 1] + x;           a[i][j] = x;         }       }       if (psum[n][m] == n * m) {         cout <<  MORTAL n ;         continue;       }       if (psum[n][m] == 0) {         cout << 0 <<   n ;         continue;       }       if (Check_1())         cout << 1 <<   n ;       else if (Check_2())         cout << 2 <<   n ;       else if (Check_3())         cout << 3 <<   n ;       else         cout << 4 <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct P {     long long x, y;   };   P rotate90(P a) {     P b;     b.x = -a.y, b.y = a.x;     return b;   }   P ar[4], br[4], cr[4];   P add(P a, P b) {     P c;     c.x = a.x + b.x;     c.y = a.y + b.y;     return c;   }   long long dis(P a, P b) {     return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);   }   int check(P eop[]) {     long long l[16], tp = 0;     for (int i = 0; i < 4; i++)       for (int j = i + 1; j < 4; j++) l[tp++] = dis(eop[i], eop[j]);     sort(l, l + tp);     if (l[0] == l[1] && l[1] == l[2] && l[2] == l[3] && l[0] == l[3] && l[0] &&         l[4] == l[5] && l[0] * 2 == l[4])       return 1;     else       return 0;   }   int main() {     int n;     scanf( %d , &n);     while (n--) {       for (int i = 0; i < 4; i++) {         scanf( %I64d%I64d%I64d%I64d , &ar[i].x, &ar[i].y, &br[i].x, &br[i].y);         cr[i].x = ar[i].x - br[i].x;         cr[i].y = ar[i].y - br[i].y;       }       int ans = 999;       for (int i = 0; i < 4; i++) {         for (int j = 0; j < 4; j++) {           for (int k = 0; k < 4; k++) {             for (int l = 0; l < 4; l++) {               P eop[4];               for (int z = 0; z < 4; z++) eop[z] = cr[z];               for (int z = 0; z < i; z++) eop[0] = rotate90(eop[0]);               for (int z = 0; z < j; z++) eop[1] = rotate90(eop[1]);               for (int z = 0; z < k; z++) eop[2] = rotate90(eop[2]);               for (int z = 0; z < l; z++) eop[3] = rotate90(eop[3]);               for (int z = 0; z < 4; z++) eop[z] = add(eop[z], br[z]);               if (check(eop)) ans = min(ans, i + j + k + l);             }           }         }       }       printf( %d n , ans == 999 ? -1 : ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long hit(long long n) { return ((1 + n) * n) / 2; }   int main() {     long long m, n;     scanf( %lld%lld , &n, &m);     long long hasilmin, hasilmax;     hasilmin = hit(n / m) * (n % m) + hit(n / m - 1) * (m - n % m);     hasilmax = hit(n - m);     printf( %lld %lld n , hasilmin, hasilmax);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int n, m, sx, sy, vx, vy;   inline long long int extgcd(long long int a, long long int b, long long int &x,                               long long int &y) {     if (!b) {       x = 1;       y = 0;       return a;     }     long long int d = extgcd(b, a % b, x, y);     long long int _x = y;     long long int _y = x - (a / b) * y;     x = _x;     y = _y;     return d;   }   inline long long int crt(long long int a1, long long int m1, long long int a2,                            long long int m2) {     a1 = (a1 + m1) % m1;     a2 = (a2 + m2) % m2;     if (a1 > a2) {       swap(a1, a2);       swap(m1, m2);     }     long long int x, y;     long long int d = extgcd(m1, m2, x, y);     if ((a2 - a1) % d) return -1;     x *= (a2 - a1) / d;     y *= -(a2 - a1) / d;     x = (x - (x / (m2 / d)) * m2 / d + m2 / d) % (m2 / d);     return m1 * x + a1;   }   signed main() {     cin >> n >> m >> sx >> sy >> vx >> vy;     if ((sx == 0 && sy == 0) || (sx == 0 && sy == m) || (sx == n && sy == 0) ||         (sx == n && sy == m)) {       cout << sx <<     << sy << endl;       return 0;     }     if (!vx) {       if (sx == 0) {         if (vy == 1) {           cout <<  0   << m << endl;         } else {           cout <<  0 0 n  << endl;         }       } else if (sx == n) {         if (vy == 1) {           cout << n <<     << m << endl;         } else {           cout << n <<     << 0 << endl;         }       } else {         cout << -1 << endl;       }       return 0;     }     if (!vy) {       if (sy == 0) {         if (vx == 1) {           cout << n <<   0  << endl;         } else {           cout <<  0 0 n  << endl;         }       } else if (sy == m) {         if (vx == 1) {           cout << n <<     << m << endl;         } else {           cout <<  0   << m << endl;         }       } else {         cout << -1 << endl;       }       return 0;     }     long long int T = crt(n - vx * sx, n, m - vy * sy, m);     if (T == -1) {       cout << -1 << endl;       return 0;     }     long long int X = sx + T * vx;     long long int Y = sy + T * vy;     X = (X < 0 ? -X : X);     Y = (Y < 0 ? -Y : Y);     cout << ((X / n) & 1) * n <<     << ((Y / m) & 1) * m << endl;   }