Problem p02910 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC target("avx,avx2,tune=native")
#pragma GCC optimization("unroll-loops")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define oset                                                                   \
  tree<int, null_type, less<int>, rb_tree_tag,                                 \
       tree_order_statistics_node_update>
#define orz                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define inp                                                                    \
  freopen("input.txt", "r", stdin);                                            \
  freopen("out.txt", "w", stdout);
ll mod = 1e9 + 7;
void io() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
const int N = 2e5 + 5;
int a[N], v[N];
int main() {
  io();
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2) {
      if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
        continue;
      else {
        cout << "No";
        return 0;
      }
    } else {
      if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
        continue;
      else {
        cout << "No";
        return 0;
      }
    }
  }

  cout << "Yes";
}


Fixed submission:
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#pragma GCC target("avx,avx2,tune=native")
#pragma GCC optimization("unroll-loops")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define oset                                                                   \
  tree<int, null_type, less<int>, rb_tree_tag,                                 \
       tree_order_statistics_node_update>
#define orz                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define inp                                                                    \
  freopen("input.txt", "r", stdin);                                            \
  freopen("out.txt", "w", stdout);
ll mod = 1e9 + 7;
void io() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
const int N = 2e5 + 5;
int a[N], v[N];
int main() {
  // io();
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (i % 2) {
      if (s[i] == 'L' || s[i] == 'U' || s[i] == 'D')
        continue;
      else {
        cout << "No";
        return 0;
      }
    } else {
      if (s[i] == 'R' || s[i] == 'U' || s[i] == 'D')
        continue;
      else {
        cout << "No";
        return 0;
      }
    }
  }

  cout << "Yes";
}