Problem: 2057C - Trip to the Olympiad
Language: c++17 

Code 1:
#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;
 //find_by order()->iterator of indexed element,  order_of_key()-> number of elements strictly less than x
#define lli long long int
typedef tree < lli,  null_type ,  less_equal<lli> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
 
#define endl '\n'
using pii=pair<lli,lli>;
#define MP make_pair
#define F first
#define ld long double
#define S second
#define all(o) o.begin(),o.end()
lli M=1e9+7; 
using mll = map<lli,lli>;
using vi = vector<lli>;
using vvi = vector<vector<lli>>;
using vpii = vector<pii>;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define mem(a,b) memset(a,b,sizeof(a))
#define state pair<lli,pii>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x) cout << #x << "=" << x << "\n"
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define pb push_back
#define mid (l+r)/2
#define lb lower_bound
#define ub upper_bound
template <typename T> T gcd(T a, T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T bin_pow(T b, T p, T m){T x = 1;while(p){if(p&1)x=(x*b)%m;b=(b*b)%m;p=p>>1;}return x;}
//---- Debugger ---- //
#define debarr(a,n) cout<<#a<<" : ";for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debmat(mat,row,col) cout<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
lli fact[1000100],inv_fact[1000100];
lli nCr(lli n,lli r){if(r>n || n<0 ||r<0)return 0;lli d=(inv_fact[r]*inv_fact[n-r])%M;  lli f=(fact[n]*d)%M;return f;}
lli nPr(lli n,lli r){return (nCr(n,r)*fact[r])%M;}
lli n,m,x,k,tt,q,p,y,h,w,l,r,d;
lli lcm(lli a,lli b){
    return (a*b/__gcd(a,b));
}
#undef mid
vi arr,brr;
vvi g,div1;



lli solve(lli n1,lli m1){
 cin>>l>>r;

 lli posl=-1,posr=-1;
 for(lli i=30;i>=0;i--){
   if(((l>>i)&1LL) && (posl==-1)){
    posl=i;
   }
   if(((r>>i)&1LL) && (posr==-1)){
    posr=i;
   }
 }

 if(abs(posr-posl)>=2){
  cout<<(1LL<<posr)<<" "<<(1LL<<(posr-1))<<" "<<((1LL<<(posr-1))-1)<<endl;
  return 1;
 }
 else if(posr-posl==1){
  if((r&(r-1))==0){
    cout<<r<<" "<<r-1<<" "<<r-2<<endl;
  }
  else{
    lli num=(1LL<<posr);
    cout<<num+1<<" "<<num<<" "<<num-1<<endl;
  }
  return 1;
 }

 for(lli i=30;i>=0;i--){
  lli nr=(r>>i)&1LL,nl=(l>>i)&1LL;
  if(nr==1 && nl==0){
    lli num=(1LL<<i);
    lli n1=r&((1LL<<(i+1))-1);
    lli lft=r-n1;
    if(n1==num){
     cout<<lft+n1<<" "<<lft+n1-1<<" "<<lft+n1-2<<endl;
    }
    else{
     cout<<lft+num+1<<" "<<lft+num<<" "<<lft+num-1<<endl;
    }
    return 1;
  }
 }


 return 1;
}


int main(){
 IOS
 
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
  //  fact[0]=1;
  //  for(lli i=1;i<=200200;i++){
  //    fact[i]=(i*fact[i-1])%M;
  //  }
  //  for(lli i=0;i<=200200;i++){
  //   inv_fact[i]=bin_pow<lli>(fact[i],M-2,M);
  //  }
//  deb(nCr(5,2));

//  div1.resize(1001000);
//  for(lli i=1;i<1001000;i++){
//   for(lli j=i;j<1001000;j+=i){
//     div1[j].pb(i);
//   }
//  }

//  pr(div1[10]);

 

cin>>tt;
// tt=1;
// lli cnt=1;
  while(tt--){
    solve(0,0);
  
  }
  
}

Code 2:
#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;
 //find_by order()->iterator of indexed element,  order_of_key()-> number of elements strictly less than x
#define lli long long int
typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
 
#define endl '\n'
using pii=pair<lli,lli>;
#define MP make_pair
#define F first
#define ld long double
#define S second
#define all(o) o.begin(),o.end()
lli M=998244353;
using mll = map<lli,lli>;
using vi = vector<lli>;
using vvi = vector<vector<lli>>;
using vpii = vector<pii>;
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define mem(a,b) memset(a,b,sizeof(a))
#define state pair<lli,pii>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x) cout << #x << "=" << x << "\n"
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << "\n"
#define pb push_back
#define mid (l+r)/2
#define lb lower_bound
#define ub upper_bound
#define fr(i, a, b) for (lli i = a; i < b; i++)
#define rev(i, a, b) for (lli i = a; i >= b; i--)
template <typename T> T gcd(T a, T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T bin_pow(T b, T p, T m){T x = 1;while(p){if(p&1)x=(x*b)%m;b=(b*b)%m;p=p>>1;}return x;}
//---- Debugger ---- //
#define debarr(a,n) cout<<#a<<" : ";for(int i=0;i<n;i++) cerr<<a[i]<<" "; cerr<<endl;
#define debmat(mat,row,col) cout<<#mat<<" :\n";for(int i=0;i<row;i++) {for(int j=0;j<col;j++) cerr<<mat[i][j]<<" ";cerr<<endl;}
#define pr(...) dbs(#__VA_ARGS__, __VA_ARGS__)
template <class S, class T>ostream& operator <<(ostream& os, const pair<S, T>& p) {return os << "(" << p.first << ", " << p.second << ")";}
template <class T>ostream& operator <<(ostream& os, const vector<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const unordered_set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const unordered_map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const set<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T>ostream& operator <<(ostream& os, const multiset<T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class S, class T>ostream& operator <<(ostream& os, const map<S, T>& p) {os << "[ "; for (auto& it : p) os << it << " "; return os << "]";}
template <class T> void dbs(string str, T t) {cerr << str << " : " << t << "\n";}
template <class T, class... S> void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << " : " << t << ","; dbs(str.substr(idx + 1), s...);}
template <class T> void prc(T a, T b) {cerr << "["; for (T i = a; i != b; ++i) {if (i != a) cerr << ", "; cerr << *i;} cerr << "]\n";}
lli fact[1000100],inv_fact[1000100];
lli nCr(lli n,lli r){if(r>n || n<0 ||r<0)return 0;lli d=(inv_fact[r]*inv_fact[n-r])%M;  lli f=(fact[n]*d)%M;return f;}
lli nPr(lli n,lli r){return (nCr(n,r)*fact[r])%M;}
lli n,m,x,k,tt,q,p,y,h,w,l,r,d;
lli lcm(lli a,lli b){
    return (a*b/__gcd(a,b));
}

vvi arr,brr;
vvi g,pref,pref1,ans;
string str;
map<char,pii> mp;

lli rec(lli lvl,lli i,lli j,lli sum,lli rsum,lli csum){
  // deb2(i,j);


  auto [dx,dy]=mp[str[lvl]];
  lli ni=i+dx,nj=j+dy;

  lli ff=0;
  if(ni==n-1 && nj==m-1){
    if(str[lvl]=='R'){
      lli num1=sum-pref1[0][m-1];
      lli num2=sum-(pref[n-1][0]+rsum);
      ans[ni][nj]=num1;
      return num1==num2;
    }
    else{
      lli num1=sum-pref[n-1][0];
      lli num2=sum-(pref[0][m-1]+csum);
      ans[ni][nj]=num1;
      return num1==num2;
    }
  }
  else{
    if(str[lvl]=='R'){
      if(str[lvl+1]=='R'){
         ans[ni][nj]=sum-pref1[0][nj];
         ff=rec(lvl+1,ni,nj,sum,rsum+ans[ni][nj],0);
      }
      else 
        if(str[lvl+1]=='D'){
         ans[ni][nj]=sum-(pref[ni][0]+rsum);
         ff=rec(lvl+1,ni,nj,sum,0,ans[ni][nj]);
        }
    }
    else{
      if(str[lvl+1]=='D'){
         ans[ni][nj]=sum-pref[ni][0];
         ff=rec(lvl+1,ni,nj,sum,0,csum+ans[ni][nj]);
      }
      else 
        if(str[lvl+1]=='R'){
         ans[ni][nj]=sum-(pref1[0][nj]+csum);
         ff=rec(lvl+1,ni,nj,sum,ans[ni][nj],0);
        }
    }
  }

  return ff;

}


lli solve(lli n1,lli m1){
  cin>>n>>m;
  pref.assign(n,vi(m,0));
  pref1.assign(n,vi(m,0));
  ans.assign(n,vi(m,0));
  arr.assign(n,vi(m,0));
  cin>>str;

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
     cin>>arr[i][j];
     ans[i][j]=arr[i][j];
    } 
  }
  
  for(int i=0;i<n;i++){
    for(int j=m-1;j>=0;j--){
      pref[i][j]=arr[i][j];
      if(j+1<m){
        pref[i][j]+=pref[i][j+1];
      }
    }
  }

  for(int j=0;j<n;j++){
    for(int i=n-1;i>=0;i--){
      pref1[i][j]=arr[i][j];
      if(i+1<n){
        pref1[i][j]+=pref1[i+1][j];
      }
    }
  }

  lli sum=0,rsum=0,csum=0;
  if(str[0]=='D'){
    sum=pref[0][0];
  }
  else{
    sum=pref1[0][0];
  }
  
  

  lli x=rec(0,0,0,sum,0,0);
  assert(x==1);
  ans[0][0]=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cout<<ans[i][j]<<" ";
    }
    cout<<endl;
  }
  return 1;
}



int main(){
 IOS
 
  //  freopen("input.txt", "r", stdin);
  //  freopen("output.txt", "w", stdout);
//    fact[0]=1;
//    for(lli i=1;i<1000100;i++){
//      fact[i]=(i*fact[i-1])%M;
//    }
//    for(lli i=0;i<1000100;i++){
//     inv_fact[i]=bin_pow<lli>(fact[i],M-2,M);
//    }
//  deb(nCr(5,2));

//  div1.assign(1000100,0);
 
//  for(lli i=1;i<1000100;i++){
//   for(lli j=i;j<1000100;j+=i){
//     div1[j]++;
//   }
//  }

// deb(div1[2]);
mp['D']=MP(1,0);
mp['R']=MP(0,1);


cin>>tt;
// tt=1;
// lli cnt=1;
  while(tt--){
    solve(0,0);
  }
  
}

Answer: 1