prithivMLmods/Coder-Stat huggingface dataset:
Problem p02953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"

using namespace std;

int main() {

  int N;
  cin >> N;
  vector<int> H(N);

  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  for (int i = 0; i < N - 1; i++) {
    int h = H[i];
    int h_min = *min_element(H.begin() + i + 1, H.end());
    if (h - h_min >= 2) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

int main1() {

  int N;
  cin >> N;
  vector<int> H(N);

  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  /*
  for (int i = 0; i < N; i++) {
    cerr << H[i] << " ";
  }
  cerr << endl;
  */
  for (int i = 0; i < N - 1; i++) {
    if (H[i] > H[i + 1]) {
      H[i]--;
    }
  }
  /*
  for (int i = 0; i < N; i++) {
    cerr << H[i] << " ";
  }
  cerr << endl;
  */

  for (int i = 0; i < N - 1; i++) {
    if (H[i] > H[i + 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;

int main() {

  int N;
  cin >> N;
  vector<int> H(N);

  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }

  for (int i = N - 2; i >= 0; --i) {
    if (H[i] == (H[i + 1] + 1)) {
      H[i]--;
    } else if (H[i] > (H[i + 1] + 1)) {
      cout << "No";
      return 0;
    }
  }

  for (int i = 0; i < N - 1; i++) {
    if (H[i] > H[i + 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

int main2() {

  int N;
  cin >> N;
  vector<int> H(N);

  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  //! �����̉E���̗v�f��2�ȏ㏬�����̂����邩���ׂ�
  for (int i = 0; i < N - 1; i++) {
    int h = H[i];
    int h_min = *min_element(H.begin() + i + 1, H.end());
    if (h - h_min >= 2) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

int main1() {

  int N;
  cin >> N;
  vector<int> H(N);

  for (int i = 0; i < N; i++) {
    cin >> H[i];
  }
  /*
  for (int i = 0; i < N; i++) {
    cerr << H[i] << " ";
  }
  cerr << endl;
  */
  for (int i = 0; i < N - 1; i++) {
    if (H[i] > H[i + 1]) {
      H[i]--;
    }
  }
  /*
  for (int i = 0; i < N; i++) {
    cerr << H[i] << " ";
  }
  cerr << endl;
  */

  for (int i = 0; i < N - 1; i++) {
    if (H[i] > H[i + 1]) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";

  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>

int n, a[10001], i;

int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (i = n - 1; i > 0; i--) {
    if (a[i] < a[i - 1])
      a[i - 1]--;
    if (a[i - 1] == 0 || a[i - 1] > a[i]) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

Fixed submission:
#include <cstdio>

int n, a[1000001], i;

int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (i = n - 1; i > 0; i--) {
    if (a[i] < a[i - 1])
      a[i - 1]--;
    if (a[i - 1] == 0 || a[i - 1] > a[i]) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 100000 + 10;
int a[N], n;
bool vis[N];

int main() {
  scanf("%d", &n);
  a[0] = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    if (i - 1 && a[i - 1] > a[i]) {
      if (!vis[a[i - 1]]) {
        a[i - 1]--;
        vis[i - 1] = 1;
        if (a[i - 1] > a[i]) {
          printf("No");
          return 0;
        } else {
          int k = i - 2;
          if (k)
            while (k && a[k] > a[k + 1]) {
              if (vis[k]) {
                printf("No");
                return 0;
              } else {
                a[k]--;
                vis[k] = 1;
                if (a[k] > a[k + 1]) {
                  printf("No");
                  return 0;
                }
              }
              k--;
            }
        }
      } else {
        printf("No");
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 100000 + 10;
int a[N], n;
bool vis[N];

int main() {
  scanf("%d", &n);
  a[0] = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    if (i - 1 && a[i - 1] > a[i]) {
      if (!vis[i - 1]) {
        a[i - 1]--;
        vis[i - 1] = 1;
        if (a[i - 1] > a[i]) {
          printf("No");
          return 0;
        } else {
          int k = i - 2;
          if (k)
            while (k && a[k] > a[k + 1]) {
              if (vis[k]) {
                printf("No");
                return 0;
              } else {
                a[k]--;
                vis[k] = 1;
                if (a[k] > a[k + 1]) {
                  printf("No");
                  return 0;
                }
              }
              k--;
            }
        }
      } else {
        printf("No");
        return 0;
      }
    }
  }
  cout << "Yes";
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main(void) {
  int n;
  cin >> n;

  int h[n];
  rep(i, n) cin >> h[i];

  int max = 0;
  rep(i, n) {
    if (h[i] > max) {
      max = h[i];
      for (int j = i; j < n; j++) {
        if (h[i] - 1 > h[j]) {
          puts("No");
          return 0;
        }
      }
    }
  }
  puts("Yes");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)

int main(void) {
  int n;
  cin >> n;

  int h[n];
  rep(i, n) cin >> h[i];

  int max = 0;
  rep(i, n) {
    if (h[i] > max) {
      max = h[i];
      for (int j = i; j < n; j++) {
        if (h[j] > max)
          max = h[j];
        if (max - 1 > h[j]) {
          puts("No");
          return 0;
        }
      }
    }
  }
  puts("Yes");
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int a[10005];
int main() {
  int n, maxh = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  maxh = a[1];
  for (int i = 2; i <= n; i++) {
    if (a[i] - maxh <= -2) {
      cout << "No";
      return 0;
    }
    maxh = max(a[i], maxh);
  }
  cout << "Yes";
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int a[100005];
int main() {
  int n, maxh = 0;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  maxh = a[1];
  for (int i = 2; i <= n; i++) {
    if (a[i] - maxh <= -2) {
      cout << "No";
      return 0;
    }
    maxh = max(a[i], maxh);
  }
  cout << "Yes";
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  string ans = "Yes";
  for (int i = 0; i < n - 1; i++) {
    if (h.at(i) - 1 > h.at(i + 1)) {
      ans = "No";
      break;
    }
    if (i < n - 1 && h.at(i) - 1 > h.at(i + 2)) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }
  string ans = "Yes";
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      h.at(i) -= 1;
    } else {
      if (h.at(i) < h.at(i - 1)) {
        ans = "No";
        break;
      } else if (h.at(i) > h.at(i - 1)) {
        h.at(i) -= 1;
      }
    }
  }
  cout << ans << endl;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int N;
  unsigned long long int H[10000];
  cin >> N;

  H[0] = 0;

  for (int i = 1; i <= N; ++i) {
    cin >> H[i];
  }

  for (int i = 1; i <= N; ++i) {
    int d = H[i] - H[i - 1];

    if (d >= 1) {
      --H[i];
    } else if (d == 0) {
      ;
    } else {
      cout << "No";
      return 0;
    }
  }

  cout << "Yes";

  return 0;
}


Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int N;
  unsigned long long int H[100000];
  cin >> N;

  H[0] = 0;

  for (int i = 1; i <= N; ++i) {
    cin >> H[i];
  }

  for (int i = 1; i <= N; ++i) {
    int d = H[i] - H[i - 1];

    if (d >= 1) {
      --H[i];
    } else if (d == 0) {
      ;
    } else {
      cout << "No";
      return 0;
    }
  }

  cout << "Yes";

  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18 + 1;
const ll DIV = 1000000007;
// #define TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef TEST
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
#endif
  long N;
  cin >> N;
  vector<long> H(N);
  for (size_t i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (long i = N - 1; i >= 0; i--) {
    if (H[i] < H[i - 1])
      H[i - 1]--;
  }
  bool ok = true;
  for (size_t i = 1; i < N; i++) {
    if (H[i] < H[i - 1])
      ok = false;
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
#ifdef TEST
  end = chrono::system_clock::now();
  cerr << static_cast<double>(
              chrono::duration_cast<chrono::microseconds>(end - start).count() /
              1000.0)
       << "[ms]" << endl;
#endif
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18 + 1;
const ll DIV = 1000000007;
// #define TEST
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
#ifdef TEST
  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
#endif
  long N;
  cin >> N;
  vector<long> H(N);
  for (size_t i = 0; i < N; i++) {
    cin >> H[i];
  }
  for (long i = N - 1; i >= 1; i--) {
    if (H[i] < H[i - 1])
      H[i - 1]--;
  }
  bool ok = true;
  for (size_t i = 1; i < N; i++) {
    if (H[i] < H[i - 1])
      ok = false;
  }
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
#ifdef TEST
  end = chrono::system_clock::now();
  cerr << static_cast<double>(
              chrono::duration_cast<chrono::microseconds>(end - start).count() /
              1000.0)
       << "[ms]" << endl;
#endif
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  stack<long> h;
  for (int i = 0; i < n; i++) {
    long n;
    cin >> n;
    h.push(n);
  }

  long bef = h.top();
  h.pop();

  for (int i = 0; i < n; i++) {
    long now = h.top();
    h.pop();
    if (now <= bef) {
      bef = now;
      continue;
    }
    if (now - bef == 1) {
      bef = now - 1;
      continue;
    }
    printf("No");
    return 0;
  }

  printf("Yes");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  stack<long> h;
  for (int i = 0; i < n; i++) {
    long n;
    cin >> n;
    h.push(n);
  }

  long bef = h.top();
  h.pop();

  for (int i = 1; i < n; i++) {
    long now = h.top();
    h.pop();
    if (now <= bef) {
      bef = now;
      continue;
    }
    if (now - bef == 1) {
      bef = now - 1;
      continue;
    }
    printf("No");
    return 0;
  }

  printf("Yes");
  return 0;
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int64_t> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  for (int i = N - 1; i >= 0; i--) {
    if (vec[i - 1] > vec[i]) {
      vec[i - 1] = vec[i - 1] - 1;
    }
  }

  bool higensyou = true;
  for (int i = 0; i < N - 1; i++) {
    if (vec[i] > vec[i + 1]) {
      higensyou = false;
      break;
    }
  }

  if (higensyou) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int64_t> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  for (int i = N - 1; i > 0; i--) {
    if (vec[i - 1] > vec[i]) {
      vec[i - 1] = vec[i - 1] - 1;
    }
  }

  bool higensyou = true;
  for (int i = 0; i < N - 1; i++) {
    if (vec[i] > vec[i + 1]) {
      higensyou = false;
      break;
    }
  }

  if (higensyou) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, a[10005], ma;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    ma = max(a[i], ma);
    if (ma - a[i] > 1) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, a[100005], ma;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    ma = max(a[i], ma);
    if (ma - a[i] > 1) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}
Problem p02953 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N;
  cin >> N;
  long long H[100000];
  for (long long i = 0; i < N; i++) {
    cin >> H[i];
  }

  bool ans = true;
  for (long long i = 0; i < N - 1; i++) {
    for (long long j = i + 1; j < N - 1; j++) {
      if (H[i] - H[j + 1] >= 2) {
        ans = false;
        break;
      }
    }
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long N;
  cin >> N;
  long long H[100000];
  for (long long i = 0; i < N; i++) {
    cin >> H[i];
  }

  bool ans = true;

  for (long long i = N - 1; i > 0; i--) {
    if (H[i - 1] - H[i] > 1) {
      ans = false;
      break;
    } else if (H[i - 1] - H[i] == 1) {
      H[i - 1] -= 1;
    }
  }

  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02953 (C++)

Buggy submission (status: Runtime Error):
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  if (h[0] > h[1]) {
    cout << "No\n";
    return 0;
  }
  for (int i = 1; i < n - 1; i++) {
    if (h[i] - h[i + 1] == 1) {
      h[i]--;
      if (h[i - 1] - h[i] > 0) {
        cout << "No\n";
        return 0;
      }
    } else if (h[i] - h[i + 1] >= 2) {
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";
}

Fixed submission:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  int pre = -999;
  rep(i, n) {
    if (pre <= h[i] - 1) {
      pre = h[i] - 1;
    } else if (pre <= h[i]) {
      pre = h[i];
    } else {
      puts("No");
      return 0;
    }
  }

  cout << "Yes\n";
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
// using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 400005, MAXM = 102, Mod = 1000000007, MAXLog = 20;

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9),
      cout << fixed;

  string s;
  cin >> s;
  vector<int> lft(s.size());
  vector<int> right(s.size());
  int lst = 0;
  for (int i = 0; i < s.size(); ++i) {
    lst = (s[i] == 'R' ? i : lst);
    lft[i] = lst;
  }
  lst = s.size() - 1;
  for (int i = s.size() - 1; i >= 0; --i) {
    lst = (s[i] == 'L' ? i : lst);
    right[i] = lst;
  }

  vector<int> ans(s.size(), 0);

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'R') {
      ans[right[i] - ((right[i] - i) & 1)]++;
    } else {
      ans[lft[i] - ((i - lft[i]) & 1)]++;
    }
  }

  for (int i = 0; i < s.size(); ++i) {
    cout << ans[i] << ' ';
  }
  cout << '\n';

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
// #include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
// using namespace __gnu_cxx;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 400005, MAXM = 102, Mod = 1000000007, MAXLog = 20;

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9),
      cout << fixed;

  string s;
  cin >> s;
  vector<int> lft(s.size());
  vector<int> right(s.size());
  int lst = 0;
  for (int i = 0; i < s.size(); ++i) {
    lst = (s[i] == 'R' ? i : lst);
    lft[i] = lst;
  }
  lst = s.size() - 1;
  for (int i = s.size() - 1; i >= 0; --i) {
    lst = (s[i] == 'L' ? i : lst);
    right[i] = lst;
  }

  vector<int> ans(s.size(), 0);

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'R') {
      ans[right[i] - ((right[i] - i) & 1)]++;
    } else {
      ans[lft[i] + ((i - lft[i]) & 1)]++;
    }
  }

  for (int i = 0; i < s.size(); ++i) {
    cout << ans[i] << ' ';
  }
  cout << '\n';

  return 0;
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
const int N = 1e3 + 3;

int a[N];

int32_t main() {

  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  string s;
  cin >> s;
  int l = s.length();
  int now = 0;
  for (int i = 0; i < l; i++) {
    if (s[i] == 'R')
      now++;
    else {
      if (now & 1)
        a[i - 1] += now / 2 + 1, a[i] += now / 2;
      else
        a[i] += now / 2, a[i - 1] += now / 2;
      now = 0;
    }
  }
  now = 0;
  for (int i = l - 1; ~i; i--) {
    if (s[i] == 'L')
      now++;
    else {
      if (now & 1)
        a[i + 1] += now / 2 + 1, a[i] += now / 2;
      else
        a[i] += now / 2, a[i + 1] += now / 2;
      now = 0;
    }
  }
  for (int i = 0; i < l; i++)
    cout << a[i] << ' ';

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
const int N = 1e5 + 3;

int a[N];

int32_t main() {

  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

  string s;
  cin >> s;
  int l = s.length();
  int now = 0;
  for (int i = 0; i < l; i++) {
    if (s[i] == 'R')
      now++;
    else {
      if (now & 1)
        a[i - 1] += now / 2 + 1, a[i] += now / 2;
      else
        a[i] += now / 2, a[i - 1] += now / 2;
      now = 0;
    }
  }
  now = 0;
  for (int i = l - 1; ~i; i--) {
    if (s[i] == 'L')
      now++;
    else {
      if (now & 1)
        a[i + 1] += now / 2 + 1, a[i] += now / 2;
      else
        a[i] += now / 2, a[i + 1] += now / 2;
      now = 0;
    }
  }
  for (int i = 0; i < l; i++)
    cout << a[i] << ' ';

  return 0;
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
// typedef vector<unsigned int>vec;
typedef vector<ll> vec;
// typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000; // 1e18
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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;
}
template <class T> inline void add(T &a, T b) {
  a = ((a + b) % MOD + MOD) % MOD;
};

int to[44][101010];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.size();
  REP(i, N) {
    if (S[i] == 'R')
      to[0][i] = i + 1;
    else
      to[0][i] = i - 1;
  }

  REP(i, 44) { REP(j, N) to[i + 1][j] = to[i][to[i][j]]; }

  vector<int> ans(N);
  REP(i, N) ans[to[40][i]]++;

  REP(i, N) cout << ans[i] << " ";
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
// typedef vector<unsigned int>vec;
typedef vector<ll> vec;
// typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000; // 1e18
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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;
}
template <class T> inline void add(T &a, T b) {
  a = ((a + b) % MOD + MOD) % MOD;
};

int to[44][101010];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  int N = S.size();
  REP(i, N) {
    if (S[i] == 'R')
      to[0][i] = i + 1;
    else
      to[0][i] = i - 1;
  }

  REP(i, 40) { REP(j, N) to[i + 1][j] = to[i][to[i][j]]; }

  vector<int> ans(N);
  REP(i, N) ans[to[40][i]]++;

  REP(i, N) cout << ans[i] << " ";
  cout << endl;
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  vector<int> arr;
  for (int l = 0; l < sz(s);) {
    int r = l;
    while (r + 1 < sz(s) and s[l] == s[r + 1])
      r++;
    arr.push_back(r - l + 1);
    l = r + 1;
  }
  vector<int> ans(sz(s));
  int cur = 0;
  for (int pos = 0; pos < sz(s); pos += 2) {
    cur = cur + arr[pos];
    int l = cur - 1;
    int r = cur;
    ans[l] += (arr[pos] + 1) / 2;
    ans[r] += arr[pos] / 2;
    ans[r] += (arr[pos + 1] + 1) / 2;
    ans[l] += arr[pos + 1] / 2;
    cur += arr[pos + 1];
  }
  for (int i = 0; i < sz(s); i++)
    cout << ans[i] << " \n"[i == sz(s) - 1];
  return (0);
}


Fixed submission:
#include <bits/stdc++.h>

#define all(A) begin(A), end(A)
#define rall(A) rbegin(A), rend(A)
#define sz(A) int(A.size())
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  vector<int> arr;
  for (int l = 0; l < sz(s);) {
    int r = l;
    while (r + 1 < sz(s) and s[l] == s[r + 1])
      r++;
    arr.push_back(r - l + 1);
    l = r + 1;
  }
  vector<int> ans(sz(s));
  int cur = 0;
  for (int pos = 0; pos < sz(arr); pos += 2) {
    cur = cur + arr[pos];
    int l = cur - 1;
    int r = cur;
    ans[l] += (arr[pos] + 1) / 2;
    ans[r] += arr[pos] / 2;
    ans[r] += (arr[pos + 1] + 1) / 2;
    ans[l] += arr[pos + 1] / 2;
    cur += arr[pos + 1];
  }
  for (int i = 0; i < sz(s); i++)
    cout << ans[i] << " \n"[i == sz(s) - 1];
  return (0);
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> B, C, E;
  B.push_back(0);
  for (int i = 1; i < N - 1; i++) {
    if (S.at(i) == 'R' && S.at(i + 1) == 'L')
      C.push_back(i);
    if (S.at(i) == 'L' && S.at(i + 1) == 'R') {
      E.push_back(i);
      B.push_back(i + 1);
    }
  }
  E.push_back(N - 1);
  int A[100010] = {};
  for (int i = 0; i < B.size(); i++) {
    int l = C.at(i) - B.at(i) + 1;
    int r = E.at(i) - C.at(i);
    A[C.at(i)] += (l + 1) / 2;
    A[C.at(i) + 1] += l - (l + 1) / 2;
    A[C.at(i) + 1] += (r + 1) / 2;
    A[C.at(i)] += r - (r + 1) / 2;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << " ";
  }
  cout << endl;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  vector<int> B, C, E;
  B.push_back(0);
  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) == 'R' && S.at(i + 1) == 'L')
      C.push_back(i);
    if (S.at(i) == 'L' && S.at(i + 1) == 'R') {
      E.push_back(i);
      B.push_back(i + 1);
    }
  }
  E.push_back(N - 1);
  int A[100010] = {};
  for (int i = 0; i < B.size(); i++) {
    int l = C.at(i) - B.at(i) + 1;
    int r = E.at(i) - C.at(i);
    A[C.at(i)] += (l + 1) / 2;
    A[C.at(i) + 1] += l - (l + 1) / 2;
    A[C.at(i) + 1] += (r + 1) / 2;
    A[C.at(i)] += r - (r + 1) / 2;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << " ";
  }
  cout << endl;
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define MN 100005
char ch[MN], f[MN], tot[MN];
int Find(int a) { return a == f[a] ? a : Find(f[a]); }
int main() {
  scanf("%s", ch + 1);
  int n = strlen(ch + 1);
  for (int i = 1; i <= n; ++i)
    f[i] = i;
  for (int i = 1; i <= n; ++i) {
    if (ch[i] == 'L')
      f[i] = Find(i - 1);
    if (ch[i] == 'R' && ch[i + 1] == 'R')
      f[i] = Find(i + 1);
  }
  for (int i = 1; i <= n; ++i) {
    if (ch[i] == 'L')
      f[i] = Find(i - 1);
    if (ch[i] == 'R' && ch[i + 1] == 'R')
      f[i] = Find(i + 1);
    int ans = ((abs(f[i] - i)) & 1) ? (f[i] + 1) : f[i];
    tot[ans]++;
  }
  for (int i = 1; i <= n; ++i)
    printf("%d ", tot[i]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define MN 100055
char ch[MN];
int f[MN], tot[MN];
int Find(int a) { return a == f[a] ? a : (f[a] = Find(f[a])); }
int main() {
  scanf("%s", ch + 1);
  int n = strlen(ch + 1);
  for (int i = 1; i <= n; ++i)
    f[i] = i;
  for (int i = 1; i <= n; ++i) {
    if (ch[i] == 'L')
      f[i] = Find(i - 1);
    if (ch[i] == 'R' && ch[i + 1] == 'R')
      f[i] = Find(i + 1);
  }
  for (int i = 1; i <= n; ++i) {
    if (ch[i] == 'L')
      f[i] = Find(i - 1);
    if (ch[i] == 'R' && ch[i + 1] == 'R')
      f[i] = Find(i + 1);
    int ans = ((abs(f[i] - i)) & 1) ? (f[i] + 1) : f[i];
    tot[ans]++;
  }
  for (int i = 1; i <= n; ++i)
    printf("%d ", tot[i]);
  return 0;
}
Problem p02954 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  string s;
  cin >> s;
  vector<int> v(s.size(), 0);
  for (int i = 0; i < s.size(); ++i) {
    int cnt = 0;
    if (s.at(i) == 'R') {
      for (int j = i; s.at(j) == s.at(i); ++j) {
        ++cnt;
      }
    } else
      for (int j = i; s.at(j) == s.at(i); --j) {
        --cnt;
      }
    if (cnt % 2) {
      if (s.at(i) == 'R')
        ++v.at(i + cnt - 1);
      else
        ++v.at(i + cnt + 1);
    } else
      ++v.at(i + cnt);
  }
  for (auto &&i : v)
    cout << " "s << i;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  string s;
  cin >> s;
  vector<int> v(s.size(), 0);
  for (int i = 0;;) {
    while (i < s.size() && s.at(i) != 'R')
      ++i;
    if (i >= s.size())
      break;
    int st = i;
    while (s.at(i) == 'R')
      ++i;
    v.at(i) += (i - st) / 2;
    v.at(i - 1) += (i - st + 1) / 2;
  }
  for (int i = s.size() - 1;;) {
    while (i >= 0 && s.at(i) != 'L')
      --i;
    if (i < 0)
      break;
    int st = i;
    while (s.at(i) == 'L')
      --i;
    v.at(i) += (st - i) / 2;
    v.at(i + 1) += (st - i + 1) / 2;
  }
  for (auto &&i : v)
    cout << " "s << i;
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  int sl = sz(s);
  vector<pair<char, int>> a;
  vector<int> ans(sl);
  char tmp = 'R';
  int cnt = 1;
  for (int i = 0; i <= sl; i++) {
    if (i == sl)
      a.push_back(make_pair(tmp, cnt));
    else if (tmp == s.at(i))
      cnt++;
    else {
      a.push_back(make_pair(tmp, cnt));
      tmp = s.at(i);
      cnt = 1;
    }
  }
  int ind = -1, i = 0, bl = sz(a);
  while (i < bl) {
    cnt = a[i].second + a[i + 1].second;
    ind += a[i].second;
    ans.at(ind) = (a[i].second - 1) / 2 + 1;
    ans.at(ind) += (a[i + 1].second) / 2;
    ans.at(ind + 1) = cnt - ans.at(ind);
    ind += a[i + 1].second;
    i = i + 2;
  }
  rep(j, sl) cout << ans.at(j) << " ";
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

int main() {
  string s;
  cin >> s;
  int sl = sz(s);
  vector<pair<char, int>> a;
  vector<int> ans(sl);
  char tmp = 'R';
  int cnt = 1;
  for (int i = 1; i <= sl; i++) {
    if (i == sl)
      a.push_back(make_pair(tmp, cnt));
    else if (tmp == s.at(i))
      cnt++;
    else {
      a.push_back(make_pair(tmp, cnt));
      tmp = s.at(i);
      cnt = 1;
    }
  }
  int ind = -1, i = 0, bl = sz(a);
  while (i < bl) {
    cnt = a[i].second + a[i + 1].second;
    ind += a[i].second;
    ans.at(ind) = (a[i].second - 1) / 2 + 1;
    ans.at(ind) += (a[i + 1].second) / 2;
    ans.at(ind + 1) = cnt - ans.at(ind);
    ind += a[i + 1].second;
    i = i + 2;
  }
  rep(j, sl) cout << ans.at(j) << " ";
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template <typename T> void swap(T *t1, T *t2) {
  T *tmp = t1;
  t1 = t2;
  t2 = tmp;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  char s[10000];
  Int a[100000];
  cin >> s;
  Int len = strlen(s);
  int rl = 0;
  int l = 0, r = 1;
  char now = 'R';
  for (Int i = 0; i < len; i++) {
    a[i] = 0;
  }
  for (Int i = 1; i < len; i++) {
    if (now != s[i]) {
      if (now == 'R') {
        rl = i;
        l = 1;
        now = 'L';
      } else {
        a[rl - 1] = l / 2;
        a[rl - 1] += r % 2 == 0 ? r / 2 : r / 2 + 1;
        a[rl] = r / 2;
        a[rl] += l % 2 == 0 ? l / 2 : l / 2 + 1;
        r = 1;
        l = 0;
        now = 'R';
      }
    } else {
      if (now == 'R') {
        r++;
      } else {
        l++;
      }
    }
  }
  a[rl - 1] = l / 2;
  a[rl - 1] += r % 2 == 0 ? r / 2 : r / 2 + 1;
  a[rl] = r / 2;
  a[rl] += l % 2 == 0 ? l / 2 : l / 2 + 1;
  for (Int i = 0; i < len; i++) {
    cout << a[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template <typename T> void swap(T *t1, T *t2) {
  T *tmp = t1;
  t1 = t2;
  t2 = tmp;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  char s[100000];
  Int a[100000];
  cin >> s;
  Int len = strlen(s);
  int rl = 0;
  int l = 0, r = 1;
  char now = 'R';
  for (Int i = 0; i < len; i++) {
    a[i] = 0;
  }
  for (Int i = 1; i < len; i++) {
    if (now != s[i]) {
      if (now == 'R') {
        rl = i;
        l = 1;
        now = 'L';
      } else {
        a[rl - 1] = l / 2;
        a[rl - 1] += r % 2 == 0 ? r / 2 : r / 2 + 1;
        a[rl] = r / 2;
        a[rl] += l % 2 == 0 ? l / 2 : l / 2 + 1;
        r = 1;
        l = 0;
        now = 'R';
      }
    } else {
      if (now == 'R') {
        r++;
      } else {
        l++;
      }
    }
  }
  a[rl - 1] = l / 2;
  a[rl - 1] += r % 2 == 0 ? r / 2 : r / 2 + 1;
  a[rl] = r / 2;
  a[rl] += l % 2 == 0 ? l / 2 : l / 2 + 1;
  for (Int i = 0; i < len; i++) {
    cout << a[i] << endl;
  }
  return 0;
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s.size() == 2) {
    cout << "1 1" << endl;
    return 0;
  }
  s = s + "R";
  int n = s.size();
  vector<int> ans(n, 0);
  int pos = 0;
  int index = 0;
  char now = 'R';
  while (index <= n) {
    if (now == s[index]) {
      index++;
      continue;
    }
    if (now == 'R') {
      int num = index - pos + 1;
      ans[index] += (num + 1) / 2;
      ans[index - 1] += num / 2;
      now = s[index + 1];
      pos = index + 1;
      index = pos;
      continue;
    }
    if (now == 'L') {
      int num = index - pos - 1;
      ans[pos - 2] += num / 2 + 1;
      ans[pos - 1] += (num + 1) / 2;
      now = s[index];
      pos = index;
      index = pos;
    }
  }
  rep(i, n - 2) cout << ans[i] << " ";
  cout << ans[n - 2] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s.size() == 2) {
    cout << "1 1" << endl;
    return 0;
  }
  s = s + "R";
  int n = s.size();
  vector<int> ans(n, 0);
  int pos = 0;
  int index = 0;
  char now = 'R';
  while (index < n) {
    if (now == s[index]) {
      index++;
      continue;
    }
    if (now == 'R') {
      int num = index - pos + 1;
      ans[index] += (num + 1) / 2;
      ans[index - 1] += num / 2;
      now = s[index + 1];
      pos = index + 1;
      index = pos;
      continue;
    }
    if (now == 'L') {
      int num = index - pos - 1;
      ans[pos - 2] += num / 2 + 1;
      ans[pos - 1] += (num + 1) / 2;
      now = s[index];
      pos = index;
      index = pos;
    }
  }
  rep(i, n - 2) cout << ans[i] << " ";
  cout << ans[n - 2] << endl;
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

string s;

int main() {

  cin >> s;
  int n = s.size();
  vector<int> ans(n);
  int c = 0;
  int memo = 0;
  string sss;
  int sw;
  int fff;
  for (int i = 0; i < n; i++) {
    sw = 0;
    if (i == 0) {
      memo = 0;
    } else if (s[i - 1] == 'L' && s[i] == 'R' || i == n - 1) {
      if (i == n - 1) {
        i++;
        // fff=n-3;
      }

      c = i - memo;
      sss = s.substr(memo, c);
      sw = 1;
      memo = i;
      // fff--;
    }

    if (s[i - 1] == 'R' && s[i] == 'L') {
      fff = i - 1;
    }

    if (sw == 1) {
      int nnn = sss.size();
      // cout << nnn << endl;

      int a = nnn / 2;
      int b = a;
      if (nnn % 2 == 1) {
        a++;
      }
      int f;
      for (int j = 0; j < nnn; j++) {
        if (sss[j] == 'L') {
          if (j % 2 == 0) {
            int ccc = b;
            b = a;
            a = ccc;
          }
          f = j;
          break;
        }
      }
      // cout<<"f"<<f<<endl;
      // cout<<"fff"<<fff<<endl;
      ans[fff] = a;
      ans[fff + 1] = b;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define EPS 0.0000000001
#define INF 1000000000
#define MOD 1000000007
typedef long long ll;

string s;

int main() {

  cin >> s;
  int n = s.size();
  vector<int> ans(n);
  int c = 0;
  int memo = 0;
  string sss;
  int sw;
  int fff;
  for (int i = 0; i < n; i++) {
    sw = 0;
    if (i == 0) {
      memo = 0;
    } else if (s[i - 1] == 'L' && s[i] == 'R' || i == n - 1) {
      if (i == n - 1) {
        i++;
        // fff=n-3;
      }

      c = i - memo;
      sss = s.substr(memo, c);
      sw = 1;
      memo = i;
      // fff--;
    }

    if (s[i - 1] == 'R' && s[i] == 'L') {
      fff = i - 1;
    }

    if (s[i - 2] == 'R' && s[i - 1] == 'L' && i == n) {
      fff = i - 2;
    }

    if (sw == 1) {
      int nnn = sss.size();
      // cout << nnn << endl;

      int a = nnn / 2;
      int b = a;
      if (nnn % 2 == 1) {
        a++;
      }
      int f;
      for (int j = 0; j < nnn; j++) {
        if (sss[j] == 'L') {
          if (j % 2 == 0) {
            int ccc = b;
            b = a;
            a = ccc;
          }
          f = j;
          break;
        }
      }
      // cout<<"f"<<f<<endl;
      // cout<<"fff"<<fff<<endl;
      ans[fff] = a;
      ans[fff + 1] = b;
    }
  }
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int ans[10010], n, rr, ll, cr, cl;
string s;

int main() {
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') {
      rr = i;
      cr = 0;
    } else {
      cr++;
      if (cr % 2 == 0)
        ans[rr]++;
      else
        ans[rr + 1]++;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'L') {
      ll = i;
      cl = 0;
    } else {
      cl++;
      if (cl % 2 == 0)
        ans[ll]++;
      else
        ans[ll - 1]++;
    }
  }
  cout << ans[0];
  for (int i = 1; i < n; i++)
    cout << ' ' << ans[i];
  cout << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int ans[100010], n, rr, ll, cr, cl;
string s;

int main() {
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') {
      rr = i;
      cr = 0;
    } else {
      cr++;
      if (cr % 2 == 0)
        ans[rr]++;
      else
        ans[rr + 1]++;
    }
  }
  for (int i = n - 1; i >= 0; i--) {
    if (s[i] == 'L') {
      ll = i;
      cl = 0;
    } else {
      cl++;
      if (cl % 2 == 0)
        ans[ll]++;
      else
        ans[ll - 1]++;
    }
  }
  cout << ans[0];
  for (int i = 1; i < n; i++)
    cout << ' ' << ans[i];
  cout << endl;
}
Problem p02954 (Python)

Buggy submission (status: Runtime Error):
S = input()

count = 1
answer = [0] * len(S)
# RLの切り替わるインデックスをマーク
n = 0
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        count += 1
    else:
        if S[i + 1] == "R":
            # Lを割り振る
            answer[n] += count // 2
            answer[n + 1] += -(-count // 2)
            count = 1
        else:
            # Rを割り振る
            answer[i] += -(-count // 2)
            answer[i + 1] += count // 2
            count = 1
            n = i
    # 右端のLを割り振る
    if i == len(S) - 2:
        answer[n] += count // 2
        answer[n + 1] += -(-count // 2)

for i, c in enumerate(answer):
    if i == 0:
        print(c, end="")
    else:
        print(f" {c}", end="")


Fixed submission:
S = input()

count = 1
answer = [0] * len(S)
# RLの切り替わるインデックスをマーク
n = 0
for i in range(len(S) - 1):
    if S[i] == S[i + 1]:
        count += 1
    else:
        if S[i + 1] == "R":
            # Lを割り振る
            answer[n] += count // 2
            answer[n + 1] += -(-count // 2)
            count = 1
        else:
            # Rを割り振る
            answer[i] += -(-count // 2)
            answer[i + 1] += count // 2
            count = 1
            n = i
    # 右端のLを割り振る
    if i == len(S) - 2:
        answer[n] += count // 2
        answer[n + 1] += -(-count // 2)

for i, c in enumerate(answer):
    print(c, end="")
    print(" ", end="")
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int ltoR[100005];
int ans[10005];

int main() {
  string S;
  cin >> S;
  memset(ans, 0, sizeof(ans));
  memset(ltoR, 0, sizeof(ltoR));
  int lrCounter = 0;

  // 移動する距離をメモ
  // 右からなめる
  for (int i = S.size() - 1; i >= 0; i--) {
    if (S[i] == 'R') {
      lrCounter++;
      ltoR[i] = lrCounter;
    } else {
      lrCounter = 0;
    }
  }

  // 左からなめる
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'L') {
      lrCounter--;
      ltoR[i] = lrCounter;
    } else {
      lrCounter = 0;
    }
  }

  // 計算
  for (int i = 0; i < S.size(); i++) {
    if (ltoR[i] % 2 == 0) {
      ans[i + ltoR[i]] += 1;
    } else if (ltoR[i] < 0) {
      ans[i + ltoR[i] + 1] += 1;
    } else {
      ans[i + ltoR[i] - 1] += 1;
    }
  }

  // 出力
  for (int i = 0; i < S.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int ltoR[100005];
int ans[100005];

int main() {
  string S;
  cin >> S;
  memset(ans, 0, sizeof(ans));
  memset(ltoR, 0, sizeof(ltoR));
  int lrCounter = 0;

  // 移動する距離をメモ
  // 右からなめる
  for (int i = S.size() - 1; i >= 0; i--) {
    if (S[i] == 'R') {
      lrCounter++;
      ltoR[i] = lrCounter;
    } else {
      lrCounter = 0;
    }
  }

  // 左からなめる
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'L') {
      lrCounter--;
      ltoR[i] = lrCounter;
    } else {
      lrCounter = 0;
    }
  }

  // 計算
  for (int i = 0; i < S.size(); i++) {
    if (ltoR[i] % 2 == 0) {
      ans[i + ltoR[i]] += 1;
    } else if (ltoR[i] < 0) {
      ans[i + ltoR[i] + 1] += 1;
    } else {
      ans[i + ltoR[i] - 1] += 1;
    }
  }

  // 出力
  for (int i = 0; i < S.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // sort(ALL())
#include <iomanip>
#include <iostream>
#include <map> // 連想配列 map<string, int>
#include <math.h>
#include <queue> // push(), front(), pop() 先入れ先出し
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin >> argument
#define prin(argument) cout << argument << endl
#define kaigyo cout << endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul = unsigned long;
using ll = long long;
using ld = long double;
using vint = vector<int>;
using vll = vector<ll>;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using vpint = vector<pint>;
using vpll = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu + eps)

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;

  int n = s.size();

  int dp[18][n];
  REP(i, n) { dp[0][i] = i; }
  REP(i, n) {
    if (s[i] == 'R')
      dp[1][i] = i + 1;
    else
      dp[1][i] = i - 1;
  }

  REP1(j, 17) {
    REP(i, n) { dp[j + 1][i] = dp[j][dp[j][i]]; }
  }

  vint ans(n);
  REP(i, n) { ans[dp[18][i]]++; }

  REP(i, n) { cout << ans[i] << " "; }

  return 0;
}


Fixed submission:
#include <algorithm> // sort(ALL())
#include <iomanip>
#include <iostream>
#include <map> // 連想配列 map<string, int>
#include <math.h>
#include <queue> // push(), front(), pop() 先入れ先出し
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin >> argument
#define prin(argument) cout << argument << endl
#define kaigyo cout << endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul = unsigned long;
using ll = long long;
using ld = long double;
using vint = vector<int>;
using vll = vector<ll>;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using vpint = vector<pint>;
using vpll = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu + eps)

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string s;
  cin >> s;

  int n = s.size();

  int dp[19][n];
  REP(i, n) { dp[0][i] = i; }
  REP(i, n) {
    if (s[i] == 'R')
      dp[1][i] = i + 1;
    else
      dp[1][i] = i - 1;
  }

  REP1(j, 17) {
    REP(i, n) { dp[j + 1][i] = dp[j][dp[j][i]]; }
  }

  vint ans(n);
  REP(i, n) { ans[dp[18][i]]++; }

  REP(i, n) { cout << ans[i] << " "; }

  return 0;
}
Problem p02954 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
string s;
int n, tot = 1, bp[50010] /*break point */, ans[100010];
// r1l0
inline void work(int l, int r, int bpt) {
  // cout<<l<<" "<<r<<" "<<bpt<<endl;
  if ((r - l + 1) % 2 == 0) {
    ans[bpt] = (r - l + 1) / 2;
    ans[bpt + 1] = (r - l + 1) / 2;
  } else {
    if ((bpt - l + 1) % 2 == 0) {
      ans[bpt] = (r - l + 1) / 2;
      ans[bpt + 1] = (r - l + 2) / 2;
    } else {
      ans[bpt] = (r - l + 2) / 2;
      ans[bpt + 1] = (r - l + 1) / 2;
    }
  }
}
int main() {
  cin >> s;
  n = s.size();
  if (n == 2) {
    cout << "1 1" << endl;
    return 0;
  }
  // fill(ans,ans+n,1);
  bp[0] = -1;
  for (int i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1]) {
      bp[tot++] = i;
    }
  }
  bp[tot++] = n - 1;
  for (int i = 0; i < tot - 1; i += 2) {
    work(bp[i] + 1, bp[i + 2], bp[i + 1]);
  }
  for (int i = 0; i < n; i++)
    cout << ans[i] << " ";
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
string s;
int n, tot = 1, bp[100010] /*break point */, ans[100010];
// r1l0
inline void work(int l, int r, int bpt) {
  // cout<<l<<" "<<r<<" "<<bpt<<endl;
  if ((r - l + 1) % 2 == 0) {
    ans[bpt] = (r - l + 1) / 2;
    ans[bpt + 1] = (r - l + 1) / 2;
  } else {
    if ((bpt - l + 1) % 2 == 0) {
      ans[bpt] = (r - l + 1) / 2;
      ans[bpt + 1] = (r - l + 2) / 2;
    } else {
      ans[bpt] = (r - l + 2) / 2;
      ans[bpt + 1] = (r - l + 1) / 2;
    }
  }
}
int main() {
  cin >> s;
  n = s.size();
  if (n == 2) {
    cout << "1 1" << endl;
    return 0;
  }
  // fill(ans,ans+n,1);
  bp[0] = -1;
  for (int i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1]) {
      bp[tot++] = i;
    }
  }
  bp[tot++] = n - 1;
  for (int i = 0; i < tot - 1; i += 2) {
    work(bp[i] + 1, bp[i + 2], bp[i + 1]);
  }
  for (int i = 0; i < n; i++)
    cout << ans[i] << " ";
  cout << endl;
  return 0;
}