malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int A[1000005], B[1000005], cnt[1000005], num[1000005];   long long dp[2][1000005];   int main() {     int n, k;     long long l, ans = 0;     cin >> n >> l >> k;     if (l <= n) {       cout << l << endl;       return 0;     }     for (int i = 0; i < n; i++) scanf( %d , &A[i]);     for (int i = 0; i < n; i++) B[i] = A[i];     sort(B, B + n);     int m = 0, a = 0;     long long S = l / n;     for (int i = 0; i < n; i++) {       a++;       if (B[i] != B[i + 1] || i == n - 1) {         B[m] = B[i];         cnt[m++] = a;         a = 0;       }     }     sort(A, A + l % n);     for (int i = 0; i < m; i++) {       int t = lower_bound(A, A + l % n, B[i]) - A;       num[i] = l % n - t;     }     dp[0][0] = 1;     for (int i = 1; i <= min(S, 1LL * k); i++) {       int cur = i & 1;       long long sum = 0;       for (int j = 0; j < n; j++) {         sum = (sum + dp[!cur][j]) % 1000000007;         dp[cur][j] = (sum * cnt[j]) % 1000000007;         ans = (ans + dp[cur][j] * (S % 1000000007 + 1000000007 - i + 1)) %               1000000007;         if (i < k) ans = (ans + dp[cur][j] * num[j]) % 1000000007;       }     }     ans = (ans + l % n) % 1000000007;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   int n, q[20];   long long A, B, C, a, b, c, m, m1, ans, v, p[20];   void dfs1(register int s, long long now) {     if (now > m) return;     if (s > n) {       if (now < a) return;       b = now;       c = v / a / b;       if (a * b + a * c + b * c < ans)         ans = a * b + a * c + b * c, A = a, B = b, C = c;       return;     }     if (q[s]) q[s]--, dfs1(s, now * p[s]), q[s]++;     dfs1(s + 1, now);   }   void dfs2(register int s, long long now) {     if (now > m1) return;     if (s > n) {       if (a = now, v / a + 2 * a * sqrt(v / a) < ans)         m = sqrt(v / a) + 1e-8, dfs1(1, 1);       return;     }     if (q[s]) q[s]--, dfs2(s, now * p[s]), q[s]++;     dfs2(s + 1, now);   }   int main() {     for (register int T, x = scanf( %d , &T); T--;) {       scanf( %d , &n);       for (register int i = v = 1; i <= n; i++) {         scanf( %lld%d , &p[i], &q[i]);         for (register int j = 1; j <= q[i]; j++) v *= p[i];       }       ans = 5e18;       A = 0;       m1 = pow(v, 1. / 3) + 1e-8;       dfs2(1, 1);       printf( %lld %lld %lld %lld n , ans * 2, A, B, C);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   long long power(long long x, long long p) {     if (p == 0) return 1;     if (p == 1) return x;     if (p % 2) return x * power(x, p - 1);     long long y = power(x, p / 2);     return y * y;   }   void solve() {     long long n;     cin >> n;     long long arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     pair<long long, long long> modd, meven;     long long odd = 0, even = 0, l = -1, r = -1, res = 0;     for (int i = 0; i < n; i++) {       if (i % 2)         odd += arr[i];       else         even += arr[i];       long long cur = odd - even;       pair<long long, long long> p;       if (i % 2)         p = meven;       else         p = modd;       long long val = cur - p.first;       if (val > res) {         l = p.second;         r = i;         res = val;       }       long long x = odd - even + arr[i] * (i % 2 ? -1 : 1);       if (i % 2 == 0) {         if (x < meven.first) meven = make_pair(x, i);       } else {         if (x < modd.first) modd = make_pair(x, i);       }     }     if (l != -1) {       for (int i = 0; i < (r - l + 1) / 2; i++) {         swap(arr[l + i], arr[r - i]);       }     }     odd = 0;     even = 0;     for (int i = 0; i < n; i++) {       if (i % 2)         odd += arr[i];       else         even += arr[i];     }     cout << max(odd, even) << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 5001, M = 1e9 + 7;   int n, F, vis[maxn], T = 1, mid, a[maxn], b[maxn], w[maxn][maxn], ans = 1;   vector<int> g[maxn];   bool C[maxn];   bool dfs(int v) {     vis[v] = T;     for (int i = 0; i < g[v].size(); i++)       if (vis[g[v][i]] != T) {         C[g[v][i]] = !C[v];         if (!dfs(g[v][i])) return false;       } else if (C[g[v][i]] == C[v])         return false;     return true;   }   inline bool check(int x) {     for (int i = 1; i <= n; i++) g[i].resize(0);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         if (w[i][j] > x) g[i].push_back(j), g[j].push_back(i);     T++;     for (int i = 1; i <= n; i++)       if (vis[i] != T)         if (!dfs(i)) return false;     return true;   }   inline void bs(int f, int l) {     while (f != l) {       mid = (f + l) / 2;       if (check(mid))         l = mid;       else         f = mid + 1;     }     check(f);     F = f;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %d%d , a + i, b + i);     for (int i = 1; i <= n; i++)       for (int j = i + 1; j <= n; j++)         w[i][j] = abs(a[i] - a[j]) + abs(b[i] - b[j]);     bs(0, 7500);     T++;     ans = 1;     for (int i = 1; i <= n; i++)       if (vis[i] != T) dfs(i), ans = (ans << 1) % M;     printf( %d n%d n , F, ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> adj[200005];   long long eff[200005];   long long dp[200005][2];   long long dfs(int src, int polarity) {     long long &ret = dp[src][polarity];     if (ret != -1) return ret;     if (adj[src].size() == 0) return ret = eff[src] * polarity;     long long sumE = 0;     vector<long long> even(adj[src].size()), diff(adj[src].size());     for (int i = 0; i < adj[src].size(); i++) {       even[i] = dfs(adj[src][i], 0);       sumE += even[i];       diff[i] = dfs(adj[src][i], 1) - even[i];     }     sort(diff.begin(), diff.end());     vector<long long> temp = diff;     long long bestEvenFromChildren = sumE, bestOddFromChildren = sumE;     while (temp.size() >= 2 && temp.back() + temp[temp.size() - 2] > 0) {       bestEvenFromChildren += temp.back();       temp.pop_back();       bestEvenFromChildren += temp.back();       temp.pop_back();     }     temp = diff;     bestOddFromChildren += temp.back();     temp.pop_back();     while (temp.size() >= 2 && temp.back() + temp[temp.size() - 2] > 0) {       bestOddFromChildren += temp.back();       temp.pop_back();       bestOddFromChildren += temp.back();       temp.pop_back();     }     if (polarity == 0)       return ret = bestEvenFromChildren;     else       return ret = max(bestEvenFromChildren + eff[src], bestOddFromChildren);   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof dp);     int n;     cin >> n;     for (int i = 1; i <= n; i++) {       int p, e;       cin >> p >> eff[i];       if (p != -1) adj[p].push_back(i);     }     cout << max(dfs(1, 0), dfs(1, 1)) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, i, d[100005], x, y, a, b, c, r;   int main() {     cin >> n >> m;     for (i = 1; i <= m; i++) {       cin >> x >> y;       d[x]++;       d[y]++;     }     for (i = 1; i <= n; i++) {       if (d[i] == 1) a++;       if (d[i] == 2) b++;       if (d[i] == n - 1)         c++;       else         r++;     }     if (a == 2 && b == n - 2) {       cout <<  bus topology ;       return 0;     }     if (a == n - 1 && c == 1) {       cout <<  star topology ;       return 0;     }     if (b == n) {       cout <<  ring topology ;       return 0;     }     cout <<  unknown topology ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int mult(int a, int b) { return ((long long)a * b) % 1000000007; }   int binaryPow(int n, int p) {     int acc = 1;     while (p) {       if (p & 1) acc = mult(acc, n);       n = mult(n, n);       p >>= 1;     }     return acc;   }   int modularInv(int n) { return binaryPow(n, 1000000007 - 2); }   int main() {     int k, a, b;     cin >> k >> a >> b;     int pa = mult(a, modularInv(a + b));     int pb = mult(b, modularInv(a + b));     int modPB = modularInv(pb);     int dp[k + 1][k + 1];     for (int i = k; i >= 1; i--) {       for (int j = k; j >= 0; j--) {         if (i + j < k) {           dp[i][j] =               (mult(pa, dp[i + 1][j]) + mult(pb, dp[i][i + j])) % 1000000007;         } else {           dp[i][j] = (i + j + mult(pa, modPB)) % 1000000007;         }       }     }     cout << dp[1][0] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int MOD;   struct Modint {     int val;     Modint(int nval = 0) { val = nval % MOD; }     Modint& operator+=(Modint r) {       val = (val + r.val) % MOD;       return *this;     }     Modint operator+(Modint r) { return Modint(*this) += r; }     Modint& operator-=(Modint r) {       val = (val + MOD - r.val) % MOD;       return *this;     }     Modint operator-(Modint r) { return Modint(*this) -= r; }     Modint& operator*=(Modint r) {       val = 1LL * val * r.val % MOD;       return *this;     }     Modint operator*(Modint r) { return Modint(*this) *= r; }   };   int main() {     int n, k;     cin >> n >> k >> MOD;     static Modint dp[1001][100];     static Modint from_end[1001];     from_end[0] = 1;     from_end[1] = 9;     for (int i = 2; i <= n; i++) {       from_end[i] = from_end[i - 1] * 10;     }     Modint result = 0;     for (int i = 1; i < 10; i++) {       dp[1][i % k] += 1;     }     int tpow = 10 % k;     for (int i = 1; i < n; i++) {       for (int s = 1; s < k; s++) {         for (int m = 0; m < 10; m++) {           dp[i + 1][(s + tpow * m) % k] += dp[i][s];         }       }       for (int m = 1; m < 10; m++) {         dp[i + 1][tpow * m % k] += 1;       }       tpow = (tpow * 10) % k;     }     for (int i = 1; i <= n; i++) {       result += dp[i][0] * from_end[n - i];     }     cout << result.val <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   long long powmod(long long a, long long b, long long p) {     long long res = 1;     a %= p;     while (b) {       if (b & 1) res = res * a % p;       a = a * a % p;       b >>= 1;     }     return res;   }   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   void solve() {     int n, m;     cin >> n >> m;     vector<string> v(n);     for (int i = 0; i < n; i++) {       cin >> v[i];     }     string ans = v[0];     for (int j = 0; j < m; j++) {       char save = ans[j];       for (char d =  a ; d <=  z ; d++) {         ans[j] = d;         bool flag = true;         for (int z = 0; z < n; z++) {           int cntErrors = 0;           for (int c = 0; c < m; c++) {             if (v[z][c] != ans[c]) {               cntErrors++;             }           }           if (cntErrors > 1) {             flag = false;             break;           }         }         if (flag) {           cout << ans << endl;           return;         }       }       ans[j] = save;     }     cout <<  -1  << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }
#include <bits/stdc++.h>   using std::cin;   using std::cout;   using std::vector;   int main() {     long long n;     cin >> n;     int t = 0;     while (n > 0) {       if (n % 2 != 0) t++;       n = n / 2;     }     cout << t;     int h;     cin >> h;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dist[65][65][65];   int dp[65][65][65][2];   int n, m, r, td[65][65];   vector<long long> li[1024];   int ans[222222];   void prep() {     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         for (int k = 0; k < m; k++) dp[i][j][k][0] = dist[k][i][j];     for (int i = 0; i < int(li[0].size()); i++) {       int u = li[0][i], v = li[0][i + 1], ii = li[0][i + 2];       i++;       i++;       ans[ii] = 2000000000;       for (int car = 0; car < m; car++) ans[ii] = min(ans[ii], dp[u][v][car][0]);     }     int flag = 1;     for (int k = 1; k <= n; k++) {       for (int i = 0; i < n; i++)         for (int j = 0; j < n; j++) {           td[i][j] = dp[i][j][0][1 - flag];           for (int cc = 0; cc < m; cc++) {             td[i][j] = min(dp[i][j][cc][1 - flag], td[i][j]);           }         }       for (int car = 0; car < m; car++) {         for (int i = 0; i < n; i++)           for (int j = 0; j < n; j++) {             dp[i][j][car][flag] = td[i][j];             for (int p = 0; p < n; p++)               dp[i][j][car][flag] =                   min(dp[i][j][car][flag], td[i][p] + dist[car][p][j]);           }       }       for (int i = 0; i < int(li[k].size()); i++) {         int u = li[k][i], v = li[k][i + 1], ii = li[k][i + 2];         i++;         i++;         ans[ii] = 2000000000;         for (int car = 0; car < m; car++)           ans[ii] = min(ans[ii], dp[u][v][car][flag]);       }       flag = 1 - flag;     }   }   int main() {     scanf( %d , &n);     scanf( %d , &m);     scanf( %d , &r);     for (int i = 0; i < m; i++) {       for (int j = 0; j < n; j++)         for (int k = 0; k < n; k++) scanf( %d , &dist[i][j][k]);       for (int k = 0; k < n; k++)         for (int ii = 0; ii < n; ii++)           for (int j = 0; j < n; j++)             dist[i][ii][j] = min(dist[i][ii][j], dist[i][ii][k] + dist[i][k][j]);     }     for (int i = 0; i < r; i++) {       int u, v, k;       scanf( %d , &u);       scanf( %d , &v);       scanf( %d , &k);       u--;       v--;       k = min(k, n);       li[k].push_back(u);       li[k].push_back(v);       li[k].push_back(i);     }     prep();     for (int i = 0; i < r; i++) {       printf( %d , ans[i]);       ;       printf(  n );     }   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5;   const int maxm = 1e4;   struct tree {     int x, h, Lp, Rp;   } T[maxn + 5];   struct Mushroom {     int x, power;   } M[maxm + 5];   int n, m, cnt, L, R, posx[5 * maxn + 5];   double arr[20 * maxn + 5], lazy[20 * maxn + 5];   inline void Push_Up(int index) {     arr[index] = arr[2 * index] + arr[2 * index + 1];   }   inline void Push_Down(int index) {     double k = lazy[index];     arr[2 * index] *= k;     arr[2 * index + 1] *= k;     lazy[2 * index] *= k;     lazy[2 * index + 1] *= k;     lazy[index] = 1.0;   }   void Build(int index, int L, int R) {     lazy[index] = 1.0;     if (L == R) return;     int mid = L + R >> 1;     Build(2 * index, L, mid);     Build(2 * index + 1, mid + 1, R);   }   void Update_Point(int index, int L, int R, int pos, int value) {     if (L == R) {       arr[index] += value;       return;     }     int mid = L + R >> 1;     if (mid >= pos)       Update_Point(2 * index, L, mid, pos, value);     else       Update_Point(2 * index + 1, mid + 1, R, pos, value);     Push_Up(index);   }   void Update(int index, int L, int R, int UL, int UR, int p) {     if (L >= UL && R <= UR) {       double k = double(p) / 100;       arr[index] *= k;       lazy[index] *= k;       return;     }     if (lazy[index] != 1.0) Push_Down(index);     int mid = L + R >> 1;     if (mid >= UL) Update(2 * index, L, mid, UL, UR, p);     if (UR > mid) Update(2 * index + 1, mid + 1, R, UL, UR, p);     Push_Up(index);   }   int main(void) {     scanf( %d %d , &n, &m);     for (int i = 1; i <= n; ++i) {       scanf( %d %d %d %d , &T[i].x, &T[i].h, &T[i].Lp, &T[i].Rp);       posx[++cnt] = T[i].x - 1;       posx[++cnt] = T[i].x + 1;       posx[++cnt] = T[i].x - T[i].h;       posx[++cnt] = T[i].x + T[i].h;     }     for (int i = 1; i <= m; ++i) {       scanf( %d %d , &M[i].x, &M[i].power);       posx[++cnt] = M[i].x;     }     sort(posx + 1, posx + 1 + cnt);     cnt = unique(posx + 1, posx + 1 + cnt) - posx - 1;     Build(1, 1, cnt);     for (int i = 1; i <= m; ++i) {       L = lower_bound(posx + 1, posx + 1 + cnt, M[i].x) - posx;       Update_Point(1, 1, cnt, L, M[i].power);     }     for (int i = 1; i <= n; ++i) {       L = lower_bound(posx + 1, posx + 1 + cnt, T[i].x - T[i].h) - posx;       R = lower_bound(posx + 1, posx + 1 + cnt, T[i].x - 1) - posx;       Update(1, 1, cnt, L, R, 100 - T[i].Lp);       L = lower_bound(posx + 1, posx + 1 + cnt, T[i].x + 1) - posx;       R = lower_bound(posx + 1, posx + 1 + cnt, T[i].x + T[i].h) - posx;       Update(1, 1, cnt, L, R, 100 - T[i].Rp);     }     printf( %.10lf n , arr[1]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 0x3f3f3f3f;   const long long infLL = 0x3f3f3f3f3f3f3f3fLL;   const int maxn = 200 + 5;   const int maxl = 1000000 + 5;   int n, m, q;   int g[maxn][maxn];   int a[10], b[10];   bool mrk[maxn][maxn], vis[maxn][maxn];   int cx[maxn][maxn], cy[maxn][maxn], S[maxn][maxn];   char s[maxl];   int suf[maxl];   inline void go(int &x, int &y) {     int nx = x + a[g[x][y]], ny = y + b[g[x][y]];     if (1 <= nx && nx <= n && 1 <= ny && ny <= m) x = nx, y = ny;   }   void init() {     memset(S, -1, sizeof(S));     for (int i = (1); i <= (n); ++i)       for (int j = (1); j <= (m); ++j) {         int x = i, y = j;         go(x, y), mrk[x][y] = true;       }     for (int i = (1); i <= (n); ++i)       for (int j = (1); j <= (m); ++j)         if (!mrk[i][j]) {           int x = i, y = j;           do vis[x][y] = true, go(x, y);           while (!vis[x][y]);           if (S[x][y] == -1) {             int u = x, v = y, w = 0;             do w |= 1 << g[u][v], go(u, v);             while (u != x || v != y);             do cx[u][v] = u, cy[u][v] = v, S[u][v] = w, go(u, v);             while (u != x || v != y);           }           int u = i, v = j;           do             cx[u][v] = cx[x][y], cy[u][v] = cy[x][y], S[u][v] = S[x][y], go(u, v);           while (u != x || v != y);         }     for (int i = (1); i <= (n); ++i)       for (int j = (1); j <= (m); ++j)         if (!vis[i][j]) {           mrk[i][j] = false;           int x = i, y = j, z = 0;           do z |= 1 << g[x][y], go(x, y);           while (x != i || y != j);           do cx[x][y] = x, cy[x][y] = y, S[x][y] = z, go(x, y);           while (x != i || y != j);         }   }   bool find() {     int l = strlen(s);     suf[l] = 0;     for (int i = l - 1; i >= 0; --i) suf[i] = suf[i + 1] | (1 << (s[i] -  0 ));     for (int i = (1); i <= (n); ++i)       for (int j = (1); j <= (m); ++j)         if (!mrk[i][j]) {           int x = i, y = j, p = 0;           for (; x != cx[i][j] || y != cy[i][j]; go(x, y))             if (g[x][y] == s[p] -  0  && !s[++p]) return true;           if ((suf[p] & S[i][j]) == suf[p]) return true;         }     return false;   }   int main() {     scanf( %d%d%d , &n, &m, &q);     for (int i = (1); i <= (n); ++i)       for (int j = (1); j <= (m); ++j) scanf( %1d , &g[i][j]);     for (int i = 0; i < (10); ++i) scanf( %d%d , &a[i], &b[i]);     init();     while (q--) {       scanf( %s , s);       puts(find() ?  YES  :  NO );     }     return 0;   }
#include<map>   #include<set>   #include <vector>   #include<stack>   #include<queue>   #include<cmath>   #include<string>   #include<cstdio>   #include<cstring>   #include<cstdlib>   #include<iostream>   #include <numeric>       // #include <boost/multiprecision/cpp_dec_float_50.hpp>   // using namespace boost::multiprecision;      // #include <boost/multiprecision/cpp_dec_float.hpp>   // #include <boost/math/constants/constants.hpp>        // using boost::multiprecision::cpp_dec_float_50;      using namespace std;   #define ll long long   #define llf long long float   #define pl pair<ll,ll>   #define test() ll t;cin>>t;while(t--)   #define FOR(i,a,b) for(ll i=a;i<b;i++)   #define ROF(i,a,b) for(ll i=a;i>=b;i--)   #define endl   n    #define modulus 1000000007         //fast the code   #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);   // void fastscan(int &number){ bool negative = false;register int c;number = 0; c = getchar();if (c== - ){negative = true;c = getchar();}for (; (c>47 && c<58); c=getchar())number = number *10 + c - 48;if (negative)number *= -1;}           typedef vector<ll> vi ;   typedef vector<bool> vb ;   #define  PB push_back      ll Gcd(ll a, ll b)   {       if (b == 0)           return a;       return Gcd(b, a % b);           }      bool isPrime(int n){       // Corner cases      if(n==1) return true;       if (n < 1)           return false;       if (n <= 3)           return true;            // This is checked so that we can skip       // middle five numbers in below loop       if (n % 2 == 0 || n % 3 == 0)           return false;            for (int i = 5; i * i <= n; i = i + 6)           if (n % i == 0 || n % (i + 2) == 0)               return false;            return true;   }      // ll power(ll a,ll b){   //     if(b==0) return 1;   //     ll res=1;   //    while(b>0){   //         if(b&1) res*=a;   //         a*=a;   //         b>>=1;   //    }   //    return res;   // }   // ll gcd(ll a,ll b,ll &x,ll &y){   //     if(b==0){   //         x=1;y=0;   //         return a;   //     }      //     ll x1,y1;   //     ll d=gcd(b,a%b,x1,y1);   //     x=y1;   //     y=x1-y1*(a/b);   //     return d;      // }      // ll get(ll a,ll b, ll c,ll d){      //     ll x,y;   //     gcd(a,c)       // }      int main(){      fast          test(){       ll n;cin>>n;       ll a[n];       map<ll,ll>m;       FOR(i,0,n) {cin>>a[i];m[a[i]]++;}       map<ll,ll>::iterator itr=m.begin();            itr++;       ll res=0;       for(itr;itr!=m.end();itr++)          res+=itr->second;       cout<<res<<endl;          }      }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1001;   const int maxm = 1001;   char c[maxn][maxm];   int n, m;   int pair_num[maxn][maxm];   int pair_cnt;   int temp_color[maxn][maxm];   map<int, int> Color;   int main() {     scanf( %d%d n , &n, &m);     for (int i = 0, _n = (n); i < _n; i++) {       for (int j = 0, _n = (m); j < _n; j++) {         scanf( %c , &c[i][j]);       }       scanf(  n );     }     for (int i = 0, _n = (n); i < _n; i++) {       for (int j = 0, _n = (m); j < _n; j++) {         if (j < m - 1 && c[i][j] ==  .  && c[i][j + 1] ==  .  &&             !pair_num[i][j] && !pair_num[i][j + 1]) {           pair_num[i][j] = pair_num[i][j + 1] = ++pair_cnt;         }         if (i < n - 1 && c[i][j] ==  .  && c[i + 1][j] ==  .  &&             !pair_num[i][j] && !pair_num[i + 1][j]) {           pair_num[i][j] = pair_num[i + 1][j] = ++pair_cnt;         }       }     }     for (int i = 0, _n = (n); i < _n; i++) {       for (int j = 0, _n = (m); j < _n; j++) {         if (c[i][j] ==  .  && !pair_num[i][j]) {           if (j && pair_num[i][j - 1]) {             pair_num[i][j] = pair_num[i][j - 1];           } else if (i && pair_num[i - 1][j]) {             pair_num[i][j] = pair_num[i - 1][j];           } else if (i != n - 1 && pair_num[i + 1][j]) {             pair_num[i][j] = pair_num[i + 1][j];           } else if (j != m - 1 && pair_num[i][j + 1]) {             pair_num[i][j] = pair_num[i][j + 1];           } else {             printf( -1 n );             return 0;           }         }       }     }     for (int i = 0, _n = (n); i < _n; i++)       for (int j = 0, _n = (m); j < _n; j++)         temp_color[i][j] = (i % 3) * 3 + j % 3;     for (int i = 0, _n = (n); i < _n; i++) {       for (int j = 0, _n = (m); j < _n; j++) {         if (c[i][j] ==  .  && (i + j) % 2 == 0) {           if (Color.count(pair_num[i][j]) == 0)             Color[pair_num[i][j]] = temp_color[i][j];         }       }     }     for (int i = 0, _n = (n); i < _n; i++) {       for (int j = 0, _n = (m); j < _n; j++) {         if (c[i][j] ==  . )           printf( %d , Color[pair_num[i][j]]);         else           printf( # );       }       printf(  n );     }     return 0;   }