malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   // #include <ext/pb_ds/assoc_container.hpp>   // #include <ext/pb_ds/tree_policy.hpp>   using namespace std;   // using namespace __gnu_pbds;   #define lli long long int   #define llu unsigned long long int   #define pb push_back   #define rt return 0   #define endln   n    #define all(x) x.begin(), x.end()   #define sz(x) (lli)(x.size())   #define len(x) (lli)(x.length())   const lli MOD = 1e9 + 7;   const double PI = 2 * acos(0.0);   // cout << fixed << setprecision(0) << pi <<endl;   // typedef tree<int, null_type, less<int>, rb_tree_tag,   //              tree_order_statistics_node_update>   //     new_data_set;   // for multiset   // typedef tree<int, null_type, less_equal<int>, rb_tree_tag,   //              tree_order_statistics_node_update>   //     new_data_set;   // order_of_key(val): returns the number of values less than val   // find_by_order(k): returns an iterator to the kth largest element (0-based)      void solve() {       lli n, a;       cin >> n;       vector<lli> v;       for (lli i = 0; i < n; i++) {           cin >> a;           v.pb(a);       }          for (lli i = 0; i < n; i++) {           lli tmp = v[i], ind = 0, one;           while (tmp > 0) {               if (tmp % 2 == 1) {                   one = ind;               }               tmp /= 2;               ind++;           }              lli p = pow(2, one);           cout << p <<    ;       }       cout << endl;   }      int main(void) {       ios::sync_with_stdio(0);       cin.tie(0);       cout.tie(0);       lli t;       cin >> t;       while (t--)           solve();       rt;   }
#include <bits/stdc++.h>   using namespace std;   const int Max_N = 1E6 + 10;   int n, m, ans = 1, p[Max_N], color[Max_N];   vector<int> chil[Max_N];   bool mark[Max_N];   int dfs(int i) {     int res = 0;     mark[i] = true;     for (int u : chil[i])       if (!mark[u] && color[i] != color[u]) ++res;     return res;   }   int main() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> p[i];       p[i]--;       chil[p[i]].push_back(i);     }     for (int i = 0; i < n; i++) cin >> color[i];     for (int i = 0; i < n; i++)       if (!mark[i]) ans += dfs(i);     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1010;   const int MAXK = 1000010;   int n, m, k, p, a[N][N], row[N], col[N];   long long ans1[MAXK], ans2[MAXK];   multiset<long long> Unis;   void solve(long long *ans, int n, int *a, int dta) {     Unis.clear();     for (int i = 1; i <= n; ++i) {       Unis.insert(-a[i]);     }     long long now = 0;     for (int kk = 1; kk <= k; ++kk) {       long long val = *Unis.begin();       now += val;       Unis.erase(Unis.begin());       Unis.insert(val + dta);       ans[kk] = -now;     }   }   int main() {     scanf( %d %d %d %d , &n, &m, &k, &p);     for (int i = 1; i <= n; ++i)       for (int j = 1; j <= m; ++j) {         scanf( %d , &a[i][j]);         row[i] += a[i][j];         col[j] += a[i][j];       }     solve(ans1, n, row, p * m);     solve(ans2, m, col, p * n);     long long zans = -1e18;     for (int i = 0; i <= k; ++i) {       zans = max(zans, ans1[i] + ans2[k - i] - (long long)i * (k - i) * p);     }     cout << zans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int c, hi, hb, wi, wb;   inline long long f(int x) {     long long k1 = x;     long long k2 = 1ll * (0ll + c - 1ll * x * wi) / wb;     return k1 * hi + k2 * hb;   }   int main() {     cin >> c >> hi >> hb >> wi >> wb;     int kek1 = c / wi;     int l = 0;     int r = kek1;     long long ans = 0;     ans = max(ans, f(0));     ans = max(ans, f(kek1));     for (int i = 0; i <= 10000000; ++i)       if (i <= kek1) ans = max(ans, f(i));     while (r - l > 1) {       int m = (r - l + 1) / 3;       int k1 = l + m;       int k2 = r - m;       if (f(k1) > f(k2))         r = k2;       else         l = k1;     }     for (int i = l - 9000000; i <= r + 9000000; ++i)       if (i >= 0 && i <= kek1) ans = max(ans, f(i));     swap(wi, wb);     swap(hi, hb);     kek1 = c / wi;     l = 0;     r = kek1;     for (int i = 0; i <= 10000000; ++i)       if (i <= kek1) ans = max(ans, f(i));     while (r - l > 1) {       int m = (r - l + 1) / 3;       int k1 = l + m;       int k2 = r - m;       if (f(k1) > f(k2))         r = k2;       else         l = k1;     }     for (int i = l - 9000000; i <= r + 9000000; ++i)       if (i >= 0 && i <= kek1) ans = max(ans, f(i));     ans = max(ans, f(0));     ans = max(ans, f(kek1));     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a[101000], tmp;   struct C {     int b, p;   } c[101000];   long long ans = 0, tot;   bool cmp(C c1, C c2) { return c1.b < c2.b; }   priority_queue<int, vector<int>, greater<int> > q;   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     for (int i = 1; i <= m; i++) scanf( %d , &c[i].b);     for (int i = 1; i <= m; i++) scanf( %d , &c[i].p);     sort(c + 1, c + m + 1, cmp);     int p, pos = 0;     for (int now = n; now > 0; now = p - 1) {       p = now;       tot = a[p];       for (; a[p - 1] <= a[now] && p > 1;) tot += a[--p];       for (; pos < m && c[pos + 1].b <= a[now];) q.push(c[++pos].p);       for (; !q.empty();) {         if (tot >= q.top()) {           ans++;           tot -= q.top();           q.pop();         } else {           tmp = q.top() - tot;           q.pop();           q.push(tmp);           tot = 0;           break;         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   int t, n, a[N];   int main() {     ios::sync_with_stdio(false);     for (cin >> t; t; t--) {       cin >> n;       long long l = 0, r = 0;       for (int i = 1; i <= n; i++) {         cin >> a[i];         l += a[i];         r ^= a[i];       }       cout << 2 <<   n  << r <<     << (l + r) <<   n ;     }     return 0;   }
#include  bits/stdc++.h    using namespace std;   #define ll               long long int   #define pb                push_back   #define ppb               pop_back   #define pf                push_front   #define ppf               pop_front   #define all(x)            (x).begin(),(x).end()   #define uniq(v)           (v).erase(unique(all(v)),(v).end())   #define sz(x)             (int)((x).size())   #define fr                first   #define sc                second   #define pii               pair<int,int>   #define rep(i,a,b)        for(int i=a;i<b;i++)   #define mem1(a)           memset(a,-1,sizeof(a))   #define mem0(a)           memset(a,0,sizeof(a))   #define ppc               __builtin_popcount   #define ppcll             __builtin_popcountll          template<typename T,typename T1>T max_self(T &a,T1 b){if(b>a)a=b;return a;}   template<typename T,typename T1>T min_self(T &a,T1 b){if(b<a)a=b;return a;}       const long long int INF=1e9;   const int N=0;   const int modn=1e9+7;                  void solve(){   int n,m;cin>>n>>m;    string s,t;    cin>>s>>t;    int left[m],right[m];    int i=0,j=0;     while(j<m)      {while(s[i]!=t[j])         i++;        left[j]=i;        j++,i++;       }      i=n-1; j=m-1;      while(~j)      {       while(s[i]!=t[j])         i--;         right[j]=i;         i--,j--;    }     int ans=0;    //rep(i,0,m)    //cout<<left[i]<<   ;       rep(i,1,m)       max_self(ans,right[i]-left[i-1]);    cout<<ans<<  n  ;       }   int main(){    ios_base::sync_with_stdio(false);    cin.tie(0);cout.tie(0);    int t=1;    //cin>>t;    while(t--) solve();    return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long gcd(long long x, long long y) {     if (y == 0) return x;     return gcd(y, x % y);   }   long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }   void XsliferX() {     ios::sync_with_stdio(0);     ios_base::sync_with_stdio(0);     cin.tie(0), cout.tie(0);   }   long long f_p(long long x, int y) {     if (y == 0)       return 1;     else if (y % 2 == 0)       return f_p(x * x, y / 2);     else       return x * f_p(x * x, y / 2);   }   long long l_p(long long n) {     n = n | (n >> 1);     n = n | (n >> 2);     n = n | (n >> 4);     n = n | (n >> 8);     return (n + 1) >> 1;   }   int dp[5005];   int a[5005];   int n;   int L[5005], R[5005];   bool vis[5005];   int solve(int idx) {     int x = 0;     int lft = L[a[idx]], rit = R[a[idx]];     if (idx == n) return 0;     if (dp[idx] != -1) return dp[idx];     for (int i = L[a[idx]]; i <= R[a[idx]]; i++) {       if (lft > L[a[i]]) lft = L[a[i]];       if (rit < R[a[i]]) rit = R[a[i]];     }     bool v[5005] = {0};     if (idx == lft) {       int xo = 0;       for (int i = lft; i <= rit; i++) {         if (!v[a[i]]) {           xo ^= a[i];           v[a[i]] = 1;         }         vis[a[i]] = 1;       }       x = max(x, solve(rit + 1) + xo);       for (int i = lft; i < rit; i++) {         vis[a[i]] = 0;       }     }     vis[a[idx]] = 1;     x = max(x, solve(idx + 1));     vis[a[idx]] = 0;     return dp[idx] = x;   }   int main() {     memset(dp, -1, sizeof dp);     cin >> n;     for (int i = 0; i < n; i++) cin >> a[i], R[a[i]] = i;     memset(L, -1, sizeof L);     for (int i = 0; i < n; i++)       if (L[a[i]] == -1) L[a[i]] = i;     cout << solve(0) <<   n ;     return 0;   }
#include <bits/stdc++.h>   template <class T>   inline bool chmax(T& a, T b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   inline bool chmin(T& a, T b) {     if (a > b) {       a = b;       return 1;     }     return 0;   }   constexpr long long MAX = 5100000;   constexpr long long INF = 1LL << 60;   constexpr int inf = 1000000007;   constexpr long long mod = 998244353LL;   const long double PI = acos((long double)(-1));   using namespace std;   struct mint {     long long x;     mint(long long x = 0) : x((x % mod + mod) % mod) {}     mint& operator+=(const mint a) {       if ((x += a.x) >= mod) x -= mod;       return *this;     }     mint& operator-=(const mint a) {       if ((x += mod - a.x) >= mod) x -= mod;       return *this;     }     mint& operator*=(const mint a) {       (x *= a.x) %= mod;       return *this;     }     mint operator+(const mint a) const {       mint res(*this);       return res += a;     }     mint operator-(const mint a) const {       mint res(*this);       return res -= a;     }     mint operator*(const mint a) const {       mint res(*this);       return res *= a;     }     mint pow(long long t) const {       if (!t) return 1;       mint a = pow(t >> 1);       a *= a;       if (t & 1) a *= *this;       return a;     }     mint inv() const { return pow(mod - 2); }     mint& operator/=(const mint a) { return (*this) *= a.inv(); }     mint operator/(const mint a) const {       mint res(*this);       return res /= a;     }   };   mint dp[2][4001];   void init(int x) {     for (int i = 0; i <= 4000; i++) dp[x][i] = 0;   }   long long fac[MAX], finv[MAX], inv[MAX];   void COMinit() {     fac[0] = fac[1] = 1;     finv[0] = finv[1] = 1;     inv[1] = 1;     for (int i = 2; i < MAX; i++) {       fac[i] = fac[i - 1] * i % mod;       inv[i] = mod - inv[mod % i] * (mod / i) % mod;       finv[i] = finv[i - 1] * inv[i] % mod;     }   }   mint COM(int n, int k) {     if (n < k) return 0;     if (n < 0 || k < 0) return 0;     return mint(fac[n] * (finv[k] * finv[n - k] % mod) % mod);   }   int main() {     COMinit();     long long n, k;     scanf( %lld %lld , &n, &k);     vector<long long> h(n);     for (int i = 0; i < n; i++) scanf( %lld , &h[i]);     int cnt = 0;     for (int i = 0; i < n; i++) {       if (h[i] != h[(i + 1) % n]) {         cnt++;       }     }     mint res = 0;     vector<mint> k2(n + 1);     k2[0] = 1;     for (int i = 1; i <= n; i++) k2[i] = k2[i - 1] * (k - 2);     vector<mint> tw(n + 1);     tw[0] = 1;     for (int i = 1; i <= n; i++) tw[i] = tw[i - 1] * 2;     mint tinv = mint(2).inv();     for (int i = 0; i < cnt; i++) {       int r = cnt - i;       if (r & 1)         res += COM(cnt, i) * k2[i] * tw[r - 1];       else         res += COM(cnt, i) * k2[i] * (tw[r] - COM(r, r / 2)) * tinv;     }     res *= mint(k).pow(n - cnt);     cout << res.x <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long inf = 1000ll * 1000ll * 1000ll;   const long long inf64 = inf * inf;   const double pi = acos(-1.0);   long long Abs(long long a) { return (a >= 0 ? a : -a); }   template <typename T>   inline T Sqr(T a) {     return a * a;   }   vector<int> par, sz;   bool solve() {     ios_base::sync_with_stdio(0);     ifstream fin( run.in );     ofstream fout( run.out );     int n, a, b;     cin >> n;     vector<int> d(n - 1);     for (int i(0); i < n - 1; i++) cin >> d[i];     cin >> a >> b;     a--, b--;     long long ans = 0;     for (int i(a); i < b; i++) ans += d[i];     cout << ans <<   n ;     return true;   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 10;   const int inf = 1e9;   int arr[N], pos[N], rMax[N];   int main() {     int n, m;     scanf( %d %d , &n, &m);     for (int i = 0; i < n; i++) {       scanf( %d , arr + i);       pos[arr[i]] = i;     }     fill(rMax, rMax + N, n - 1);     while (m--) {       int a, b;       scanf( %d %d , &a, &b);       if (pos[a] < pos[b]) {         rMax[a] = min(pos[b] - 1, rMax[a]);       } else {         rMax[b] = min(pos[a] - 1, rMax[b]);       }     }     long long ans = 1;     for (int i = n - 2; i >= 0; i--) {       int k = arr[i];       int j = arr[i + 1];       rMax[k] = min(rMax[k], rMax[j]);       ans += rMax[k] - i + 1;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   void change_stream(char* in, char* out) {     ifstream fin;     fin.open(in);     ofstream fout;     fout.open(out);     if (fin && fout) {       freopen(in,  r , stdin);       freopen(out,  w , stdout);     }   }   long long a[500], renum[500];   void shift(long long i) {     long long p = a[i];     a[i] = a[i + 2];     a[i + 2] = a[i + 1];     a[i + 1] = p;     renum[a[i]] = i;     renum[a[i + 1]] = i + 1;     renum[a[i + 2]] = i + 2;   }   void solve() {     long long n;     cin >> n;     pair<long long, long long> s[n];     for (long long i = 0; i < n; i++) {       cin >> a[i];       s[i] = {a[i], i};     }     sort(s, s + n);     for (long long i = 0; i < n; i++) {       renum[i] = s[i].second;       a[renum[i]] = i;     }     long long sdv = 0;     for (long long i = 0; i < n; i++)       for (long long j = i + 1; j < n; j++)         if (a[i] > a[j]) sdv++;     if (sdv % 2) {       bool flag = false;       for (long long i = 0; i < n - 1; i++)         if (s[i].first == s[i + 1].first) {           swap(a[s[i].second], a[s[i + 1].second]);           renum[a[s[i].second]] = s[i].second;           renum[a[s[i + 1].second]] = s[i + 1].second;           flag = true;           break;         }       if (!flag) {         cout <<  -1 n ;         return;       }     }     vector<long long> ans;     for (long long i = n - 1; i > 1; i--) {       while (renum[i] < i) {         long long l = max(0ll, renum[i] - 1);         ans.push_back(l);         shift(l);       }     }     cout << ans.size() <<   n ;     for (long long i : ans) cout << i + 1 <<    ;     cout <<   n ;   }   signed main() {     change_stream( in ,  out );     ios::sync_with_stdio(0);     cin.tie(0);     long long test_count = 1;     cin >> test_count;     while (test_count--) solve();   }
#include <bits/stdc++.h>   using namespace std;   long long dist(const pair<long long, long long> &a,                  const pair<long long, long long> &b) {     return (a.first - b.first) * (a.first - b.first) +            (a.second - b.second) * (a.second - b.second);   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int n;     cin >> n;     pair<long long, long long> p1, p2;     cin >> p1.first >> p1.second >> p2.first >> p2.second;     vector<pair<long long, long long>> v(n);     for (int i = 0; i < n; ++i) {       pair<long long, long long> tmp;       cin >> tmp.first >> tmp.second;       v[i] = {dist(p1, tmp), dist(p2, tmp)};     }     long long ans = (1LL << 62);     v.push_back({0, 0});     for (int i = 0; i < v.size(); ++i) {       long long r2 = 0;       for (int j = 0; j < v.size(); ++j) {         if (i == j || v[j].first <= v[i].first)           continue;         else           r2 = max(r2, v[j].second);       }       ans = min(ans, v[i].first + r2);     }     if (n == 1) ans = min(ans, v[0].second);     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[200010];   int base;   int n, tmp;   int main() {     cin >> n;     cin >> base;     a[100000]++;     for (int i = 1; i <= n - 1; i++) {       cin >> tmp;       int offset = tmp - base;       if (abs(offset) > 100000) {         cout <<  NO  << endl;         return 0;       }       a[offset + 100000]++;     }     int ub = 100000, lb = 100000;     int cnt = n + a[100000];     while (a[ub]) {       cnt -= a[ub];       ub++;     }     while (a[lb]) {       cnt -= a[lb];       lb--;     }     lb++;     ub--;     if (cnt != 0) {       cout <<  NO ;       return 0;     }     for (int i = lb + 1; i <= ub - 1; i++) {       if (a[i] < 2) {         cout <<  NO ;         return 0;       }       a[i] -= 2;     }     a[lb]--;     a[ub]--;     for (int i = lb; i <= ub; i++) {       if (a[i + 1] < a[i]) {         cout <<  NO ;         return 0;       }       a[i + 1] -= a[i];     }     cout <<  YES ;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   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;   }   int n;   int a[maxn];   int flag = 0;   int flag1 = 0;   int main() {     n = read();     for (int i = 1; i <= n; i++) {       a[i] = read();       if (i <= n - 1 && a[i] == 0) flag1 = 1;     }     if (a[n] == 0) flag = 1;     if (flag) {       if (flag1 == 0) {         printf( YES n );         for (int i = 1; i <= n - 1; i++) {           printf( %d-> , a[i]);         }         printf( %d n , a[n]);         return 0;       }       int place = 0;       for (int i = n - 2; i >= 1; i--) {         if (a[i] == 0) {           place = i;           break;         }       }       if (place == 0) {         printf( NO n );         return 0;       }       printf( YES n );       for (int i = 1; i <= place - 1; i++) {         printf( %d-> , a[i]);       }       printf( (%d-> , a[place]);       printf( ( );       for (int i = place + 1; i <= n - 2; i++) {         printf( %d-> , a[i]);       }       printf( %d , a[n - 1]);       printf( ))-> );       printf( %d n , a[n]);     } else {       printf( NO n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T, class T2>   inline int chkmax(T &x, const T2 &y) {     return x < y ? x = y, 1 : 0;   }   template <class T, class T2>   inline int chkmin(T &x, const T2 &y) {     return x > y ? x = y, 1 : 0;   }   const int MAXN = (1 << 20);   int n, sum = 0;   vector<int> li1;   vector<pair<int, int> > li;   void read() {     cin >> n;     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       if (x == 1)         li1.push_back(i);       else         sum += x - 2, li.push_back({x - 2, i});     }   }   vector<pair<int, int> > answer;   void solve() {     if (sum < ((int)li1.size()) - 2) {       cout <<  NO  <<   n ;       return;     }     int d = ((int)li.size()) - 1;     for (int i = 0; i < ((int)li.size()) - 1; i++)       answer.push_back({li[i].second, li[i + 1].second});     if (((int)li1.size()) >= 1) {       int x = li1.back();       li1.pop_back();       answer.push_back({x, li[0].second});       d++;     }     if (((int)li1.size()) >= 1) {       int x = li1.back();       li1.pop_back();       answer.push_back({x, li.back().second});       d++;     }     for (auto &it : li) {       while (it.first >= 1 && ((int)li1.size())) {         int x = li1.back();         li1.pop_back();         answer.push_back({x, it.second});         it.first--;       }     }     cout <<  YES           <<     << d <<   n ;     cout << ((int)answer.size()) <<   n ;     for (auto e : answer) cout << e.first <<     << e.second <<   n ;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     read();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, n, ans, ghor, j, k, flag = 0;     cin >> n;     for (i = 0;; i++) {       ans = (n - 1) / (5 * pow(2, i));       if (ans == 0) break;       n = n - (5 * pow(2, i));     }     ghor = i + 1;     long long p = pow(2, i);     long long cnt = 1;     for (j = 1; j <= 5; j++) {       for (k = 1; k <= p; k++) {         if (cnt == n) {           flag = 1;           break;         }         cnt++;       }       if (flag == 1) break;     }     switch (j) {       case 1:         cout <<  Sheldon  << endl;         break;       case 2:         cout <<  Leonard  << endl;         break;       case 3:         cout <<  Penny  << endl;         break;       case 4:         cout <<  Rajesh  << endl;         break;       case 5:         cout <<  Howard  << endl;         break;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int i, j, n, m;     cin >> n;     vector<int> vec(n);     vector<int> ans;     int count = 1;     for (int i = 0; i < n; i++) {       cin >> vec[i];     }     for (int i = 0; i < n; i++) {       count = 1;       for (int j = 0; j < n; j++) {         if (vec[i] < vec[j]) {           count++;         }       }       ans.push_back(count);     }     for (auto x : ans) {       if (x > 1)         cout << x <<    ;       else         cout << 1 <<    ;     }     cout <<   n ;   }   int32_t main() {     int T = 1;     while (T--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   char matrix[2020][2020];   int dp[2020][2020];   pair<int, int> p[2020 * 2020];   int n, m;   int fill(int i, int j) {     if (i < 0 || j < 0 || i >= n || j >= m) {       return 0;     }     if (dp[i][j] == -1) {       int start_x = i;       int start_y = j;       int count = 0;       p[count++] = {i, j};       if (matrix[i][j] ==  U ) {         i = i - 1;       } else if (matrix[i][j] ==  L ) {         j = j - 1;       } else if (matrix[i][j] ==  D ) {         i = i + 1;       } else {         j = j + 1;       }       while (i != start_x || j != start_y) {         p[count++] = {i, j};         if (matrix[i][j] ==  U ) {           i = i - 1;         } else if (matrix[i][j] ==  L ) {           j = j - 1;         } else if (matrix[i][j] ==  D ) {           i = i + 1;         } else {           j = j + 1;         }       }       for (int i = 0; i < count; i++) {         dp[p[i].first][p[i].second] = (-1 * count);       }       return 0;     }     if (dp[i][j] != 0) {       return dp[i][j];     }     dp[i][j] = -1;     int ans = 1;     if (matrix[i][j] ==  U ) {       ans += abs(fill(i - 1, j));     } else if (matrix[i][j] ==  L ) {       ans += abs(fill(i, j - 1));     } else if (matrix[i][j] ==  D ) {       ans += abs(fill(i + 1, j));     } else {       ans += abs(fill(i, j + 1));     }     if (dp[i][j] < -1) {       ans = dp[i][j];     }     return dp[i][j] = ans;   }   int main() {     int t;     cin >> t;     while (t--) {       cin >> n >> m;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           cin >> matrix[i][j];         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           dp[i][j] = 0;         }       }       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           fill(i, j);         }       }       int ans = dp[0][0];       int x = 0;       int y = 0;       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) {           if (abs(dp[i][j]) > ans) {             x = i;             y = j;             ans = abs(dp[i][j]);           }         }       }       cout << (x + 1) <<     << (y + 1) <<     << ans << endl;     }   }