Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define count2way(v, x) high2way(v, x) - low2way(v, x)
#define lower(v, x)                                                            \
  low2way(v, x) - v.begin() // 1番左が0、もし見つから無いならｎを出力
#define higher(v, x)                                                           \
  high2way(v, x) - v.begin() -                                                 \
      1 // 1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout << a << endl
#define putout2(a, b)                                                          \
  putout(a);                                                                   \
  putout(b)
#define putout3(a, b, c)                                                       \
  putout(a);                                                                   \
  putout(b);                                                                   \
  putout(c)
#define putout4(a, b, c, d)                                                    \
  putout(a);                                                                   \
  putout(b);                                                                   \
  putout(c);                                                                   \
  putout(d)
#define putout5(a, b, c, d, e)                                                 \
  putout(a);                                                                   \
  putout(b);                                                                   \
  putout(c);                                                                   \
  putout(d);                                                                   \
  putout(e)
#define Gput(a, b) G[a].push_back(b)
#define cin1(a) cin >> a
#define cin2(a, b) cin >> a >> b
#define cin3(a, b, c) cin >> a >> b >> c
#define cin4(a, b, c, d) cin >> a >> b >> c >> d
#define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
#define erase(s) s.erase(s.end() - 1) // 文字列sの末尾削除

ll ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll lcm(ll x, ll y) {
  ll z = gcd(x, y);
  return x * y / z;
}
ll primejudge(ll n) {
  if (n < 2)
    return 0;
  else if (n == 2)
    return 1;
  else if (n % 2 == 0)
    return 0;
  double sqrtn = sqrt(n);
  Loop(i, 3, sqrtn + 1) {
    if (n % i == 0) {
      return 0;
    }
    i++;
  }
  return 1;
}
string RLE(string s) {
  ll n = s.size();
  char now = '.';
  ll count = 1;
  string press;
  loop(i, n) {
    if (s[i] != now) {
      if (i) {
        press += now;
        press += to_string(count);
      }
      now = s[i];
      count = 1;
      continue;
    } else
      count++;
  }
  press += now;
  press += to_string(count);
  return press;
}
int main() {
  cout << fixed << setprecision(30);
  string s;
  cin >> s;
  string x = RLE(s);
  ll n = x.size();
  ll rcount = 0;
  loop(i, n) if (x[i] == 'R') rcount++;
  ll area = 0;
  loop(i, rcount) {
    string a, b;
    ll p1 = 0, p2 = 0;
    Loop(j, area, n) {
      if (x[j] == 'L') {
        p1 = j - 1;
        break;
      }
    }
    Loop(j, p1, n) if (x[j] == 'R') {
      p2 = j - 1;
      break;
    }
    Loop(j, area + 1, p1 + 1) a += x[j];
    Loop(j, p1 + 2, p2 + 1) b += x[j];
    ll r = stoll(a);
    ll l = stoll(b);
    loop(j, r - 1) putout(0);
    ll k = (r + 1) / 2 + l / 2;
    putout(k);
    putout(r + l - k);
    loop(j, l - 1) putout(0);
    Loop(j, area + 1, n) {
      if (x[j] == 'R') {
        area = j;
        break;
      }
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define count2way(v, x) high2way(v, x) - low2way(v, x)
#define lower(v, x)                                                            \
  low2way(v, x) - v.begin() // 1番左が0、もし見つから無いならｎを出力
#define higher(v, x)                                                           \
  high2way(v, x) - v.begin() -                                                 \
      1 // 1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout << a << endl
#define putout2(a, b)                                                          \
  putout(a);                                                                   \
  putout(b)
#define putout3(a, b, c)                                                       \
  putout(a);                                                                   \
  putout(b);                                                                   \
  putout(c)
#define putout4(a, b, c, d)                                                    \
  putout(a);                                                                   \
  putout(b);                                                                   \
  putout(c);                                                                   \
  putout(d)
#define putout5(a, b, c, d, e)                                                 \
  putout(a);                                                                   \
  putout(b);                                                                   \
  putout(c);                                                                   \
  putout(d);                                                                   \
  putout(e)
#define Gput(a, b) G[a].push_back(b)
#define cin1(a) cin >> a
#define cin2(a, b) cin >> a >> b
#define cin3(a, b, c) cin >> a >> b >> c
#define cin4(a, b, c, d) cin >> a >> b >> c >> d
#define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
#define erase(s) s.erase(s.end() - 1) // 文字列sの末尾削除

ll ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll lcm(ll x, ll y) {
  ll z = gcd(x, y);
  return x * y / z;
}
ll primejudge(ll n) {
  if (n < 2)
    return 0;
  else if (n == 2)
    return 1;
  else if (n % 2 == 0)
    return 0;
  double sqrtn = sqrt(n);
  Loop(i, 3, sqrtn + 1) {
    if (n % i == 0) {
      return 0;
    }
    i++;
  }
  return 1;
}
string RLE(string s) {
  ll n = s.size();
  char now = '.';
  ll count = 1;
  string press;
  loop(i, n) {
    if (s[i] != now) {
      if (i) {
        press += now;
        press += to_string(count);
      }
      now = s[i];
      count = 1;
      continue;
    } else
      count++;
  }
  press += now;
  press += to_string(count);
  return press;
}
int main() {
  cout << fixed << setprecision(30);
  string s;
  cin >> s;
  string x = RLE(s);
  ll n = x.size();
  ll rcount = 0;
  loop(i, n) if (x[i] == 'R') rcount++;
  ll area = 0;
  loop(i, rcount) {
    string a, b;
    ll p1 = 0, p2 = 0;
    Loop(j, area, n) {
      if (x[j] == 'L') {
        p1 = j - 1;
        break;
      }
    }
    Loop(j, p1, n) if (x[j] == 'R') {
      p2 = j - 1;
      break;
    }
    if (i == rcount - 1)
      p2 = n - 1;
    Loop(j, area + 1, p1 + 1) a += x[j];
    Loop(j, p1 + 2, p2 + 1) b += x[j];
    ll r = stoll(a);
    ll l = stoll(b);
    loop(j, r - 1) putout(0);
    ll k = (r + 1) / 2 + l / 2;
    putout(k);
    putout(r + l - k);
    loop(j, l - 1) putout(0);
    Loop(j, area + 1, n) {
      if (x[j] == 'R') {
        area = j;
        break;
      }
    }
  }
}