func_code_string: #include <bits/stdc++.h>   #pragma comment(linker,  /STACK:67108864 )   const int MOD = 1000000007;   const long long INF = 3000000000000000001;   const double EPS = 1e-6;   const int HASH_POW = 29;   const double PI = acos(-1.0);   using namespace std;   double workTime() { return double(clock()) / CLOCKS_PER_SEC; }   void my_return(int code) { exit(code); }   int n, q;   char p[2][200010];   const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};   int cur = 0, cmp[2][200010];   void dfs(int x, int y) {     if (p[x][y] ==  X ) return;     cmp[x][y] = cur;     for (int i = 0; i < 4; ++i) {       int nx = x + dx[i], ny = y + dy[i];       if (0 <= nx && nx < 2 && 0 <= ny && ny < n && cmp[nx][ny] == 0) dfs(nx, ny);     }   }   int sum[200010], ll[200010], rr[200010];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     mt19937 mt_rand(time(0));     scanf( %d %d n , &n, &q);     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < n; ++j) p[i][j] = getchar();       getchar();     }     for (int i = 0; i < 2; ++i) {       for (int j = 0; j < n; ++j) {         if (!cmp[i][j]) {           ++cur;           dfs(i, j);         }       }     }     int lastx = -1;     for (int j = 0; j < n; ++j) {       if (p[0][j] ==  X  && p[1][j] ==  . ) {         if (lastx == 1) ++sum[j];         lastx = 0;       } else if (p[0][j] ==  .  && p[1][j] ==  X ) {         if (lastx == 0) ++sum[j];         lastx = 1;       } else if (p[0][j] ==  X  && p[1][j] ==  X )         lastx = -1;     }     for (int j = 1; j < n; ++j) sum[j] += sum[j - 1];     ll[0] = -1;     for (int j = 0; j < n; ++j)       if ((p[0][j] ==  X  && p[1][j] ==  . ) ||           (p[0][j] ==  .  && p[1][j] ==  X ))         ll[j] = j;     for (int j = 1; j < n; ++j)       if (!ll[j]) ll[j] = ll[j - 1];     rr[n - 1] = -1;     for (int j = n - 1; j >= 0; --j)       if ((p[0][j] ==  X  && p[1][j] ==  . ) ||           (p[0][j] ==  .  && p[1][j] ==  X ))         rr[j] = j;     for (int j = n - 2; j >= 0; --j)       if (!rr[j]) rr[j] = rr[j + 1];     while (q--) {       int foo, bar;       scanf( %d %d , &foo, &bar);       int x1, y1, x2, y2;       x1 = (foo - 1) / n;       y1 = (foo - 1) % n;       x2 = (bar - 1) / n;       y2 = (bar - 1) % n;       if (y1 > y2) {         swap(x1, x2);         swap(y1, y2);       }       if (cmp[x1][y1] != cmp[x2][y2])         printf( -1 n );       else {         if (rr[y1] == rr[y2])           printf( %d n , abs(y1 - y2) + abs(x1 - x2));         else {           int ans = 0;           int nxtL = rr[y1], nxtR = ll[y2];           ans += abs(nxtL - y1) + abs(nxtR - y2);           if (p[x1][nxtL] ==  X ) ++ans;           if (p[x2][nxtR] ==  X ) ++ans;           ans += abs(nxtR - nxtL) + sum[nxtR];           if (nxtL) ans -= sum[nxtL];           printf( %d n , ans);         }       }     }     my_return(0);   }   