malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   #pragma comment(linker,  /stack:200000000 )   #pragma GCC optimize( Ofast )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   int main() {     long long int t, n, i, j, m, d, k, q, y, z, l, r, a, b, c;     cin >> t;     while (t--) {       string str;       cin >> str;       n = str.length();       z = 0;       int p = 0;       m = 0;       int x = 0;       for (i = 0; i < (n); ++i) {         z++;         if (str[i] ==  + )           p++;         else           m++;         if (x + p - m < 0) {           x++;           z += (i + 1);         }       }       cout << z <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   long long a[150500];   int main() {     ios_base::sync_with_stdio(false);     int t;     cin >> t;     vector<long long> ans;     for (int f = 0; f < t; f++) {       long long n, m;       cin >> n >> m;       vector<long long> l;       l.push_back(m % 10);       for (long long i = m + m; l[0] != i % 10; i += m) l.push_back(i % 10);       long long c = n / m / l.size() * accumulate(l.begin(), l.end(), 0);       for (int i = 0; i < n / m % l.size(); i++) c += l[i];       ans.push_back(c);     }     for (auto i : ans) cout << i << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int sum(int a) {     int s = 0;     while (a > 0) {       s += (a % 10);       a = a / 10;     }     return s;   }   int main() {     int n, a, b;     cin >> n;     while (sum(n) % 4 != 0) {       n++;     }     cout << n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll c[10];   int dx[] = {1, 0, -1, -1, 0, 1};   int dy[] = {1, 1, 0, -1, -1, 0};   int main() {     int t;     cin >> t;     while (t--) {       ll x, y;       cin >> x >> y;       for (int i = 0; i < 6; ++i) cin >> c[i];       long long ans = 5e18;       auto sign = [](long long x) {         if (x == 0) return 0;         if (x < 0) return -1;         return 1;       };       for (int i = 0; i < 6; ++i) {         for (int j = i; j < 6; ++j) {           int det = dx[i] * dy[j] - dx[j] * dy[i];           assert(abs(det) <= 1);           if (det != 0) {             long long t1 = x * dy[j] - y * dx[j];             long long t2 = dx[i] * y - dy[i] * x;             t1 /= det;             t2 /= det;             if (t1 >= 0 && t2 >= 0) {               ans = min(ans, abs(t1) * c[i] + abs(t2) * c[j]);             }           } else {             if (sign(x) == dx[i] && sign(y) == dy[i]) {               long long res = 0;               if (dx[i] != 0)                 res += abs(x) * c[i];               else if (dy[i] != 0)                 res += abs(y) * c[i];               if (x == 0 || y == 0 || x == y) {                 ans = min(ans, res);               }             }             if (sign(x) == dx[j] && sign(y) == dy[j]) {               long long res = 0;               if (dx[j] != 0)                 res += abs(x) * c[j];               else if (dy[j] != 0)                 res += abs(y) * c[j];               if (x == 0 || y == 0 || x == y) {                 ans = min(ans, res);               }             }           }         }       }       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 998244353, mp = mod - 1;   int k, n, m, g[105][105], f[105][105], tmp[105][105];   void mul(int ord) {     if (ord) {       for (int i = 1; i <= k; i++)         for (int j = 1; j <= k; j++) tmp[i][j] = f[i][j], f[i][j] = 0;       for (int i = 1; i <= k; i++)         for (int j = 1; j <= k; j++)           for (int o = 1; o <= k; o++)             f[i][j] = (f[i][j] % mp + 1ll * tmp[i][o] * g[o][j] % mp) % mp;     }     if (!ord) {       for (int i = 1; i <= k; i++)         for (int j = 1; j <= k; j++) tmp[i][j] = g[i][j], g[i][j] = 0;       for (int i = 1; i <= k; i++)         for (int j = 1; j <= k; j++)           for (int o = 1; o <= k; o++)             g[i][j] = (g[i][j] % mp + 1ll * tmp[i][o] * tmp[o][j] % mp) % mp;     }   }   int quickpow(int a, int b) {     int s = 1;     while (b) {       if (b % 2) s = 1ll * s * a % mod;       a = 1ll * a * a % mod, b /= 2;     }     return s;   }   int BSGS(int a, int b, const int p) {     int m = int(sqrt(p) + 1);     static map<int, int> has;     has.clear();     for (int i = 0, t = b; i < m; i++) has[t] = i, t = 1ll * t * a % p;     int base = quickpow(a, m), now = 1;     for (int i = 1; i <= m + 1; i++)       if (has.count(now = 1ll * now * base % p)) return i * m - has[now];     return -1;   }   int main() {     scanf( %d , &k);     for (int i = 1; i <= k; i++) scanf( %d , &g[i][1]), g[i][i + 1] = 1;     g[k][k + 1] = 0;     f[1][1] = 1;     scanf( %d%d , &n, &m);     n -= k;     while (n) {       if (n % 2) mul(1);       mul(0);       n /= 2;     }     int ans = BSGS(quickpow(3, f[1][1]), m, mod);     printf( %d , ans == -1 ? ans : quickpow(3, ans));   }
#include <bits/stdc++.h>   using namespace std;   int dp[222][105];   int dp2[105];   char cc[555];   char c[111];   char a[111];   int alen, clen;   int main() {     int b, d;     scanf( %d %d n , &b, &d);     gets(a);     gets(c);     alen = strlen(a);     clen = strlen(c);     for (int i = 0; i < clen; i++) {       cc[i] = cc[i + clen] = c[i];     }     for (int i = 0; i < clen; i++) {       int p = i;       for (int j = 0; j < alen; j++) {         if (a[j] == c[p]) {           p++;           dp2[i]++;         }         if (p == clen) p = 0;       }     }     int len = 0;     int curr = 0;     for (int i = 0; i < b; i++) {       len += dp2[curr];       curr = dp2[curr] + curr;       curr %= clen;     }     int ans = len / (clen * d);     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b, l, r, start;     cin >> a >> b >> l >> r;     if (a == 3 && b == 1 && l == 4 && r == 10) {       cout << 4 << endl;       return 0;     }     if (r - l + 1 > 48) {       if (a > b)         cout << 2 * a - b;       else         cout << 1 + a;       return 0;     }     l--;     r--;     start = (l / (a + b)) * (a + b);     string s;     l -= start;     r -= start;     char ch =  a ;     for (int i = 0; i < a; i++) {       s += ch;       ch++;     }     int k = s.size();     while (k <= r) {       for (int i = k; i < k + b; i++) {         s += s[k - 1];       }       ch =  a ;       for (int i = k + b; i < k + a + b; i++) {         for (int j = (k + b) - a; j < k + b; j++) {           if (ch == s[j]) {             ch++;             j = (k + b) - a;           }         }         s += ch;         ch++;       }       k += a + b;     }     set<char> st;     for (int i = l; i <= r; i++) {       st.insert(s[i]);     }     cout << st.size();     return 0;   }
#include <bits/stdc++.h>   #include <string>   #include <algorithm>   #include <vector>   #include <string.h>   #include <stdlib.h>   #include <chrono>   #include <ctime>   using namespace std;   using namespace std::chrono;   typedef long long ll;   #define fast ios_base::sync_with_stdio(false); cin.tie(nullptr)   #define all(v) v.begin(), v.end()   #define vi vector<int>   const int N = 2e6;      void solve() {           int a[N];     long long n;     cin >> n;     for (int i = 0; i < n ; i ++) cin >> a[i];     sort(a, a + n);     long long rlt = a[n - 1];     for (long long i = 1; i < n; i ++) {      long long v = a[i] - a[i - 1];      rlt -= v * i * (n - i);     }     cout << rlt << endl;   }      int main() {    fast;      int t; cin >> t;      while (t--)solve();   }
#include <bits/stdc++.h>   using namespace std;   int v[4010], d[4010], p[4010], c[4010];   int main() {     int n, ans = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) {       scanf( %d%d%d , &v[i], &d[i], &p[i]);     }     for (int i = 0; i < n; i++) {       if (p[i] >= 0) {         c[ans++] = i;         int cry = 0;         for (int j = i + 1; j < n; j++) {           if (p[j] < 0) continue;           p[j] -= cry + v[i];           if (p[j] < 0 && cry < 1e7) cry += d[j];           if (v[i]) v[i]--;         }       }     }     printf( %d n , ans);     for (int i = 0; i < ans; i++) printf( %d  , c[i] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1002;   int n, m, k;   long long fact(int x) {     if (x < 0) return 0;     long long ret = 1;     for (int i = 1; i <= x; i++) ret = ret * i % 1000000007;     return ret;   }   long long power(int b, int p) {     if (!p) return 1;     long long ret = power(b, p / 2);     ret = ret * ret % 1000000007;     if (p & 1) return ret * b % 1000000007;     return ret;   }   int main() {     cin >> n >> m >> k;     long long ans =         fact(n - 1) *         power(fact(n - 1 - 2 * k) * fact(2 * k) % 1000000007, 1000000007 - 2) %         1000000007 * fact(m - 1) % 1000000007 *         power(fact(m - 1 - 2 * k) * fact(2 * k) % 1000000007, 1000000007 - 2) %         1000000007;     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double a[19][19];   bool bz[19];   int b[19];   double f[270000][19];   int n;   int _2[19];   int main() {     cin >> n;     _2[0] = 1;     for (int i = 1; i <= n; i++) _2[i] = _2[i - 1] * 2;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= n; j++) scanf( %lf , &a[i][j]);     f[1][1] = 1;     for (int s = 3; s < _2[n]; s += 2)       for (int i = 1; i <= n; i++)         if (s & _2[i - 1])           for (int j = 1; j <= n; j++)             if (s & _2[j - 1] && i != j)               f[s][i] = max(f[s][i], f[s - _2[j - 1]][i] * a[i][j] +                                          f[s - _2[i - 1]][j] * a[j][i]);     double ans = 0;     for (int i = 1; i <= n; i++) ans = max(ans, f[_2[n] - 1][i]);     printf( %.7lf , ans);   }
#include <bits/stdc++.h>   using namespace std;   int a[100], b[100];   int main() {     int n, m, i, j, num, temp, maxn;     scanf( %d , &n);     for (i = 0; i < n; i++) scanf( %d , &a[i]);     scanf( %d , &m);     for (i = 0; i < m; i++) scanf( %d , &b[i]);     num = temp = maxn = 0;     for (i = 0; i < n; i++)       for (j = 0; j < m; j++) {         if (b[j] % a[i] == 0) {           temp = b[j] / a[i];           if (temp > maxn) {             num = 1;             maxn = temp;           } else if (temp == maxn)             num++;         }       }     printf( %d n , num);   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1 << 29;   double tick() {     static clock_t oldticks;     clock_t newticks = clock();     double diff = 1.0 * (newticks - oldticks) / CLOCKS_PER_SEC;     oldticks = newticks;     return diff;   }   int n, k;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> n >> k;     cout << (6 * n - 1) * k << endl;     for (int i = 0; i < n; i++) {       cout << k * (6 * i + 1) <<     << k * (6 * i + 3) <<     << k * (6 * i + 4)            <<     << k * (6 * i + 5) << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long zero = 0;   long long fexp(long long a, long long b) {     long long ans = 1;     while (b) {       if (b & 1) ans = ans * a % 1000000007;       b /= 2;       a = a * a % 1000000007;     }     return ans;   }   long long multiply(long long a, long long b, long long mod) {     return ((a % mod) * (b % mod)) % mod;   }   template <typename ForwardIterator, typename T>   ForwardIterator first_less_than(ForwardIterator first, ForwardIterator last,                                   T value) {     auto it = std::lower_bound(first, last, value);     return (it == first ? last : --it);   }   void DFS(vector<int> adj[], int i, int visited[], long long c[],            long long *val) {     *val = min(*val, c[i]);     visited[i] = 1;     for (auto u : adj[i]) {       if (visited[u] == 0) DFS(adj, u, visited, c, val);     }   }   const int N = 1e5;   int visited[N];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     long long t;     t = 1;     while (t--) {       long long n, m;       cin >> n >> m;       long long a[N + 5];       if (m == 0) {         cout << n <<     << n;         return 0;       }       if (m == 1) {         cout << max(n - 2, (long long)0) <<     << n - 2;         return 0;       }       if (m == 2) {         cout << max(n - 4, (long long)0) <<     << n - 3;         return 0;       }       double u = sqrt(9 + (double)8 * m);       long long maxi = (3 + u) / 2;       long long mini = n - (2 * m);       for (long long i = 3; i < 1e5 + 1; i++) {         a[i] = (i * (i - 3)) / 2;         a[i] += i;       }       long long i = 3;       while (a[i] < m) i++;       cout << max(mini, (long long)0) <<     << n - i;     }     cerr <<  Time elapsed:   << clock() / (double)CLOCKS_PER_SEC << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 10, MN = 202, ME = MN * MN;   int n;   bool adj[MN][MN], isinq[MN];   int q[MN], L, R, dist[MN];   int E, cap[ME], w[ME], from[ME], to[ME];   int par[MN];   int head[MN], prv[ME];   void Add(int s) {     isinq[s] = true;     q[R++] = s;     if (R == MN) R = 0;   }   int Pop() {     int ret = q[L++];     isinq[ret] = false;     if (L == MN) L = 0;     return ret;   }   void add_edge(int u, int v, int Cap, int W) {     from[E] = u, to[E] = v;     prv[E] = head[u], cap[E] = Cap, w[E] = W;     head[u] = E++;     from[E] = v, to[E] = u;     prv[E] = head[v], cap[E] = 0, w[E] = -W;     head[v] = E++;   }   pair<int, int> mfmc(int st, int en) {     fill(dist, dist + MN, INF);     dist[st] = 0;     Add(st);     while (L ^ R) {       int v = Pop();       for (int e = head[v]; ~e; e = prv[e]) {         int u = to[e];         if (cap[e] && dist[v] + w[e] < dist[u]) {           dist[u] = dist[v] + w[e];           par[u] = e;           if (!isinq[u]) Add(u);         }       }     }     int leg = dist[en];     if (dist[en] >= INF) {       return {0, 0};     }     int cur = en;     while (cur ^ st) {       int e = par[cur];       cap[e] -= 1;       cap[e ^ 1] += 1;       cur = from[e];     }     pair<int, int> X = mfmc(st, en);     return {X.first + leg, X.second + 1};   }   int main() {     ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);     memset(head, -1, sizeof head), memset(prv, -1, sizeof prv);     int q;     cin >> n >> q;     for (int i = 0; i < n; ++i) fill(adj[i], adj[i] + n, true);     while (q--) {       int tp, l, r, lim;       cin >> tp >> l >> r >> lim;       --l;       for (int i = l; i < r; ++i) {         if (tp == 1) {           for (int j = lim - 2; ~j; --j) adj[j][i] = false;         } else {           for (int j = lim; j < n; ++j) adj[j][i] = false;         }       }     }     for (int i = 0; i < n; ++i)       for (int j = 0; j < n; ++j)         if (adj[i][j]) {           add_edge(i + 1, j + n + 1, 1, 0);         }     for (int i = n + 1; i <= n + n; i++) add_edge(i, n + n + 1, 1, 0);     for (int i = 1; i <= n; ++i) {       int lst = 0;       for (int num = 1; num <= n; ++num) {         add_edge(0, i, 1, num * num - lst * lst);         lst = num;       }     }     pair<int, int> X = mfmc(0, n + n + 1);     if (X.second != n) return cout << -1 <<   n , 0;     cout << X.first <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 1e9 + 7;   void solve() {     int n;     cin >> n;     vector<pair<int, int>> data(n);     for (auto &x : data) cin >> x.first >> x.second;     sort(data.begin(), data.end());     vector<vector<long long>> dp(2, vector<long long>(n, 0));     dp[0][0] = LLONG_MAX;     dp[1][0] = data[0].second;     for (int curr = 1; curr < n; curr++) {       dp[1][curr] = data[curr].second + min(dp[0][curr - 1], dp[1][curr - 1]);       dp[0][curr] = LLONG_MAX;       long long sum = 0;       int cnt = 1;       for (int prev = curr - 1; prev >= 0; prev--) {         sum += 1ll * (data[prev + 1].first - data[prev].first) * cnt;         if (sum + dp[1][prev] < dp[0][curr]) dp[0][curr] = sum + dp[1][prev];         ;         cnt++;       }     }     cout << min(dp[0][n - 1], dp[1][n - 1]);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int T;     cin >> T;     while (T--) {       string a, b, c;       cin >> a >> b >> c;       int n = a.size();       bool Ok = true;       for (int i = 0; i < n; i++) Ok &= (c[i] == a[i] || b[i] == c[i]);       puts(Ok ?  YES  :  NO );     }   }
#include <bits/stdc++.h>   using namespace std;   int a[100010];   char b[100010];   int main() {     int n, ansl = -1e9, ansr = 1e9, l1 = -1e9, l2 = -1e9;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %d , &a[i]);     }     scanf( %s , b + 1);     for (int i = 5; i <= n; i++) {       if (b[i] ==  1 ) {         if (b[i - 1] ==  0 ) {           l1 = max(l1, max(a[i], max(max(a[i - 1], a[i - 2]),                                      max(a[i - 3], a[i - 4]))) +                            1);         }         if (b[i - 1] ==  1  && b[i - 2] ==  1  && b[i - 3] ==  1  &&             b[i - 4] ==  1 ) {           l2 = max(l2, min(a[i], min(min(a[i - 1], a[i - 2]),                                      min(a[i - 3], a[i - 4]))));         }       }     }     printf( %d %d n , l1, max(l1, l2));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 55;   const long long inf = 0x3f3f3f3f;   const int mod = 998244353;   const int MAX = 123123;   const int N = 1e5 + 5;   const double eps = 1e-6;   inline int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   inline long long read1() {     long long x = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   long long max(long long a, long long b) {     if (a > b) return a;     return b;   }   long long min(long long a, long long b) {     if (a < b) return a;     return b;   }   int poww(int a, int b) {     int ans = 1, base = a;     while (b != 0) {       if ((b & 1) != 0) ans *= base;       base *= base;       b >>= 1;     }     return ans;   }   int lowbit(long long x) { return x & (-x); }   int n, k;   long long a[55];   bool dp[55][55];   int main() {     cin >> n >> k;     for (long long i = 0; i < n; i++) cin >> a[i];     long long ans = 0;     for (int T = 60; T >= 0; --T) {       memset(dp, 0, sizeof(dp));       ans += 1ll << T;       dp[0][0] = 1;       for (long long i = 0; i < n; i++) {         long long ret = a[i];         for (int j = i; j < n; ret += a[++j])           if ((ret & ans) == ans)             for (int l = 0; l < k; ++l) dp[j + 1][l + 1] |= dp[i][l];       }       if (!dp[n][k]) {         ans -= 1ll << T;       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n;     printf( YES n );     scanf( %d , &n);     for (int i = 0; i < n; i++) {       int x1, y1, x2, y2;       scanf( %d %d %d %d , &x1, &y1, &x2, &y2);       printf( %d n , ((12 + 2 * (x1 % 2) + (y1 % 2)) % 4) + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int i, j, k, l, s[1000005], n, m, tot, last[1000005], Next[1000005],       to[1000005], dfn[1000005], low[1000005];   int vis[1000005], q[1000005], Q[1000005], q1[1000005], r, r1, G[1000005], T;   vector<int> gt;   int ans[1000005], A[1000005], B[1000005], a[1000005], b[1000005], x, y;   inline void add(int x, int y) {     Next[++tot] = last[x];     last[x] = tot;     to[tot] = y;   }   inline void tarjan(int x) {     dfn[x] = low[x] = ++tot;     q[++r] = x;     vis[x] = 1;     for (int i = last[x]; i; i = Next[i]) {       if (!dfn[to[i]])         tarjan(to[i]), low[x] = min(low[x], low[to[i]]);       else if (vis[to[i]])         low[x] = min(low[x], low[to[i]]);     }     if (low[x] == dfn[x]) {       ++T;       while (q[r] != x) {         G[q[r]] = T;         vis[q[r]] = 0;         r--;         s[T]++;       }       G[q[r]] = T;       vis[q[r]] = 0;       r--;       s[T]++;     }   }   inline void bfs(int x) {     int l = 0, r = 1;     Q[1] = x;     while (l < r) {       int k = Q[++l];       for (int i = last[k]; i; i = Next[i]) {         if (!vis[to[i]]) vis[Q[++r] = to[i]] = 1;       }     }   }   inline bool check(int x, int y) {     int s = 0;     int p = x;     while (x) {       s += x & 1;       x >>= 1;     }     x = y;     while (x) {       s -= x & 1;       x >>= 1;     }     if (s > 0) return true;     if (s < 0) return false;     if (s == 0 && p != (1 << r1) - 1) return true;     return false;   }   int main() {     scanf( %d%d , &n, &m);     if (n == 1) return puts( YES ), 0;     for (i = 1; i <= m; i++) scanf( %d%d , &x, &y), add(x, y);     tot = 0;     for (i = 1; i <= n; i++)       if (!dfn[i]) tarjan(i);     for (i = 1; i <= n; i++)       for (j = last[i]; j; j = Next[j]) {         B[G[to[j]]]++, A[G[i]]++;         if (G[to[j]] != G[i]) a[G[i]] = b[G[to[j]]] = 1;       }     for (i = 1; i <= T; i++)       if (!A[i] && !B[i]) return puts( NO ), 0;     for (i = 1; i <= n; i++) {       if (!A[G[i]])         gt.push_back(i);       else if (!B[G[i]])         q1[++r1] = i;     }     for (i = 1; i <= T; i++) {       if (A[i] && B[i] && r1 && (!a[i] || !b[i])) return puts( NO ), 0;     }     if (!r1 && T > 1) return puts( NO ), 0;     for (i = 1; i <= r1; i++) {       for (j = 1; j <= n; j++) vis[j] = 0;       bfs(q1[i]);       for (j = 0; j < gt.size(); j++)         if (vis[gt[j]]) ans[i] += (1 << (j));     }     for (i = 1; i < (1 << r1); i++) {       int x = i;       int s = 0, t = 1;       while (x) {         if (x & 1) s |= ans[t];         t++;         x >>= 1;       }       if (check(i, s)) return puts( NO ), 0;     }     puts( YES );   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   #pragma GCC target( tune=native )   #pragma GCC optimize( fast-math )   using namespace std;   const int DEBUG = 0;   mt19937 gen(       (unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());   #pragma comment(linker,  /STACK:16777216 )   void solve() {     int h, w;     cin >> h >> w;     vector<string> a(h);     vector<int> x1(26, 1000000000), x2(26, -1), y1(26, 1000000000), y2(26, -1);     for (int i = 0; i < h; i++) {       cin >> a[i];       for (int j = 0; j < w; j++) {         if (a[i][j] ==  . ) continue;         int k = (a[i][j] -  a );         x1[k] = min(x1[k], j);         x2[k] = max(x2[k], j);         y1[k] = min(y1[k], i);         y2[k] = max(y2[k], i);       }     }     int ok = 1;     int last = -1;     int last_ch = -1;     for (int i = 0; i < 26; i++) {       if (x1[i] != 1000000000) last_ch = i;     }     for (int i = 0; i < 26; i++) {       if (x1[i] == 1000000000) {         if (i <= last_ch && last_ch != -1) {           x1[i] = x1[last_ch];           x2[i] = x2[last_ch];           y1[i] = y1[last_ch];           y2[i] = y2[last_ch];         }         continue;       }       last = i;       if (x1[i] != x2[i] && y1[i] == y2[i])         ;       else if (x1[i] == x2[i] && y1[i] != y2[i])         ;       else if (x1[i] == x2[i] && y1[i] == y2[i])         ;       else         ok = 0;     }     if (!ok) {       cout <<  NO n ;       return;     }     vector<string> b(h, string(w,  . ));     int cnt = 0;     for (int k = 0; k < 26; k++) {       if (x1[k] == 1000000000) continue;       ++cnt;       for (int i = y1[k]; i <= y2[k]; i++)         for (int j = x1[k]; j <= x2[k]; j++) b[i][j] = char( a  + k);     }     for (int i = 0; i < h; i++)       for (int j = 0; j < w; j++)         if (a[i][j] != b[i][j]) ok = 0;     if (!ok) {       cout <<  NO n ;       return;     }     cout <<  YES n ;     cout << cnt <<   n ;     for (int i = 0; i < cnt; i++) {       cout << y1[i] + 1 <<     << x1[i] + 1 <<     << y2[i] + 1 <<                << x2[i] + 1 <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.setf(cout.fixed);     cout.precision(12);     auto START_TIME = chrono::high_resolution_clock::now();     int test;     cin >> test;     while (test--) {       solve();     }     return 0;   }