malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, k;     cin >> n >> k;     vector<int> a(n + 1);     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     int u = 0, v = 1;     vector<vector<double>> d[2];     d[u].assign(n + 1, vector<double>(n + 1));     for (int i = 1; i <= n; ++i) {       for (int j = i + 1; j <= n; ++j) {         if (a[i] < a[j]) {           d[u][i][j] = 1.0;         } else {           d[u][j][i] = 1.0;         }       }     }     double p = 2.0 / (n * (n + 1));     for (; k--; swap(u, v)) {       d[v].assign(n + 1, vector<double>(n + 1));       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= n; ++j) {           if (i == j) {             continue;           }           for (int x = 1; x <= n; ++x) {             for (int y = x; y <= n; ++y) {               int ni = i;               if (x <= i && i <= y) {                 ni = x + y - i;               }               int nj = j;               if (x <= j && j <= y) {                 nj = x + y - j;               }               d[v][ni][nj] += d[u][i][j] * p;             }           }         }       }     }     double ans = 0.0;     for (int i = 1; i <= n; ++i) {       for (int j = 1; j < i; ++j) {         ans += d[u][i][j];       }     }     cout << ans << endl;   }   void init() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(10);   }   int main() {     init();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f(int, int);   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     int a[m + 1];     int c[m];     int b = 0;     for (int i = 0; i < m; i++) {       c[i] = 0;     }     for (int i = 0; i <= m; i++) {       cin >> a[i];     }     for (int i = 0; i < m; i++) {       for (int j = 1; j <= n; j++) {         if (f(a[i], j) != f(a[m], j)) c[i]++;       }       if (c[i] <= k) b++;     }     cout << b;     return (0);   }   int f(int q, int w) {     int e = q;     for (int i = 1; i < w; i++) {       e = e / 2;     }     return (e % 2);   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   ostream& operator<<(ostream& s, vector<T> t) {     for (int i = 0; i < (int)(t.size()); i++) s << (i ?     :   ) << t[i];     return s;   }   template <typename T>   istream& operator>>(istream& s, vector<T>& t) {     for (int i = 0; i < (int)(t.size()); i++) s >> t[i];     return s;   }   template <typename T, typename U>   ostream& operator<<(ostream& s, pair<T, U> t) {     s <<  (  << t.first <<  ,  << t.second <<  ) ;     return s;   }   template <typename T, typename U>   istream& operator>>(istream& s, pair<T, U>& t) {     s >> t.first >> t.second;     return s;   }   typedef pair<double, double> it;   const double EPS = 1e-15;   it intersect(it a, it b) {     if (a.first == -1 || b.first == -1) return {-1, -1};     it res = {max(a.first, b.first), min(a.second, b.second)};     if (res.first + EPS >= res.second) return {-1, -1};     return res;   }   it get1D(double r, double v, double x1, double x2) {     if (v == 0) {       if (r > x1 && r < x2)         return {0, 1e18};       else         return {-1, -1};     }     double t1 = (x1 - r) / v, t2 = (x2 - r) / v;     if (t2 < t1) swap(t1, t2);     if (t2 < 0) return {-1, -1};     if (t1 < 0) t1 = 0;     return {t1, t2};   }   int main() {     ios_base::sync_with_stdio(false);     int n;     cin >> n;     double x1, y1, x2, y2;     cin >> x1 >> y1 >> x2 >> y2;     it res = {0, 1e18};     for (int i = 0; i < (int)(n); i++) {       double rx, ry, vx, vy;       cin >> rx >> ry >> vx >> vy;       it xi = get1D(rx, vx, x1, x2);       it yi = get1D(ry, vy, y1, y2);       it cur = intersect(xi, yi);       res = intersect(res, cur);     }     cout << fixed << setprecision(9);     if (res.first == -1) {       cout <<  -1  << endl;     } else {       cout << res.first << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   void _print(long long int x) { cerr << x <<    ; }   void _print(float x) { cerr << x <<    ; }   void _print(double x) { cerr << x <<    ; }   void _print(char x) { cerr << x <<    ; }   void _print(string x) { cerr << x <<    ; }   void _print(bool x) { cerr << x <<    ; }   template <class T, class V>   void _print(pair<T, V> x) {     cerr <<  { ;     _print(x.first);     cerr <<  , ;     _print(x.second);     cerr <<  } ;   }   template <class T>   void _print(vector<T> x) {     cerr <<  [  ;     for (T i : x) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(set<T> x) {     cerr <<  [  ;     for (T i : x) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T>   void _print(multiset<T> x) {     cerr <<  [  ;     for (T i : x) {       _print(i);       cerr <<    ;     }     cerr <<  ] ;   }   template <class T, class V>   void _print(map<T, V> x) {     cerr <<  [  ;     for (auto i : x) {       _print(i);       cerr <<    ;     }     cerr <<   ] ;   }   void solve() {     string s;     cin >> s;     long long int n = s.size();     if (n % 2 == 1) {       cout <<  NO  << endl;       return;     }     for (long long int i = 0; i <= (n / 2) - 1; i++) {       if (s[i] != s[i + (n / 2)]) {         cout <<  NO  << endl;         return;       }     }     cout <<  YES  << endl;   }   signed main() {     ios_base ::sync_with_stdio(false);     cin.tie(NULL);     clock_t start, end;     start = clock();     long long int t;     cin >> t;     while (t--) {       solve();     }     end = clock();     double time_taken = double(end - start) / double(CLOCKS_PER_SEC);     cerr <<  Time taken by program is :   << fixed << time_taken          << setprecision(5);     cerr <<   sec   << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e5 + 5;   char s[maxn];   int vis[maxn];   pair<char, int> sta[maxn];   int main() {     scanf( %s , s);     int o = -1;     for (int i = 0; s[i]; i++) {       if (s[i] ==  0  && o >= 0 && sta[o].first ==  1 ) {         vis[sta[o].second] = 1;         o--;       } else         sta[++o] = make_pair(s[i], i);     }     for (int i = 0; s[i]; i++) printf( %d , vis[i]);   }
#include <bits/stdc++.h>   using namespace std;   vector<long long int> prime;   unordered_set<long long int> stprime;   void sieve(long long int n) {     bool p[n + 1];     memset(p, true, sizeof(p));     for (long long int i = 2; i * i <= n; i++) {       if (p[i]) {         for (int j = i * i; j <= n; j += i) {           p[j] = false;         }       }     }     for (long long int i = 2; i <= n; i++) {       if (p[i]) {         prime.push_back(i);         stprime.insert(i);       }     }   }   void solve() {     long long int m;     cin >> m;     long long int arr[8];     memset(arr, 0, sizeof(arr));     for (int i = 0; i < m; i++) {       long long int a;       cin >> a;       arr[a]++;     }     m /= 3;     if (arr[1] != m || arr[5] | arr[7] || arr[2] < arr[4] || arr[6] < arr[3] ||         arr[2] + arr[3] != arr[4] + arr[6]) {       cout <<  -1  << endl;     } else {       for (int i = 1; i <= arr[4]; i++) cout <<  1 2 4  << endl;       for (int i = 1; i <= arr[2] - arr[4]; i++) cout <<  1 2 6  << endl;       for (int i = 1; i <= arr[3]; i++) cout <<  1 3 6  << endl;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int frd[2110][2110], rev[2110][2110];   vector<int> v;   int main() {     int a, b, c, d, e, i, j, p, q, mx, mx1, len;     string x, y;     cin >> x >> y;     a = x.length();     b = y.length();     x =  %  + x;     y =  *  + y;     for (i = b; i >= 1; i--) {       for (j = a; j >= 1; j--) {         if (y[i] == x[j]) {           frd[i][j] = frd[i + 1][j + 1] + 1;         }       }       for (j = 1; j <= a; j++) {         if (y[i] == x[j]) {           rev[i][j] = rev[i + 1][j - 1] + 1;         }       }     }     for (i = 1; i <= b;) {       p = -1;       q = -1;       mx = -1;       mx1 = -1;       for (j = 1; j <= a; j++) {         if (frd[i][j] > mx) {           mx = frd[i][j];           p = j;         }       }       for (j = 1; j <= a; j++) {         if (rev[i][j] > mx1) {           mx1 = rev[i][j];           q = j;         }       }       len = max(mx, mx1);       if (len == 0) {         cout <<  -1  << endl;         return 0;       }       if (len == mx) {         v.push_back(p);         v.push_back(p + len - 1);       } else {         v.push_back(q);         v.push_back(q - len + 1);       }       i = i + len;     }     cout << v.size() / 2 << endl;     e = v.size();     for (i = 0; i < e; i = i + 2) {       cout << v[i] <<     << v[i + 1] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[1000000];   int main() {     int n, x, counter = 0;     cin >> n >> x;     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     sort(arr, arr + n);     while (arr[((n + 1) / 2 - 1)] != x) {       arr[n++] = x;       sort(arr, arr + n);       counter++;     }     cout << counter;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MX = 305;   vector<int> adj[MX];   vector<int> l, ans;   int dfs(int u, int v, vector<int>& p, int par = 0) {     int sum = 0;     for (int w : adj[u]) {       if (w != par) {         p.push_back(w);         sum = max(sum, dfs(w, v, p, u));         p.pop_back();       }     }     if (u == v) {       for (int i : p) ans.push_back(i);       return p.size();     }     return sum;   }   int main() {     int n, k = 0;     cin >> n;     for (int i = 1; i < n; i++) {       int u, v;       cin >> u >> v;       adj[u].push_back(v);       adj[v].push_back(u);     }     for (int i = 2; i <= n; i++)       if (adj[i].size() == 1) k++;     for (int i = 0; i < k; i++) {       int u;       cin >> u;       l.push_back(u);     }     l.push_back(1);     vector<int> vec[k + 1];     int sum = 0;     int u = 1;     for (int i = 0; i <= k; i++) {       sum += dfs(u, l[i], vec[i], u);       u = l[i];     }     if (sum != 2 * n - 2)       cout <<  -1  <<   n ;     else {       cout <<  1  <<    ;       for (int i : ans) cout << i <<    ;     }   }
#include <bits/stdc++.h>   int main() {     int n, m;     scanf( %d %d , &n, &m);     char a[1005][1005];     for (int k = 0; k < n; k++) {       scanf( %s , a[k]);     }     char b[1005][1005] = {0};     for (int x = 1; x < n - 1; x++) {       for (int y = 1; y < m - 1; y++) {         if (a[x - 1][y] ==  #  && a[x - 1][y - 1] ==  #  &&             a[x - 1][y + 1] ==  # ) {           if (a[x][y + 1] ==  #  && a[x][y - 1] ==  #  &&               a[x + 1][y - 1] ==  #  && a[x + 1][y] ==  #  &&               a[x + 1][y + 1] ==  # )             b[x][y] =  2 ;         }       }     }     for (int x = 1; x < n - 1; x++) {       for (int y = 1; y < m - 1; y++) {         if (b[x][y] ==  2 ) {           a[x - 1][y] =  . ;           a[x - 1][y - 1] =  . ;           a[x - 1][y + 1] =  . ;           a[x][y - 1] =  . ;           a[x][y + 1] =  . ;           a[x + 1][y] =  . ;           a[x + 1][y - 1] =  . ;           a[x + 1][y + 1] =  . ;         }       }     }     int book = 1;     for (int k = 0; k < n; k++) {       for (int y = 0; y < m; y++) {         if (a[k][y] ==  # ) book = 0;         if (book == 0) break;       }     }     if (book == 1)       printf( YES );     else       printf( NO );   }
#include <bits/stdc++.h>   using namespace std;   int t[110], w[110];   int main() {     int n, cnt = 0;     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d%d , &t[i], &w[i]);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         if (i != j) {           if (t[i] == w[j]) {             cnt++;             break;           }         }       }     }     printf( %d , n - cnt);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   void rd(T& ret) {     ret = 0;     bool ok = 0, u = 0;     for (;;) {       int c = getchar();       if (c >=  0  && c <=  9 )         ret = (ret << 3) + (ret << 1) + c -  0 , ok = 1;       else if (c ==  - )         u = 1;       else if (ok) {         if (u) ret *= -1;         return;       }     }   }   long long powmod(long long p, long long n, long long mod) {     long long ret = 1;     for (; n; n >>= 1) {       if (n & 1) ret = ret * p % mod;       p = p * p % mod;     }     return ret;   }   template <class T>   bool chmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool chmax(T& a, const T& b) {     return b > a ? a = b, 1 : 0;   }   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   const long long mod = (long long)1e9 + 7;   const int N = 1 << 21;   pair<pair<int, int>, int> qn[N];   int stk[N], top, an[N], ans[N];   bool has[N];   int main() {     int n, q;     scanf( %d%d , &n, &q);     for (int i = (0); i < (n); i++) scanf( %d , an + i);     for (int i = (0); i < (q); i++) {       int l, first;       scanf( %d%d , &l, &first);       --l;       qn[i].first = pair<int, int>(l, first);       qn[i].second = i;     }     sort(qn, qn + q);     has[0] = 1;     stk[top++] = 0;     long long t = 1, it = 0;     for (int i = (0); i < (n); i++) {       if (has[an[i]])         t = (t << 1) % mod;       else {         int tn = top, second;         for (int j = (0); j < (tn); j++) {           second = an[i] ^ stk[j];           stk[top++] = second;           has[second] = 1;         }         has[an[i]] = 1;         stk[top++] = an[i];       }       while (it < q && qn[it].first.first == i) {         int val = qn[it].first.second;         ans[qn[it].second] = has[val] ? t : 0;         ++it;       }     }     for (int i = (0); i < (q); i++) printf( %d n , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 1000000007;   const long long MAX = 100005;   const long double PI = 3.14159265359;   const long double G = 9.807;   const long long INF = 1e18;   const long double EPS = 1e-6;   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   bool isprime(long long a) {     if (a == 2) return 1;     if (!(a & 1)) return 0;     for (long long i = 3; i * i <= a; i += 2)       if (a % i == 0) return 0;     return 1;   }   long long mpow(long long base, long long exponent, long long modulus) {     if (modulus == 1) return 0;     long long result = 1;     base = base % modulus;     while (exponent) {       if (exponent % 2 == 1) result = (result * base) % modulus;       exponent = exponent >> 1;       base = (base * base) % modulus;     }     return result;   }   long long minv(long long a, long long mod) {     long long _gcd = gcd(a, mod);     assert(_gcd == 1);     return mpow(a, mod - 2, mod);   }   long long n;   long long ans;   long long a[1005];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int i = 2; i < n; ++i) {       if (a[i - 1] > a[i] and a[i] < a[i + 1])         ans++;       else if (a[i - 1] < a[i] and a[i] > a[i + 1])         ans++;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native )   using namespace std;   const int maxn = 3e5 + 10, lg = 20;   vector<pair<long long, long long> > v[maxn];   long long n, w[maxn], rmq[lg + 2][maxn], dp[maxn], up[maxn], W[maxn],       par[lg + 2][maxn], h[maxn], q;   void dfs_down(int i, int j) {     h[i] = h[j] + 1;     dp[i] = w[i];     for (int y = 0; y < v[i].size(); y++) {       int x = v[i][y].first;       if (x - j) {         W[x] = v[i][y].second;         dfs_down(x, i);         dp[i] += max(0LL, dp[x] - 2 * W[x]);       }     }   }   long long get_dp(int pes) {     long long s = 0;     if (dp[pes] - 2 * W[pes] >= 0 && pes != 1) s = -(dp[pes] - 2 * W[pes]);     return s;   }   void dfs_up(int i, int j) {     if (i != 1) {       up[i] = max(0LL, up[j] + dp[j] + get_dp(i) - 2 * W[i]);     }     for (int y = 0; y < v[i].size(); y++) {       int x = v[i][y].first;       if (x - j) {         dfs_up(x, i);       }     }   }   void get_par(int i, int j) {     par[0][i] = j;     rmq[0][i] = -W[i] + dp[j] + get_dp(i);     for (int y = 1; y <= lg; y++) {       int p = par[y - 1][i];       par[y][i] = par[y - 1][p];       rmq[y][i] = rmq[y - 1][i] + rmq[y - 1][p];     }     for (int y = 0; y < v[i].size(); y++) {       int x = v[i][y].first;       if (x - j) {         get_par(x, i);       }     }   }   long long query(int i, int j) {     if (i == j) return up[i] + dp[i];     if (h[i] > h[j]) swap(i, j);     int o = h[j] - h[i];     int I = i;     int J = j;     long long Ans = 0;     for (int y = 0; y <= lg; y++) {       if (o & (1 << y)) {         Ans += rmq[y][j];         j = par[y][j];       }     }     if (j == i) return Ans + dp[J] + up[i];     Ans += dp[I] + dp[J];     for (int y = lg; y > -1; y--) {       if (par[y][i] != par[y][j])         Ans += rmq[y][j] + rmq[y][i], i = par[y][i], j = par[y][j];     }     int p = par[0][j];     Ans += up[p] + rmq[0][i] + rmq[0][j] + get_dp(i) + get_dp(j) -            (dp[p] + get_dp(i) + get_dp(j));     return Ans;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> q;     for (int y = 1; y <= n; y++) cin >> w[y];     for (int y = 1; y < n; y++) {       int i, j, p;       cin >> i >> j >> p;       v[i].push_back(pair<long long, long long>(j, p));       v[j].push_back(pair<long long, long long>(i, p));     }     dfs_down(1, 0);     dfs_up(1, 0);     get_par(1, 0);     while (q--) {       int i, j;       cin >> i >> j;       cout << query(i, j) << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   #pragma comment(linker,  /STACK:100000000 )   int mod = 1000000007;   int mas[1010];   int pow2(int b) {     if (b == -1) return 0;     int res = 1;     for (int i = 1; i <= b; i++) {       res <<= 1;       res %= mod;     }     return res;   }   int GCD(int a, int b) {     if (b == 0)       return a;     else       return GCD(b, a % b);   }   vector<int> v;   vector<int> C;   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < m; i++) scanf( %d , &mas[i]);     sort(mas, mas + m);     if (mas[0] != 1) v.push_back(mas[0] - 1);     if ((n > 1 || m != 1) && mas[m - 1] != n) v.push_back(n - mas[m - 1]);     for (int i = 1; i < m; i++) {       int a = pow2(mas[i] - mas[i - 1] - 2);       if (mas[i] - 1 != mas[i - 1]) v.push_back(mas[i] - mas[i - 1] - 1);       a = max(a, 1);       C.push_back(a);     }     sort(v.begin(), v.end());     int S = 0;     vector<int> F;     for (int i = 0, maxi = (int)(v).size(); i < maxi; i++) S += v[i];     for (int i = 2; i <= S; i++) F.push_back(i);     vector<int> VVV;     for (int i = 0, maxi = (int)(v).size(); i < maxi; i++)       for (int j = 2; j <= v[i]; j++) VVV.push_back(j);     for (int i = 0, maxi = (int)(VVV).size(); i < maxi; i++) {       for (int j = 0, maxj = (int)(F).size(); j < maxj; j++) {         if (VVV[i] == 1) break;         int G = GCD(F[j], VVV[i]);         VVV[i] /= G;         F[j] /= G;       }     }     long long ans = 1;     for (int i = 0, maxi = (int)(F).size(); i < maxi; i++)       ans *= (long long)F[i], ans %= (long long)mod;     for (int i = 0, maxi = (int)(C).size(); i < maxi; i++)       ans *= (long long)C[i], ans %= (long long)mod;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     cin >> t;     int a[1000]{};     for (int i = 0; i < t; i++) {       int n, s, k;       cin >> n >> s >> k;       set<int> b;       for (int j = 0; j < k; j++) {         cin >> a[j];         b.insert(a[j]);       }       int ans = n;       for (int i = max(1, s - k); i <= min(n, s + k + 1); i++) {         if (b.count(i) == 0) {           ans = min(ans, abs(s - i));         }       }       cout << ans <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   using namespace std;   const double PI = acos(-1.0);   const long long MOD = 1000000007LL;   template <class T>   inline bool chmax(T &a, T b) {     if (a < b) {       a = b;       return true;     }     return false;   }   template <class T>   inline bool chmin(T &a, T b) {     if (a > b) {       a = b;       return true;     }     return false;   }   int dp[500][500];   void solve() {     string S, T;     cin >> S >> T;     int N = S.size();     int M = T.size();     for (int i = 0; i < (int)(M); ++i) {       for (int j = 0; j < (int)(N + 1); ++j)         for (int k = 0; k < (int)(M + 1); ++k) dp[j][k] = -1;       for (int j = 0; j < (int)(N + 1); ++j) dp[j][0] = 0;       for (int j = 0; j < (int)(N); ++j) {         for (int k = 0; k < (int)(i + 1); ++k) {           chmax(dp[j + 1][k], dp[j][k]);           if (k < i && S[j] == T[k]) {             chmax(dp[j + 1][k + 1], dp[j][k]);           }           if (dp[j][k] >= 0 && dp[j][k] < M - i && S[j] == T[i + dp[j][k]]) {             chmax(dp[j + 1][k], dp[j][k] + 1);           }         }       }       if (dp[N][i] == M - i) {         cout <<  YES  <<   n ;         return;       }     }     cout <<  NO  <<   n ;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(nullptr);     int Q;     cin >> Q;     while (Q--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   int t, n;   int hmz, hmbz, bsz = -100000, sum;   int main() {     cin >> t;     for (; t; t--) {       cin >> n;       hmz = 0;       hmbz = 0;       bsz = -100000;       sum = 0;       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         if (x == 0)           hmz++;         else if (x < 0)           bsz = max(bsz, x);         else           hmbz++;         sum += x;       }       int sol = 0;       if (hmz) sum += hmz, sol += hmz;       if (sum == 0) {         if (hmbz)           sol++;         else           sol += (1 - hmbz);       }       cout << sol <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e3 + 5;   int times[maxn][maxn], Time, cost[maxn][maxn], n, m;   string k[maxn];   int dfs(int x, int y) {     if (!min(x, y) or x > n or y > m) return 0;     times[x][y] = ++Time;     int now = k[x][y - 1];     int nextx, nexty;     if (now ==  R )       nextx = x, nexty = y + 1;     else if (now ==  L )       nextx = x, nexty = y - 1;     else if (now ==  U )       nextx = x - 1, nexty = y;     else       nextx = x + 1, nexty = y;     if (times[nextx][nexty]) {       cost[x][y] = Time - times[nextx][nexty] + 1;       times[x][y] = 0;       return cost[x][y] - 1;     }     if (cost[nextx][nexty]) {       cost[x][y] = cost[nextx][nexty] + 1;       times[x][y] = 0;       return 0;     }     int gg = dfs(nextx, nexty);     if (!gg) {       cost[x][y] = cost[nextx][nexty] + 1;       times[x][y] = 0;       return 0;     } else {       cost[x][y] = cost[nextx][nexty];       times[x][y] = 0;       return gg - 1;     }   }   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> k[i];     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         Time = 0;         if (!cost[i][j]) dfs(i, j);       }     }     int ans = 0, ansx, ansy;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++)         if (cost[i][j] > ans) ans = cost[i][j], ansx = i, ansy = j;     cout << ansx <<     << ansy <<     << ans <<   n ;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) cost[i][j] = times[i][j] = 0;   }   int main() {     ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);     int t;     cin >> t;     for (int i = 1; i <= t; i++) solve();     return 0;   }