func_code_string: #include <bits/stdc++.h>   using namespace std;   long long check, tn, tm, maxn;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;       return a;     }     long long d = exgcd(b, a % b, x, y);     long long z = x;     x = y;     y = z - y * (a / b);     return d;   }   long long solve(long long x, long long y) {     long long c = x + y, dx, dy;     long long d = exgcd(tn, tm, dx, dy);     if (c % d) return maxn + 1;     long long mod = tm / d;     dx *= c / d;     if (mod < 0) mod = -mod;     dx = (dx % mod + mod) % mod;     long long ans = tn * dx - x;     if (ans < 0 || ans > maxn) return maxn + 1;     return ans;   }   int main() {     long long n, m, k, x, y;     cin >> n >> m >> k;     maxn = n * m / gcd(n, m);     tn = n << 1, tm = -(m << 1);     for (int i = 1; i <= k; ++i) {       cin >> x >> y;       long long ans = maxn + 1;       ans = min(ans, solve(x, y));       ans = min(ans, solve(x, -y));       ans = min(ans, solve(-x, y));       ans = min(ans, solve(-x, -y));       if (ans == maxn + 1)         cout << -1 << endl;       else         cout << ans << endl;     }   }   