malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main()   {       int t;       cin>>t;       while(t--)       {           int x,y;           cin>>x>>y;                      int count =0;           while(x>0&&y>0)           {               x--;               y--;               count+=2;           }           if(x!=0||y!=0)           count =count+2*max(x,y)-1;           cout<<count<<  n ;       }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long n, mod = 1000000007, a[26], f[1000] = {}, l[1000] = {}, g[1000];     string s;     cin >> n >> s;     for (int i = 0; i < 26; i++) cin >> a[i];     f[0] = l[0] = g[0] = 1;     for (int i = 1; i < n; i++) {       long long z = i, b[26] = {};       while (z >= 0) {         b[s[z] -  a ] = 1;         long long flag = 1;         for (int j = 0; j < 26; j++)           if (b[j] && a[j] < i - z + 1) {             flag = 0;             break;           }         if (!flag) break;         z--;       }       g[i] = i + 1;       for (long long j = z + 1; j <= i; j++) {         f[i] = (f[i] + (j ? f[j - 1] : 1)) % mod;         l[i] = max({l[i], i - j + 1, (j ? l[j - 1] : 0)});         g[i] = min(g[i], 1 + (j ? g[j - 1] : 0));       }     }     cout << f[n - 1] << endl << l[n - 1] << endl << g[n - 1];   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     while (scanf( %lld , &n) != EOF) {       long long tpn = n;       long long ninenum = 0;       long long tezheng;       while (tpn) {         tpn /= 10;         ninenum++;       }       ninenum--;       long long sum = 1;       while (ninenum) {         sum = sum * 10;         ninenum--;       }       long long fivesum = 5 * sum;       if (fivesum <= n) {         tezheng = fivesum;         sum = sum * 10;       } else {         tezheng = fivesum / 10;       }       long long ans = 0;       if (tezheng != 0) {         long long yunum = n % sum;         long long geshu = n / sum;         if (yunum <= tezheng - 1) {           ans = yunum * (geshu + 1) * (geshu) +                 (tezheng - 1 - yunum) * geshu * geshu;           ans += geshu * geshu;         } else {           if (yunum == sum - 1) {             ans +=                 (yunum - 1 - tezheng + 1) * (geshu + 1) * (geshu + 1) +                 (tezheng - 1 - (yunum - 1 - tezheng + 1)) * (geshu + 1) * (geshu);             ans += geshu * (geshu + 1);           } else {             ans += (yunum - tezheng + 1) * (geshu + 1) * (geshu + 1) +                    (tezheng - 1 - (yunum - tezheng + 1)) * (geshu + 1) * (geshu);             ans += geshu * geshu;           }         }       } else {         ans = n * (n - 1) / 2;       }       printf( %lld n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const long long INF = 1e18;   const long long MAX = 100100;   void pre() {}   void solve() {     long long n;     cin >> n;     vector<long long> p(n), c(n);     for (long long i = 0; i < n; ++i) cin >> p[i] >> c[i];     for (long long i = 0; i < n; ++i) {       if (c[i] > p[i]) {         cout <<  NO               <<   n ;         return;       }     }     for (long long i = 1; i < n; ++i) {       if (p[i] < p[i - 1]) {         cout <<  NO               <<   n ;         return;       }       if (c[i] < c[i - 1]) {         cout <<  NO               <<   n ;         return;       }       if ((p[i] - p[i - 1]) < (c[i] - c[i - 1])) {         cout <<  NO               <<   n ;         return;       }     }     cout <<  YES           <<   n ;   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     pre();     long long t = 1;     cin >> t;     for (long long CASE = 1; CASE <= t; ++CASE) {       solve();     }     {};     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   #pragma GCC optimize( unroll-loops )   using namespace std;   long long power(long long a, long long b, long long md) {     return (!b ? 1                : (b & 1 ? a * power(a * a % md, b / 2, md) % md                         : power(a * a % md, b / 2, md) % md));   }   const int xn = 2e2 + 10;   const int xm = -20 + 10;   const int sq = 300;   const int inf = 1e9 + 10;   const long long INF = 1e18 + 10;   const int mod = 1e6 + 7;   const int base = 257;   const int SIG = 26;   struct matrix {     long long n, m, a[xn][xn];     matrix(int n1, int m1, long long x = -INF) {       n = n1;       m = m1;       for (int i = 0; i < n; i++)         for (int j = 0; j < m; j++) a[i][j] = x;     }     matrix operator*(const matrix &t) {       matrix r = matrix(n, t.m);       for (int i = 0; i < n; i++)         for (int j = 0; j < t.m; j++)           for (int k = 0; k < m; k++)             r.a[i][j] = max(r.a[i][j], a[i][k] + t.a[k][j]);       return r;     }     matrix operator=(const int &t) {       for (int i = 0; i < n; ++i)         for (int j = 0; j < m; ++j) a[i][j] = t;     }   };   matrix Pow(matrix a, long long b) {     matrix res = matrix(a.n, a.m);     for (int i = 0; i < a.n; i++) res.a[i][i] = 0;     for (; b; b = b >> 1) {       if (b & 1) res = res * a;       a = a * a;     }     return res;   }   int n, a[xn], F[xn], nxt[SIG][xn];   int ahoq[xn], ptr, ps[xn], par[xn];   long long l, ans;   string S;   vector<int> vec[xn], adj[xn];   void build_aho() {     int L = 0, R = 0;     for (int i = 0; i < SIG; ++i)       if (nxt[i][0]) ahoq[R++] = nxt[i][0];     while (L < R) {       int v = ahoq[L++];       adj[F[v]].push_back(v);       for (int i = 0; i < SIG; ++i) {         if (nxt[i][v])           F[nxt[i][v]] = nxt[i][F[v]], ahoq[R++] = nxt[i][v];         else           nxt[i][v] = nxt[i][F[v]];       }     }   }   void DFS(int v) {     vec[v].push_back(v);     for (int u : adj[v]) {       ps[u] += ps[v];       DFS(u);       for (int x : vec[u]) vec[v].push_back(x);     }   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     ;     cin >> n >> l;     for (int i = 1; i <= n; ++i) cin >> a[i];     for (int i = 1; i <= n; ++i) {       cin >> S;       int v = 0;       for (int j = 0; j < int(S.size()); ++j) {         int c = S[j] -  a ;         if (!nxt[c][v]) nxt[c][v] = ++ptr;         par[nxt[c][v]] = v;         v = nxt[c][v];       }       ps[v] += a[i];     }     matrix m(ptr + 1, 1), c(ptr + 1, ptr + 1);     build_aho(), DFS(0);     for (int i = 0; i <= ptr; ++i)       for (int v : vec[par[i]]) c.a[i][v] = ps[i];     m.a[0][0] = 0;     m = Pow(c, l) * m;     for (int i = 0; i <= ptr; ++i) ans = max(ans, m.a[i][0]);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long a, long long b) {     if (b == 0LL) return a;     return gcd(b, a % b);   }   long long bigmod(long long a, long long b, long long mod) {     if (b == 0LL) return 1LL;     long long sq = bigmod(a, b / 2LL, mod);     sq = (sq * sq) % mod;     if (b & 1LL) return (sq * (a % mod)) % mod;     return sq;   }   vector<int> primes;   vector<int> sieve(const int n) {     vector<int> primes(n + 1, 0);     primes[1] = 1;     for (int p = 2; p * p <= n; p++) {       if (!primes[p]) {         for (int i = p * p; i <= n; i += p) primes[i] = p;       }     }     for (int i = 2; i <= n; i++)       if (!primes[i]) primes[i] = i;     return primes;   }   map<int, int> getDivs(int x) {     map<int, int> divs;     while (x > 1) {       int div = primes[x];       int cnt = 0;       while (x % div == 0) {         x /= div;         cnt++;       }       divs[div] = cnt;     }     return divs;   }   void solve() {     int n;     cin >> n;     vector<int> a(n);     vector<int> cm(n + 1, 100000000);     for (auto &x : (a)) {       cin >> x;     }     for (int i = n - 1; i >= 0; i--) {       cm[i] = min(cm[i + 1], a[i]);     }     int ans = 0;     for (int i = 1; i < n; i++) {       if (cm[i] < a[i - 1]) ans++;     }     cout << ans << endl;   }   int main() {     int t = 1;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 100 * 1000;   int n;   long long dp[2][N];   int c[N], a[N];   bool read() {     if (!(cin >> n)) return false;     for (int i = 0; i < int(n); ++i) {       cin >> a[i];       c[i] = a[i];     }     return true;   }   void upd(long long &a, long long b) {     if (a == -1) a = b;     a = min(a, b);   }   void solve() {     int t = 0;     sort(c, c + n);     memset(dp, -1, sizeof dp);     dp[t][0] = 0;     for (int i = 0; i < int(n); ++i) {       memset(dp[!t], -1, sizeof(dp[!t]));       long long mn = -1;       for (int j = 0; j < int(n); ++j) {         if (dp[t][j] != -1) upd(mn, dp[t][j]);         upd(dp[!t][j], mn + abs(a[i] - c[j]));       }       t = !t;     }     long long res = -1;     for (int i = 0; i < int(n); ++i)       if (dp[t][i] != -1) upd(res, dp[t][i]);     cout << res << endl;   }   int main() {     while (read()) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long dp[55][2];   int main() {     long long X, Y;     scanf( %lld %lld , &Y, &X);     dp[51][0] = 1;     for (int i = 50; i >= 0; i--) {       for (int flag = 0; flag <= 1; flag++) {         bool x = (X >> i) & 1, y = (Y >> i) & 1;         if (x)           dp[i][flag] += dp[i + 1][(flag + 1) / 2] * (flag != y) * 2;         else {           dp[i][flag] += dp[i + 1][(flag + 2) / 2] * (flag == y);           dp[i][flag] += dp[i + 1][0] * (flag == y);         }       }     }     if (!X) assert(dp[0][0] - (X == Y) * 2 == (!(Y & 1)));     printf( %lld n , dp[0][0] - (X == Y) * 2);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[120][120] = {0}, n;   int main() {     int i, j, k;     scanf( %d , &n);     if (n == 1) {       puts( 0 );       return 0;     }     if (n == 2) {       puts( 1 n1 2 );       return 0;     }     if (n == 3) {       puts( 2 n1 2 n2 3 );       return 0;     }     int x = n / 2;     int y = n - x;     for (i = 0; i < x; i++) {       for (j = 0; j < x; j++) {         a[i][j] = -1;       }     }     for (i = x; i < n; i++) {       for (j = x; j < n; j++) {         a[i][j] = -1;       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (!a[i][j]) a[i][j] = 1;       }     }     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         if (a[i][j] == -1) a[i][j] = 0;       }     }     int ans = 0;     for (i = 0; i < n; i++) {       for (j = 0; j < n; j++) {         ans += a[i][j];       }     }     ans /= 2;     printf( %d n , ans);     for (i = 0; i < n; i++) {       for (j = i + 1; j < n; j++) {         if (a[i][j]) {           printf( %d %d n , i + 1, j + 1);         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   constexpr T inf = numeric_limits<T>::max() / 2;   long long calc(long long border, const vector<int> &h,                  const vector<long long> &acc, const vector<long long> &acc_rev,                  int a, int r, int m) {     int n = h.size();     if (border > h[n - 1] || border < h[0]) return inf<long long>;     int pos = -1;     for (int i = 0; (i) < (int)(n); (i)++) {       if (h[i] <= border && (i == n - 1 || h[i + 1] > border)) {         pos = i;         break;       }     }     assert(pos != -1);     long long x = border * (pos + 1) - acc[pos];     long long y = (pos == n - 1 ? 0 : acc_rev[pos + 1] - border * (n - pos - 1));     if (y >= x) {       return (long long)(y - x) * r + (long long)x * m;     } else {       return (long long)(x - y) * a + (long long)y * m;     }   }   int main() {     int n, a, r, m;     scanf( %d%d%d%d , &n, &a, &r, &m);     m = min(m, a + r);     vector<int> h(n);     for (int i = 0; (i) < (int)(n); (i)++) {       scanf( %d , &h[i]);     }     sort(h.begin(), h.end());     vector<long long> acc(n), acc_rev(n);     acc[0] = h[0];     for (int i = 0; (i) < (int)(n); (i)++)       if (i) acc[i] = acc[i - 1] + h[i];     acc_rev[n - 1] = h[n - 1];     for (int i = n - 2; i >= 0; i--) acc_rev[i] = acc_rev[i + 1] + h[i];     long long lb = h[0], ub = h[n - 1] + 1;     while (ub - lb > 3) {       long long ml = (2 * lb + ub) / 3;       long long mr = (lb + 2 * ub) / 3;       long long cl = calc(ml, h, acc, acc_rev, a, r, m);       long long cr = calc(mr, h, acc, acc_rev, a, r, m);       if (cl < cr) {         ub = mr;       } else {         lb = ml;       }     }     long long ans = inf<long long>;     for (int p = lb - 3; p <= lb + 10; p++) {       ans = min(ans, calc(p, h, acc, acc_rev, a, r, m));     }     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, flag = 0;     while (scanf( %d , &n) != EOF) {       int a[n];       for (int i = 0; i < n; i++) {         scanf( %d , &a[i]);         if (a[i] == 1) {           flag = 1;         }       }       if (flag == 1)         printf( -1 n );       else         printf( 1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long w, m;     cin >> w >> m;     vector<int> f;     while (m) {       f.push_back(m % w);       m /= w;     }     f.push_back(0);     f.push_back(0);     reverse(f.begin(), f.end());     for (int i = f.size() - 1; i >= 0; i--) {       if (i > 1) f[i - 1] += f[i] / w;       f[i] %= w;       if (f[i] == 0) continue;       if (f[i] == 1) continue;       if (f[i] == w - 1) {         f[i - 1]++;         continue;       }       cout <<  NO ;       return 0;     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   int n, a[211111];   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       cin >> a[i];     }     long long l = 0;     long long r = 0;     long long suml = 0;     long long sumr = 0;     for (int i = 0; i < n; i++) {       if (a[i] == 1) {         r++;       }       if (a[i] == 0) {         suml += r;       }     }     for (int i = n - 1; i >= 0; i--) {       if (a[i] == 0) {         l++;       }       if (a[i] == 1) {         sumr += l;       }     }     cout << min(sumr, suml);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 1000;   int from[MAXN + 5];   void Gauss(int n, int d, double a[][MAXN + 5], double *Ans) {     for (int i = 1; i <= n; i++) from[i] = i;     for (int i = 1; i <= n; i++) {       if (!a[i][i])         for (int j = i + 1; j <= min(n, i + d); j++)           if (a[i][j]) {             for (int k = max(1, i - d); k <= min(n, i + d); k++)               swap(a[k][i], a[k][j]);             swap(from[i], from[j]);             break;           }       for (int j = i + 1; j <= min(n, i + d); j++) {         double div = a[j][i] / a[i][i];         for (int k = i; k <= min(n, i + d); k++) a[j][k] -= a[i][k] * div;         a[j][n + 1] -= a[i][n + 1] * div;       }     }     for (int i = n; i >= 1; i--) {       Ans[from[i]] = a[i][n + 1];       for (int j = i + 1; j <= min(i + d, n); j++)         Ans[from[i]] -= Ans[from[j]] * a[i][j];       Ans[from[i]] /= a[i][i];     }   }   int n, m, x, y;   double a[MAXN + 5][MAXN + 5], Ans[MAXN + 5][MAXN + 5];   int main() {     scanf( %d %d %d %d , &n, &m, &x, &y);     if (m == 1) {       printf( %.4f n , 2.0 * (n - x));       return 0;     }     for (int i = n - 1; i >= 1; i--) {       a[1][1] = 2.0 / 3;       a[1][2] = -1.0 / 3;       a[1][m + 1] = 1.0 / 3 * Ans[i + 1][1] + 1;       for (int j = 2; j <= m - 1; j++) {         a[j][j - 1] = -1.0 / 4;         a[j][j] = 3.0 / 4;         a[j][j + 1] = -1.0 / 4;         a[j][m + 1] = 1.0 / 4 * Ans[i + 1][j] + 1;       }       a[m][m - 1] = -1.0 / 3;       a[m][m] = 2.0 / 3;       a[m][m + 1] = 1.0 / 3 * Ans[i + 1][m] + 1;       Gauss(m, 1, a, Ans[i]);     }     printf( %.4f n , Ans[x][y]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 6e3;   const int M = 2 * 5e3 + 2;   int n, m;   int G[N], H[N];   int q[N], qf, qb;   int dG[N][N], bG[N][3], szG[N];   int dH[N][N], bH[N][3], szH[N];   int ansv[4], aux[6], as;   int to[M], nx[M], es;   void calculate(int* ad, int d[][N], int b[][3], int sz[N]) {     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) d[i][j] = n << 1;       d[i][n] = -N;       d[i][i] = 0;       qf = qb = 0;       q[qb++] = i;       while (qb - qf > 0) {         int j = q[qf++];         for (int e = ad[j]; e; e = nx[e])           if (d[i][to[e]] > d[i][j] + 1) {             d[i][to[e]] = d[i][j] + 1;             q[qb++] = to[e];           }       }       int k = 0;       for (int j = qf - 1; j && k < 3; --j) b[i][k++] = q[j];       sz[i] = k;     }   }   int main() {     scanf(  %d%d , &n, &m);     for (int i = 0; i < m; i++) {       int j, k;       scanf(  %d%d , &j, &k);       --j;       --k;       dG[j][k] = 1;     }     es = 1;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (dG[i][j]) {           to[es] = j;           nx[es] = G[i];           G[i] = es++;           to[es] = i;           nx[es] = H[j];           H[j] = es++;         }     calculate(G, dG, bG, szG);     calculate(H, dH, bH, szH);     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) {         if (dG[i][j] == (n << 1)) dG[i][j] = -N;         if (dH[i][j] == (n << 1)) dH[i][j] = -N;       }     int ans = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++)         if (i != j) {           for (int _i = 0; _i < szH[i]; _i++)             for (int _j = 0; _j < szG[j]; _j++) {               int k = bH[i][_i], l = bG[j][_j];               if (k == l || k == j || i == l) continue;               if (dH[i][k] + dG[i][j] + dG[j][l] > ans) {                 ans = dH[i][k] + dG[i][j] + dG[j][l];                 ansv[0] = k, ansv[1] = i, ansv[2] = j, ansv[3] = l;               }             }         }     for (int i = 0; i < 4; i++) printf( %d%c , 1 + ansv[i],    n [i == 3]);   }
#include <bits/stdc++.h>   using namespace std;   long long n;   pair<long long, long long> loc[2001];   long long cp[2001];   long long cw[2001];   pair<long long, pair<long long, long long> > road[4000001];   long long ct = 0;   long long val[2001];   long long ans = 0;   long long ansleft;   long long ansr = 0;   bool cs[4000001];   struct node {     long long r, f;   } opt[100001];   long long fd(long long x) {     if (x != opt[x].f) opt[x].f = fd(opt[x].f);     return opt[x].f;   }   void mdf(long long x, long long y) {     x = fd(x), y = fd(y);     if (x == y) return;     if (opt[x].r < opt[y].r)       opt[x].f = y, opt[y].r += opt[x].r;     else       opt[y].f = x, opt[x].r += opt[y].r;   }   long long dis(long long x, long long y) {     return abs(loc[x].first - loc[y].first) + abs(loc[x].second - loc[y].second);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long i, j;     for (long long i = 1; i <= 100000; i++) opt[i].f = i, opt[i].r = 1;     cin >> n, ansleft = n;     for (i = 1; i <= n; i++) cin >> loc[i].first >> loc[i].second;     for (i = 1; i <= n; i++) cin >> cp[i];     for (i = 1; i <= n; i++) cin >> cw[i];     for (i = 1; i <= n; i++) val[i] = cp[i];     for (i = 1; i <= n; i++) ans += cp[i];     for (i = 1; i <= n; i++)       for (j = i + 1; j <= n; j++)         road[++ct] = pair<long long, pair<long long, long long> >(             dis(i, j) * (cw[i] + cw[j]), pair<long long, long long>(i, j));     sort(road + 1, road + ct + 1);     for (i = 1; i <= ct; i++) {       pair<long long, pair<long long, long long> > f = road[i];       long long aa = fd(f.second.first), bb = fd(f.second.second);       if (aa != bb && f.first < max(val[aa], val[bb])) {         mdf(aa, bb);         long long father = fd(aa);         ans -= max(val[aa], val[bb]) - f.first;         val[father] = min(val[aa], val[bb]);         ansleft--, ansr++;         cs[i] = true;       }     }     cout << ans << endl;     cout << ansleft << endl;     for (i = 1; i <= n; i++) {       if (cp[i] == val[fd(i)]) cout << i <<    , val[fd(i)] = -1;     }     cout << endl;     cout << ansr << endl;     for (i = 1; i <= ct; i++)       if (cs[i])         cout << road[i].second.first <<     << road[i].second.second << endl;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC target( avx2 )   #pragma GCC optimize( unroll-loops )   #pragma GCC optimize( Ofast )   constexpr long long INF = 200000000000000001LL;   constexpr int INF32 = 2100000001;   size_t seed42 = std::chrono::system_clock::now().time_since_epoch().count();   std::mt19937 rng(seed42);   std::uniform_int_distribution<int> unidistrib;   int randint() { return unidistrib(rng); }   using namespace std;   unsigned long long modulo = 998244353;   int modulo32 = 998244353;   unsigned long long poww(unsigned long long x, unsigned long long n) {     if (n == 0) return 1;     unsigned long long answ = poww(x, n / 2);     answ = (answ * answ) % modulo;     if (n % 2) answ = (answ * x) % modulo;     return answ;   }   pair<int, int> operator+(const pair<int, int>& lhs, pair<int, int>& rhs) {     return {lhs.first + rhs.first, lhs.second + rhs.second};   }   template <class T>   ostream& operator<<(ostream& lhs, pair<T, T>& rhs) {     return (lhs << rhs.first <<  :  << rhs.second);   }   struct Node {     Node(int p, int a, int c) : p(p), a(a), c(c), p2(1, p) {}     int p;     int a;     int c;     vector<int> p2;   };   int main() {     ios::sync_with_stdio(false);     std::cin.tie(0);     int n, m, t;     cin >> n >> m;     string s;     cin >> s;     map<string, vector<int>> dp;     vector<string> ss = { abc ,  acb ,  bac ,  bca ,  cab ,  cba };     for (auto mask : ss) {       dp[mask] = vector<int>(n);       for (int i = 0; i < n; ++i) {         dp[mask][i] = (i > 0 ? dp[mask][i - 1] : 0) + (s[i] != mask[i % 3]);       }     }     while (m--) {       int l, r;       cin >> l >> r;       --r;       --l;       int minn = INF32;       for (auto mask : ss) {         minn = min(minn, dp[mask][r] - (l > 0 ? dp[mask][l - 1] : 0));       }       cout << minn << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int dx[] = {0, 1, 0, -1};   int dy[] = {1, 0, -1, 0};   int dp[1005][1005];   bool vis[1005][1005];   int sx, sy, x, y;   vector<string> v;   bool valid(int xx, int yy) {     if (xx >= 0 && yy >= 0 && xx < x && yy < y && v[xx][yy] !=  * ) return 1;     return 0;   }   int bfs() {     int wx, wy, ans = 0;     vector<pair<int, int> > vaa;     queue<pair<int, int> > q;     q.push(make_pair(sx, sy));     vis[sx][sy] = 1;     while (!q.empty()) {       sx = q.front().first;       sy = q.front().second;       vaa.push_back(make_pair(sx, sy));       q.pop();       for (int i = 0; i < 4; i++) {         wx = sx + dx[i];         wy = sy + dy[i];         if (!valid(wx, wy)) ans++;         if (valid(wx, wy) && !vis[wx][wy]) {           vis[wx][wy] = 1;           q.push(pair<int, int>(wx, wy));         }       }     }     for (int i = 0; i < vaa.size(); i++) dp[vaa[i].first][vaa[i].second] = ans;     return ans;   }   int main() {     memset(dp, -1, sizeof(dp));     for (int i = 0; i < 1005; i++)       for (int j = 0; j < 1005; j++) vis[i][j] = 0;     int t;     string s;     cin >> x >> y >> t;     for (int i = 0; i < x; i++) {       cin >> s;       v.push_back(s);     }     while (t--) {       cin >> sx >> sy;       sx--;       sy--;       if (dp[sx][sy] != -1)         printf( %d n , dp[sx][sy]);       else         printf( %d n , bfs());     }     return 0;   }