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

Buggy submission (status: Runtime Error):
%:pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N = 1e5 + 5;

int n, x, top, pos;
LL len, a[N], t[N], suf[N];

inline int nex(LL x) { return lower_bound(a + 1, a + 1 + n, x) - a - 1; }
int main() {
  scanf("%d%d", &x, &n);
  a[1] = x;
  for (int i = 2; i <= n + 1; ++i)
    scanf("%lld", a + i);
  for (int i = 1; i <= n + 1; ++i) {
    while (top && a[top] >= a[i])
      --top;
    a[++top] = a[i];
  }
  n = top;
  t[n] = 1;
  for (int i = n; i > 1; --i) {
    len = a[i];
    pos = nex(len);
    while (pos) {
      t[pos] += t[i] * (len / a[pos]);
      len %= a[pos];
      pos = nex(pos);
    }
    if (len)
      suf[len] += t[i];
  }
  for (int i = a[1] - 1; ~i; --i)
    suf[i] += suf[i + 1];
  for (int i = 1; i <= a[1]; ++i)
    printf("%lld\n", suf[i] + t[1]);
  for (int i = a[1] + 1; i <= x; ++i)
    putchar('0'), putchar('\n');
  return 0;
}


Fixed submission:
%:pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int N = 1e5 + 5;

int n, x, top, pos;
LL len, a[N], t[N], suf[N];

inline int nex(LL x) { return lower_bound(a + 1, a + 1 + n, x) - a - 1; }
int main() {
  scanf("%d%d", &x, &n);
  a[1] = x;
  for (int i = 2; i <= n + 1; ++i)
    scanf("%lld", a + i);
  for (int i = 1; i <= n + 1; ++i) {
    while (top && a[top] >= a[i])
      --top;
    a[++top] = a[i];
  }
  n = top;
  t[n] = 1;
  for (int i = n; i > 1; --i) {
    len = a[i];
    pos = nex(len);
    while (pos) {
      t[pos] += t[i] * (len / a[pos]);
      len %= a[pos];
      pos = nex(len);
    }
    if (len)
      suf[len] += t[i];
  }
  for (int i = a[1] - 1; ~i; --i)
    suf[i] += suf[i + 1];
  for (int i = 1; i <= a[1]; ++i)
    printf("%lld\n", suf[i] + t[1]);
  for (int i = a[1] + 1; i <= x; ++i)
    putchar('0'), putchar('\n');
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

const int MAX_N = 100005;
typedef long long i64;

int N, Q, top;
i64 q[MAX_N], st[MAX_N], sum[MAX_N], val[MAX_N];

int main() {
  scanf("%d%d", &N, &Q);

  st[++top] = N;
  for (int i = 1; i <= Q; ++i) {
    scanf("%lld", &q[i]);
    while (top > 0 && st[top] >= q[i])
      top--;
    st[++top] = q[i];
  }

  val[top] = 1;
  for (int i = top; i; --i) {
    int temp = st[i], pos = i;
    while (true) {
      pos = lower_bound(st + 1, st + pos + 1, temp) - st - 1;
      if (pos == 0)
        break;
      val[pos] += val[i] * (temp / st[pos]);
      temp %= st[pos];
    }
    sum[temp] += val[i];
  }

  for (int i = N; i; --i)
    sum[i] += sum[i + 1];
  for (int i = 1; i <= N; ++i)
    printf("%lld\n", sum[i]);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;

const int MAX_N = 100005;
typedef long long i64;

int N, Q, top;
i64 q[MAX_N], st[MAX_N], sum[MAX_N], val[MAX_N];

int main() {
  scanf("%d%d", &N, &Q);

  st[++top] = N;
  for (int i = 1; i <= Q; ++i) {
    scanf("%lld", &q[i]);
    while (top > 0 && st[top] >= q[i])
      top--;
    st[++top] = q[i];
  }

  val[top] = 1;
  for (int i = top; i; --i) {
    i64 temp = st[i];
    int pos = i;
    while (true) {
      pos = lower_bound(st + 1, st + pos + 1, temp) - st - 1;
      if (pos == 0)
        break;
      val[pos] += val[i] * (temp / st[pos]);
      temp %= st[pos];
    }
    sum[temp] += val[i];
  }

  for (int i = N; i; --i)
    sum[i] += sum[i + 1];
  for (int i = 1; i <= N; ++i)
    printf("%lld\n", sum[i]);

  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
using namespace std;
int n, nn, q;
long long a[100001], ans[100001], num[100001];
stack<long long> s;
void solve(long long len, long long sum) {
  int pos = lower_bound(a + 1, a + nn + 1, len) - a - 1;
  if (!pos) {
    ans[1] += sum;
    ans[len + 1] -= sum;
    return;
  }
  num[pos] += len / a[pos] * sum;
  solve(len % a[pos], sum);
}
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &q);
  s.push(n);
  for (int i = 1; i <= q; i++) {
    long long x;
    scanf("%lld", &x);
    while (!s.empty() && x < s.top()) {
      s.pop();
    }
    s.push(x);
  }
  nn = s.size();
  for (int i = nn; i >= 1; i--) {
    a[i] = s.top();
    s.pop();
  }
  num[nn] = 1;
  for (int i = nn; i >= 1; i--) {
    solve(a[i], num[i]);
  }
  for (int i = 1; i <= n; i++) {
    ans[i] += ans[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <stack>
using namespace std;
int n, nn, q;
long long a[100005], ans[100005], num[100005];
stack<long long> s;
void solve(long long len, long long sum) {
  int pos = lower_bound(a + 1, a + nn + 1, len) - a - 1;
  if (!pos) {
    ans[1] += sum;
    ans[len + 1] -= sum;
    return;
  }
  num[pos] += len / a[pos] * sum;
  solve(len % a[pos], sum);
}
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &q);
  s.push(n);
  for (int i = 1; i <= q; i++) {
    long long x;
    scanf("%lld", &x);
    while (!s.empty() && x < s.top()) {
      s.pop();
    }
    s.push(x);
  }
  nn = s.size();
  for (int i = nn; i >= 1; i--) {
    a[i] = s.top();
    s.pop();
  }
  num[nn] = 1;
  for (int i = nn; i >= 1; i--) {
    solve(a[i], num[i]);
  }
  for (int i = 1; i <= n; i++) {
    ans[i] += ans[i - 1];
  }
  for (int i = 1; i <= n; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Time Limit Exceeded):
/************************************************
 * Au: Hany01
 * Date: Aug 16th, 2018
 * Prob: AGC003E
 * Email: hany01@foxmail.com
 * Inst: Yali High School
 ************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define For(i, j, k)                                                           \
  for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++i)
#define Fordown(i, j, k)                                                       \
  for (register int i = (j), i##_end_ = (k); i >= i##_end_; --i)
inline LL read() {
  static LL _, __;
  static char c_;
  for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar())
    if (c_ == '-')
      __ = -1;
  for (; c_ >= '0' && c_ <= '9'; c_ = getchar())
    _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
  return _ * __;
}
const int maxn = 1e5 + 5;
LL a[maxn], sm[maxn], c[maxn], t;
int n, N, m, p;
int main() {
#ifdef hany01
  freopen("agc003e.in", "r", stdin);
  freopen("agc003e.out", "w", stdout);
#endif
  for (N = a[n = 1] = read(), m = read(); m--;) {
    for (t = read(); n && t <= a[n]; --n)
      ;
    a[++n] = t;
  }
  sm[n] = 1;
  Fordown(i, n - 1,
          1) for (sm[i] += a[i + 1] / a[i] * sm[i + 1], t = a[i + 1] % a[i];
                  t;) if (p = upper_bound(a + 1, a + 1 + n, t) - a - 1) sm[p] +=
      (t / a[p]) * sm[i + 1];
  else c[t] += sm[i + 1], t = 0;
  c[a[1]] += sm[1];
  Fordown(i, N, 1) c[i] += c[i + 1];
  For(i, 1, N) printf("%lld\n", c[i]);
  return 0;
}

Fixed submission:
/************************************************
 * Au: Hany01
 * Date: Aug 16th, 2018
 * Prob: AGC003E
 * Email: hany01@foxmail.com
 * Inst: Yali High School
 ************************************************/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define For(i, j, k)                                                           \
  for (register int i = (j), i##_end_ = (k); i <= i##_end_; ++i)
#define Fordown(i, j, k)                                                       \
  for (register int i = (j), i##_end_ = (k); i >= i##_end_; --i)
inline LL read() {
  static LL _, __;
  static char c_;
  for (_ = 0, __ = 1, c_ = getchar(); c_ < '0' || c_ > '9'; c_ = getchar())
    if (c_ == '-')
      __ = -1;
  for (; c_ >= '0' && c_ <= '9'; c_ = getchar())
    _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
  return _ * __;
}
const int maxn = 1e5 + 5;
LL a[maxn], sm[maxn], c[maxn], t;
int n, N, m, p;
int main() {
#ifdef hany01
  freopen("agc003e.in", "r", stdin);
  freopen("agc003e.out", "w", stdout);
#endif
  for (N = a[n = 1] = read(), m = read(); m--;) {
    for (t = read(); n && t <= a[n]; --n)
      ;
    a[++n] = t;
  }
  sm[n] = 1;
  Fordown(i, n - 1,
          1) for (sm[i] += a[i + 1] / a[i] * sm[i + 1], t = a[i + 1] % a[i];
                  t;) if (p = upper_bound(a + 1, a + 1 + n, t) - a - 1) sm[p] +=
      (t / a[p]) * sm[i + 1],
      t %= a[p];
  else c[t] += sm[i + 1], t = 0;
  c[a[1]] += sm[1];
  Fordown(i, N, 1) c[i] += c[i + 1];
  For(i, 1, N) printf("%lld\n", c[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

typedef long long ll;

inline ll read() {
  ll x = 0;
  char ch = getchar();
  while (ch < '0' || '9' < ch)
    ch = getchar();
  while ('0' <= ch && ch <= '9')
    x = x * 10 + (ch ^ 48), ch = getchar();
  return x;
}

const int N = 1e5 + 9;

ll n, q;
ll a[N], top = 0;
ll cnt[N];
ll ans[N];

int main() {
  n = read();
  q = read();

  a[0] = n;
  for (int i = 1, x; i <= q; i++) {
    x = read();
    while (top >= 0 && a[top] >= x)
      top--;
    a[++top] = x;
  }

  cnt[top] = 1;
  for (int i = top; i; i--) {
    ll x = a[i];
    while (x >= a[0]) {
      int pos = upper_bound(a, a + i, x) - a - 1;
      cnt[pos] += x / a[pos] * cnt[i];
      x %= a[pos];
    }
    ans[x] += cnt[i];
  }

  ans[a[0]] += cnt[0];
  for (int i = n; i; --i)
    ans[i - 1] += ans[i];
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", ans[i]);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>

using namespace std;

typedef long long ll;

inline ll read() {
  ll x = 0;
  char ch = getchar();
  while (ch < '0' || '9' < ch)
    ch = getchar();
  while ('0' <= ch && ch <= '9')
    x = x * 10 + (ch ^ 48), ch = getchar();
  return x;
}

const int N = 1e5 + 9;

ll n, q;
ll a[N], top = 0;
ll cnt[N];
ll ans[N];

int main() {
  n = read();
  q = read();

  a[0] = n;
  for (int i = 1; i <= q; ++i) {
    ll x = read();
    if (x <= a[0])
      a[0] = x, top = 0;
    else {
      while (a[top] >= x)
        --top;
      a[++top] = x;
    }
  }

  cnt[top] = 1;
  for (int i = top; i; i--) {
    ll x = a[i];
    while (x >= a[0]) {
      int pos = upper_bound(a, a + i, x) - a - 1;
      cnt[pos] += x / a[pos] * cnt[i];
      x %= a[pos];
    }
    ans[x] += cnt[i];
  }

  ans[a[0]] += cnt[0];
  for (int i = n; i; --i)
    ans[i - 1] += ans[i];
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", ans[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll gi() {
  char c = getchar();
  ll x = 0;
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  return x;
}
const int N = 1e5 + 5;
ll a[N], num[N], ans[N];
int t, n, m;
int main() {
  n = gi(), t = gi();
  a[++m] = n;
  while (t--) {
    ll x = gi();
    for (; m && a[m] >= x; --m)
      ;
    a[++m] = x;
  }
  num[m] = 1;
  for (int i = m - 1; i; --i) {
    ll r = a[i + 1] % a[i];
    while (r > a[1]) {
      int p = upper_bound(a + 1, a + 1 + n, r) - a - 1;
      num[p] += num[i + 1] * (r / a[p]);
      r %= a[p];
    }
    ans[r] += num[i + 1];
    num[i] += num[i + 1] * (a[i + 1] / a[i]);
  }
  ans[a[1]] += num[1];
  for (int i = n; i; --i)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; ++i)
    printf("%lld ", ans[i]);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline ll gi() {
  char c = getchar();
  ll x = 0;
  for (; c < '0' || c > '9'; c = getchar())
    ;
  for (; c >= '0' && c <= '9'; c = getchar())
    x = (x << 1) + (x << 3) + c - '0';
  return x;
}
const int N = 1e5 + 5;
ll a[N], num[N], ans[N];
int t, n, m;
int main() {
  n = gi(), t = gi();
  a[++m] = n;
  while (t--) {
    ll x = gi();
    for (; m && a[m] >= x; --m)
      ;
    a[++m] = x;
  }
  num[m] = 1;
  for (int i = m - 1; i; --i) {
    ll r = a[i + 1] % a[i];
    while (r > a[1]) {
      int p = upper_bound(a + 1, a + 1 + m, r) - a - 1;
      num[p] += num[i + 1] * (r / a[p]);
      r %= a[p];
    }
    ans[r] += num[i + 1];
    num[i] += num[i + 1] * (a[i + 1] / a[i]);
  }
  ans[a[1]] += num[1];
  for (int i = n; i; --i)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; ++i)
    printf("%lld ", ans[i]);
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
// 2017-10-15
// miaomiao
//
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

#define LL long long
#define For(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for (int i = (a); i >= (int)(b); --i)

#define N (100000 + 5)

LL a[N], cnt[N], suf[N], ans[N];

int main() {
  int rn, n, Q, an = 0;
  LL rt, len, cs;

  scanf("%d%d", &n, &Q);

  a[++an] = 1ll * n;
  For(i, 1, Q) {
    scanf("%lld", &rt);
    while (an && a[an] >= rt)
      --an;
    a[++an] = rt;
  }

  rn = n;
  n = min((int)a[1], n);
  cnt[an] = 1;

  Forr(i, an, 2) {
    len = a[i];

    while (len >= a[1]) {
      int tp = lower_bound(a + 1, a + i, len) - a - 1;
      cnt[tp] += (cs = len / a[tp]) * cnt[i];
      len -= cs * a[tp];
    }

    suf[len] += cnt[i];
  }

  LL sum = 0;
  Forr(i, n, 1) sum += suf[i], ans[i] = cnt[1] + sum;
  For(i, 1, rn) printf("%lld\n", ans[i]);

  return 0;
}

Fixed submission:
// 2017-10-15
// miaomiao
//
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>

using namespace std;

#define LL long long
#define For(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define Forr(i, a, b) for (int i = (a); i >= (int)(b); --i)

#define N (100000 + 5)

LL a[N], cnt[N], suf[N], ans[N];

int main() {
  int rn, n, Q, an = 0;
  LL rt, len, cs;

  scanf("%d%d", &n, &Q);

  a[++an] = 1ll * n;
  For(i, 1, Q) {
    scanf("%lld", &rt);
    while (an && a[an] >= rt)
      --an;
    a[++an] = rt;
  }

  rn = n;
  n = min((int)a[1], n);
  cnt[an] = 1;

  Forr(i, an, 2) {
    len = a[i];

    while (len >= a[1]) {
      int tp = lower_bound(a + 1, a + i, len) - a - 1;
      if (tp == 0)
        tp = 1;

      cnt[tp] += (cs = len / a[tp]) * cnt[i];
      len -= cs * a[tp];
    }

    suf[len] += cnt[i];
  }

  LL sum = 0;
  Forr(i, n, 1) sum += suf[i], ans[i] = cnt[1] + sum;
  For(i, 1, rn) printf("%lld\n", ans[i]);

  return 0;
}
Problem p04023 (C++)

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

using namespace std;

const int MAXN = 1e5 + 10;

int n, Q;
vector<int> vec;
long long a[MAXN], b[MAXN];
long long answer[MAXN];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> Q;
  vec.push_back(n);
  for (int i = 1; i <= Q; i++) {
    long long q;
    cin >> q;
    while (vec.size() && vec.back() >= q)
      vec.pop_back();
    vec.push_back(q);
  }
  int z = vec.size();
  a[z - 1] = 1;
  for (int i = z - 1; ~i; i--) {
    long long local = vec[i];
    while (true) {
      int id = lower_bound(vec.begin(), vec.begin() + i, local) - vec.begin();
      if (id == 0) {
        b[local] += a[i];
        break;
      }
      a[id - 1] += a[i] * (local / vec[id - 1]);
      local %= vec[id - 1];
    }
  }
  for (int i = n; i; i--) {
    b[i] += b[i + 1];
  }
  for (int i = 1; i <= n; i++)
    cout << b[i] << '\n';
  return 0;
}

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

using namespace std;

const int MAXN = 1e5 + 10;

int n, Q;
vector<long long> vec;
long long a[MAXN], b[MAXN];
long long answer[MAXN];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> Q;
  vec.push_back(n);
  for (int i = 1; i <= Q; i++) {
    long long q;
    cin >> q;
    while (vec.size() && vec.back() >= q)
      vec.pop_back();
    vec.push_back(q);
  }
  int z = vec.size();
  a[z - 1] = 1;
  for (int i = z - 1; ~i; i--) {
    long long local = vec[i];
    while (true) {
      int id = lower_bound(vec.begin(), vec.begin() + i, local) - vec.begin();
      if (id == 0) {
        b[local] += a[i];
        break;
      }
      a[id - 1] += a[i] * (local / vec[id - 1]);
      local %= vec[id - 1];
    }
  }
  for (int i = n; i; i--) {
    b[i] += b[i + 1];
  }
  for (int i = 1; i <= n; i++)
    cout << b[i] << '\n';
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <math.h>
using namespace std;

const int MAXN = 1e5 + 10;
int N, Q;
long long A[MAXN], d[MAXN], t[MAXN];
long long ans, tot;

int main() {
  register int i;
  long long x;
  scanf("%d%d", &N, &Q);
  for (i = 1; i <= Q; ++i) {
    scanf("%lld", &x);
    while (tot && x <= A[tot])
      --tot;
    A[++tot] = x;
  }
  for (t[tot] = 1, i = tot; i; --i) {
    long long tmp = A[i], j = upper_bound(A + 1, A + i, tmp) - A - 1;
    for (; j; j = upper_bound(A, A + j, tmp) - A - 1)
      t[j] += (tmp / A[j]) * t[i], tmp %= A[j];
    d[1] += t[i], d[tmp + 1] -= t[i];
  }
  for (i = 1; i <= N; ++i)
    printf("%lld\n", ans += d[i]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <math.h>
using namespace std;

const int MAXN = 1e5 + 10;
int N, Q;
long long A[MAXN], d[MAXN], t[MAXN];
long long ans, tot;

int main() {
  register int i;
  long long x;
  scanf("%d%d", &N, &Q);
  A[++tot] = N;
  for (i = 1; i <= Q; ++i) {
    scanf("%lld", &x);
    while (tot && x <= A[tot])
      --tot;
    A[++tot] = x;
  }
  for (t[tot] = 1, i = tot; i; --i) {
    long long tmp = A[i], j = upper_bound(A + 1, A + i, tmp) - A - 1;
    for (; j; j = upper_bound(A, A + j, tmp) - A - 1)
      t[j] += (tmp / A[j]) * t[i], tmp %= A[j];
    d[1] += t[i], d[tmp + 1] -= t[i];
  }
  for (i = 1; i <= N; ++i)
    printf("%lld\n", ans += d[i]);
  return 0;
}
Problem p04023 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cctype>
#include <cstdio>
#define repu(i, x, y) for (int i = x; i <= y; ++i)
#define repd(i, x, y) for (int i = x; i >= y; --i)
using namespace std;

typedef long long LL;
int n, m, log_[100100];
LL len[100100], f[100100][20], ans[100100], cnt[100100];

LL getLL() {
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  LL x = ch - '0';
  for (; isdigit(ch = getchar()); x = x * 10 + ch - '0')
    ;
  return x;
}

void solve(int x, LL l, LL w) {
  while (x) {
    for (int i = log_[x]; i >= 0; i = min(i - 1, log_[x]))
      if (f[x][i] >= l)
        x -= 1 << i;
    if (x)
      cnt[x] += l / len[x] * w, l %= len[x];
  }
  ans[n] += l / n * w, ans[l % n] += w;
}

int main() {
  scanf("%d%d", &n, &m);
  if (!m) {
    repu(i, 1, n) puts("1");
    return 0;
  }
  repu(i, 1, m) len[i] = getLL();
  log_[0] = -1;
  repu(i, 2, m) log_[i] = log_[i >> 1] + 1;
  repu(i, 1, n) {
    f[i][0] = len[i];
    repu(j, 1, log_[i]) f[i][j] =
        min(f[i][j - 1], f[i - (1 << (j - 1))][j - 1]);
  }
  solve(m - 1, len[m], 1);
  repd(i, m - 1, 1) solve(i - 1, len[i], cnt[i]);
  repd(i, n, 1) ans[i] += ans[i + 1];
  repu(i, 1, n) printf("%lld\n", ans[i]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cstdio>
#define repu(i, x, y) for (int i = x; i <= y; ++i)
#define repd(i, x, y) for (int i = x; i >= y; --i)
using namespace std;

typedef long long LL;
int n, m, log_[100100];
LL len[100100], f[100100][20], ans[100100], cnt[100100];

LL getLL() {
  char ch;
  while (!isdigit(ch = getchar()))
    ;
  LL x = ch - '0';
  for (; isdigit(ch = getchar()); x = x * 10 + ch - '0')
    ;
  return x;
}

void solve(int x, LL l, LL w) {
  while (x) {
    for (int i = log_[x]; i >= 0; i = min(i - 1, log_[x]))
      if (f[x][i] >= l)
        x -= 1 << i;
    if (x)
      cnt[x] += l / len[x] * w, l %= len[x];
  }
  ans[n] += l / n * w, ans[l % n] += w;
}

int main() {
  scanf("%d%d", &n, &m);
  if (!m) {
    repu(i, 1, n) puts("1");
    return 0;
  }
  repu(i, 1, m) len[i] = getLL();
  log_[0] = -1;
  repu(i, 2, m) log_[i] = log_[i >> 1] + 1;
  repu(i, 1, m) {
    f[i][0] = len[i];
    repu(j, 1, log_[i]) f[i][j] =
        min(f[i][j - 1], f[i - (1 << (j - 1))][j - 1]);
  }
  solve(m - 1, len[m], 1);
  repd(i, m - 1, 1) solve(i - 1, len[i], cnt[i]);
  repd(i, n, 1) ans[i] += ans[i + 1];
  repu(i, 1, n) printf("%lld\n", ans[i]);
  return 0;
}
Problem p04023 (C++)

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

#define se second
#define fi first
#define mk(a, b) make_pair(a, b)

typedef long long ll;
typedef pair<ll, ll> pll;

int N, Q;
ll que[100010];
pll mem[100010];
vector<ll> V;
map<ll, ll, greater<ll>> mp;
map<ll, ll, greater<ll>>::iterator ite;
ll ans[100010] = {0};

int main() {
  scanf("%d%d", &N, &Q);
  for (int i = 0; i < Q; i++)
    scanf("%lld", que + i);

  pll MIN = mk(que[Q - 1], Q - 1);
  for (int i = Q - 1; i >= 0; i--) {
    if (que[i] < MIN.fi)
      MIN = mk(que[i], i);
    mem[i] = MIN;
  }
  for (int id = 0; id < Q; id++) {
    id = mem[id].se;
    V.push_back(mem[id].fi);
  }

  mp[V.back()] = 1;
  for (int i = V.size() - 1; i >= 0; i--) {
    vector<pll> W;
    for (ite = mp.begin(); ite != mp.end(); ite++) {
      if (V[i] >= ite->fi)
        break;
      W.push_back(mk(V[i], ite->fi / V[i] * ite->se));
      W.push_back(mk(ite->fi % V[i], ite->se));
    }
    while (mp.size() && mp.begin()->fi > V[i])
      mp.erase(mp.begin());
    for (int j = 0; j < W.size(); j++)
      mp[W[j].fi] += W[j].se;
  }

  for (ite = mp.begin(); ite != mp.end(); ite++)
    ans[ite->fi] += ite->se;
  for (int i = N - 1; i >= 1; i--)
    ans[i] += ans[i + 1];

  for (int i = 1; i <= N; i++)
    printf("%lld\n", ans[i]);
  return 0;
}


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

#define se second
#define fi first
#define mk(a, b) make_pair(a, b)

typedef long long ll;
typedef pair<ll, ll> pll;

int N, Q;
ll que[100010];
pll mem[100010];
vector<ll> V;
map<ll, ll, greater<ll>> mp;
map<ll, ll, greater<ll>>::iterator ite;
ll ans[100010] = {0};

int main() {
  scanf("%d%d", &N, &Q);
  for (int i = 0; i < Q; i++)
    scanf("%lld", que + i);

  pll MIN = mk(que[Q - 1], Q - 1);
  for (int i = Q - 1; i >= 0; i--) {
    if (que[i] < MIN.fi)
      MIN = mk(que[i], i);
    mem[i] = MIN;
  }
  V.push_back(N);
  for (int id = 0; id < Q; id++) {
    id = mem[id].se;
    V.push_back(mem[id].fi);
  }

  mp[V.back()] = 1;
  for (int i = V.size() - 1; i >= 0; i--) {
    vector<pll> W;
    for (ite = mp.begin(); ite != mp.end(); ite++) {
      if (V[i] >= ite->fi)
        break;
      W.push_back(mk(V[i], ite->fi / V[i] * ite->se));
      W.push_back(mk(ite->fi % V[i], ite->se));
    }
    while (mp.size() && mp.begin()->fi > V[i])
      mp.erase(mp.begin());
    for (int j = 0; j < W.size(); j++)
      mp[W[j].fi] += W[j].se;
  }

  for (ite = mp.begin(); ite != mp.end(); ite++)
    ans[ite->fi] += ite->se;
  for (int i = N - 1; i >= 1; i--)
    ans[i] += ans[i + 1];

  for (int i = 1; i <= N; i++)
    printf("%lld\n", ans[i]);
  return 0;
}
Problem p04023 (C++)

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

using ll = long long;

const int max_N = 1e5 + 21;

int n, q, top;

ll A, st[max_N], t[max_N], ans[max_N];

int main() {
  scanf("%d%d", &n, &q);
  st[++top] = n;
  for (int i = 1; i <= q; ++i) {
    scanf("%lld", &A);
    while (top && st[top] >= A)
      --top;
    st[++top] = A;
  }
  t[top] = 1;
  for (int i = top; i; --i) {
    int k = st[i];
    while (k > st[1]) {
      int j = std::lower_bound(st + 1, st + 1 + top, k) - st - 1;
      t[j] += t[i] * (k / st[j]);
      k %= st[j];
    }
    ans[k] += t[i];
  }
  for (int i = n; i; --i)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", ans[i]);
  return 0;
}

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

using ll = long long;

const int max_N = 1e5 + 21;

int n, q, top;

ll A, st[max_N], t[max_N], ans[max_N];

int main() {
  scanf("%d%d", &n, &q);
  st[++top] = n;
  for (int i = 1; i <= q; ++i) {
    scanf("%lld", &A);
    while (top && st[top] >= A)
      --top;
    st[++top] = A;
  }
  t[top] = 1;
  for (int i = top; i; --i) {
    ll k = st[i];
    while (k > st[1]) {
      int j = std::lower_bound(st + 1, st + 1 + top, k) - st - 1;
      t[j] += t[i] * (k / st[j]);
      k %= st[j];
    }
    ans[k] += t[i];
  }
  for (int i = n; i; --i)
    ans[i] += ans[i + 1];
  for (int i = 1; i <= n; ++i)
    printf("%lld\n", ans[i]);
  return 0;
}
Problem p04025 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> pii;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vi data(n), costs(201, 0);
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }

  for (int i = 0; i < n; i++) {
    int x = data[i];
    for (int y = -100; y <= 200; y++) {
      int diff = (x - y) * (x - y);
      costs[y + 100] += diff;
    }
  }

  int ans = INF;
  for (int i = 0; i < costs.size(); i++) {
    ans = min(ans, costs[i]);
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int, int> pii;
typedef long long ll;

int main() {
  int n;
  cin >> n;
  vi data(n), costs(201, 0);
  for (int i = 0; i < n; i++) {
    cin >> data[i];
  }

  for (int i = 0; i < n; i++) {
    int x = data[i];
    for (int y = -100; y <= 100; y++) {
      int diff = (x - y) * (x - y);
      costs[y + 100] += diff;
    }
  }

  int ans = INF;
  for (int i = 0; i < costs.size(); i++) {
    ans = min(ans, costs[i]);
  }
  cout << ans << endl;
}
Problem p04025 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<int> num;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  int cost = 1000000;
  for (int i = -200; i <= 200; i++) {
    int be = 0;
    for (int j = 0; j < n; j++) {
      be += (i - num[j]) * (i - num[j]);
    }
    cost = min(cost, be);
  }
  cout << cost;
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  long long n;
  vector<int> num(n);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  int cost = 1000000;
  for (int i = -200; i <= 200; i++) {
    int be = 0;
    for (int j = 0; j < n; j++) {
      be += (i - num[j]) * (i - num[j]);
    }
    cost = min(cost, be);
  }
  cout << cost;
  return 0;
}
Problem p04026 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <deque>   // deque
#include <iomanip>
#include <iostream>
#include <limits>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); }
ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); }

int main() {

  string S;
  cin >> S;
  rep(i, S.size() - 1) {
    if (i < S.size() - 1 && S.at(i) == S.at(i + 2)) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
    if (S.at(i) == S.at(i + 1)) {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
  }

  cout << "-1 -1" << endl;
}


Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio>  // printf
#include <deque>   // deque
#include <iomanip>
#include <iostream>
#include <limits>
#include <map> // map
#include <numeric>
#include <queue> // queue, priority_queue
#include <set>   // set
#include <stack> // stack
#include <stdio.h>
#include <string>        // string, to_string, stoi
#include <tuple>         // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) { return max(max(a, b), c); }
ll Min(ll(a), ll(b), ll(c)) { return min(min(a, b), c); }

int main() {

  string S;
  cin >> S;
  rep(i, S.size() - 1) {
    if (i < S.size() - 2 && S.at(i) == S.at(i + 2)) {
      cout << i + 1 << " " << i + 3 << endl;
      return 0;
    }
    if (S.at(i) == S.at(i + 1)) {
      cout << i + 1 << " " << i + 2 << endl;
      return 0;
    }
  }

  cout << "-1 -1" << endl;
}
Problem p04026 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  loop(t, 2, min(n + 1, 1000)) {
    int co[26] = {0};
    rep(i, t) co[s[i] - 'a']++;
    rep(i, 26) if (t / 2 < co[i]) {
      cout << 1 << " " << t << endl;
      goto end;
    }
    loop(i, t, n) {
      co[s[i] - 'a']++;
      co[s[i - t] - 'a']--;
      rep(j, 26) if (t / 2 < co[j]) {
        cout << i - t + 2 << " " << i + 1 << endl;
        goto end;
      }
    }
  }
  cout << "-1 -1" << endl;
end:;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int, pii> pip;
typedef vector<pip> vip;
const double PI = acos(-1);
const double EPS = 1e-8;
const int inf = 1e8;
int main() {
  string s;
  cin >> s;
  int n = s.size();
  loop(t, 2, min(n + 1, 100)) {
    int co[26] = {0};
    rep(i, t) co[s[i] - 'a']++;
    rep(i, 26) if (t / 2 < co[i]) {
      cout << 1 << " " << t << endl;
      goto end;
    }
    loop(i, t, n) {
      co[s[i] - 'a']++;
      co[s[i - t] - 'a']--;
      rep(j, 26) if (t / 2 < co[j]) {
        cout << i - t + 2 << " " << i + 1 << endl;
        goto end;
      }
    }
  }
  cout << "-1 -1" << endl;
end:;
}
Problem p04026 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define erep(i, a, b) for (int i = a; i <= (int)(b); ++i)
#define per(i, a, b) for (int i = (b); i > (a); --i)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; --i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  int a = -1, b = -1;
  rep(i, 0, s.size() - 3) {
    string sub = s.substr(i, 3);
    int k = max((int)sub.find(s[0], 1), (int)sub.find(s[1], 2));
    if (k > 0)
      a = i, b = i + 3;
  }
  cout << a << " " << b << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define erep(i, a, b) for (int i = a; i <= (int)(b); ++i)
#define per(i, a, b) for (int i = (b); i > (a); --i)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; --i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

string s;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  int a = -1, b = -1;
  rep(i, 0, s.size()) {
    if (i + 1 < s.size() && s[i] == s[i + 1]) {
      a = i + 1, b = i + 2;
      break;
    } else if (i + 2 < s.size() && s[i] == s[i + 2]) {
      a = i + 1, b = i + 3;
      break;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}
Problem p04026 (C++)

Buggy submission (status: Runtime Error):

#include <stdio.h>
#include <string.h>

char s[12345];

int main() {
  scanf("%s", s);
  int length = strlen(s);
  int ans1 = -1;
  int ans2 = -1;
  for (int i = 0; i < length - 1; ++i) {
    if (s[i] == s[i + 1]) {
      ans1 = i + 1;
      ans2 = i + 2;
    }
  }
  for (int i = 0; i < length - 2; ++i) {
    if (s[i] == s[i + 2]) {
      ans1 = i + 1;
      ans2 = i + 3;
    }
  }
  printf("%d %d\n", ans1, ans2);
  return 0;
}

Fixed submission:

#include <stdio.h>
#include <string.h>

char s[123456];

int main() {
  scanf("%s", s);
  int length = strlen(s);
  int ans1 = -1;
  int ans2 = -1;
  for (int i = 0; i < length - 1; ++i) {
    if (s[i] == s[i + 1]) {
      ans1 = i + 1;
      ans2 = i + 2;
    }
  }
  for (int i = 0; i < length - 2; ++i) {
    if (s[i] == s[i + 2]) {
      ans1 = i + 1;
      ans2 = i + 3;
    }
  }
  printf("%d %d\n", ans1, ans2);
  return 0;
}
Problem p04026 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#define MAX_S_LEN 100
// 本当は10^5まで
int get_len(char *p) {
  int i;
  for (i = 0; *p != '\0'; i++) {
    p++;
  }
  return i;
}

int main() {
  char input[MAX_S_LEN];

  scanf("%s", input);
  //    printf("LEN: %d\n", get_len(input));
  int i;
  int len = get_len(input);
  char back1;
  char back2;
  char *p = input;

  for (i = 0; i < len; i++) {
    if (i == 0) {
      back1 = '\0';
      back2 = '\0';
    } else if (i == 1) {
      back2 = '\0';
    }

    if (back1 == *p) {
      //      printf("GET DOUBLED!\n");
      printf("%d %d\n", i, i + 1);
      return 0;
    } else if (back2 == *p) {
      //      printf("GET HASSAMU!\n");
      printf("%d %d\n", i - 1, i + 1);
      return 0;
    }

    back2 = back1;
    back1 = *p;

    p++;
  }
  printf("%d %d\n", -1, -1);

  return 0;
}


Fixed submission:
#include <stdio.h>
#define MAX_S_LEN 100000
// 本当は10^5まで
int get_len(char *p) {
  int i;
  for (i = 0; *p != '\0'; i++) {
    p++;
  }
  return i;
}

int main() {
  char input[MAX_S_LEN];

  scanf("%s", input);
  //    printf("LEN: %d\n", get_len(input));
  int i;
  int len = get_len(input);
  char back1;
  char back2;
  char *p = input;

  for (i = 0; i < len; i++) {
    if (i == 0) {
      back1 = '\0';
      back2 = '\0';
    } else if (i == 1) {
      back2 = '\0';
    }

    if (back1 == *p) {
      //      printf("GET DOUBLED!\n");
      printf("%d %d\n", i, i + 1);
      return 0;
    } else if (back2 == *p) {
      //      printf("GET HASSAMU!\n");
      printf("%d %d\n", i - 1, i + 1);
      return 0;
    }

    back2 = back1;
    back1 = *p;

    p++;
  }
  printf("%d %d\n", -1, -1);

  return 0;
}
Problem p04026 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

string s;
int n;

bool f(string ss) {
  int len = 0;
  bool ans;
  len = ss.size();
  map<int, int> mp;
  for (int i = 0; i < len; i++) {
    mp[ss[i]]++;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ans = it->second * 2 > len;
    if (ans)
      break;
  }
  return ans;
}

int main() {
  cin >> s;
  n = s.size();
  bool bl = false;
  int a = -1, b = -1;
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < n - i + 1; j++) {
      string s0;
      for (int k = 0; k < i; k++) {
        s0 += s[j + k];
      }
      bl = f(s0);
      if (bl) {
        a = j + 1;
        b = j + i;
        cout << a << " " << b << endl;
        // cout << s0;
        // cin >> a;
        return 0;
      }
    }
  }

  cout << a << " " << b << endl;
  // cin >> a;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

string s;
int n;

bool f(string ss) {
  int len = 0;
  bool ans;
  len = ss.size();
  map<int, int> mp;
  for (int i = 0; i < len; i++) {
    mp[ss[i]]++;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    ans = it->second * 2 > len;
    if (ans)
      break;
  }
  return ans;
}

int main() {
  cin >> s;
  n = s.size();
  bool bl = false;
  int a = -1, b = -1;
  for (int i = 2; i <= min(n, 3); i++) {
    for (int j = 0; j < n - i + 1; j++) {
      string s0;
      for (int k = 0; k < i; k++) {
        s0 += s[j + k];
      }
      bl = f(s0);
      if (bl) {
        a = j + 1;
        b = j + i;
        cout << a << " " << b << endl;
        // cout << s0;
        // cin >> a;
        return 0;
      }
    }
  }

  cout << a << " " << b << endl;
  // cin >> a;
  return 0;
}
Problem p04026 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#define M 100005
using namespace std;
map<char, int> cnt;
char s[105];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int i, j;
  for (i = 0; i < n; i++) {
    if (s[i] == s[i + 1] && i + 1 < n) {
      printf("%d %d", i + 1, i + 1 + 1);
      return 0;
    }
    if (i + 2 < n && s[i] == s[i + 2]) {
      printf("%d %d", i + 1, i + 2 + 1);
      return 0;
    }
  }
  printf("-1 -1");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
#include <vector>
#define M 100005
using namespace std;
map<char, int> cnt;
char s[100005];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  int i, j;
  for (i = 0; i < n; i++) {
    if (s[i] == s[i + 1] && i + 1 < n) {
      printf("%d %d", i + 1, i + 1 + 1);
      return 0;
    }
    if (i + 2 < n && s[i] == s[i + 2]) {
      printf("%d %d", i + 1, i + 2 + 1);
      return 0;
    }
  }
  printf("-1 -1");
  return 0;
}
Problem p04026 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define RREP(i, n) for (int(i) = (int)(n)-1; (i) >= 0; (i)--)
#define REMOVE(Itr, n)                                                         \
  (Itr).erase(remove((Itr).begin(), (Itr).end(), n), (Itr).end())
#define PB_VEC(Itr1, Itr2)                                                     \
  (Itr1).insert((Itr1).end(), (Itr2).begin(), (Itr2).end())
#define UNIQUE(Itr)                                                            \
  sort((Itr).begin(), (Itr).end());                                            \
  (Itr).erase(unique((Itr).begin(), (Itr).end()), (Itr).end())

typedef long long ll;

string s;

pair<int, int> judge() {
  for (int i = 2; i <= s.size(); i++) {
    int alpha[26] = {};
    REP(j, i) alpha[s[j] - 'a']++;
    REP(k, 26) if (alpha[k] > i / 2) return make_pair(1, i);
    for (int j = i; j < s.size(); j++) {
      alpha[s[j - i] - 'a']--;
      alpha[s[j] - 'a']++;
      REP(k, 26) if (alpha[k] > i / 2) return make_pair(j - i + 2, j + 1);
    }
  }
  return make_pair(-1, -1);
}

int main() {

  cin >> s;
  pair<int, int> t = judge();
  cout << t.first << " " << t.second << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define RREP(i, n) for (int(i) = (int)(n)-1; (i) >= 0; (i)--)
#define REMOVE(Itr, n)                                                         \
  (Itr).erase(remove((Itr).begin(), (Itr).end(), n), (Itr).end())
#define PB_VEC(Itr1, Itr2)                                                     \
  (Itr1).insert((Itr1).end(), (Itr2).begin(), (Itr2).end())
#define UNIQUE(Itr)                                                            \
  sort((Itr).begin(), (Itr).end());                                            \
  (Itr).erase(unique((Itr).begin(), (Itr).end()), (Itr).end())

typedef long long ll;

string s;

pair<int, int> judge() {
  char c1 = s[0], c2 = s[1];
  if (c1 == c2)
    return make_pair(1, 2);
  for (int i = 2; i < s.size(); i++) {
    if (c1 == s[i])
      return make_pair(i - 1, i + 1);
    if (c2 == s[i])
      return make_pair(i, i + 1);
    c1 = c2;
    c2 = s[i];
  }
  return make_pair(-1, -1);
}

int main() {

  cin >> s;
  pair<int, int> t = judge();
  cout << t.first << " " << t.second << endl;

  return 0;
}
Problem p04026 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  for (int i = 0; i < S.size() - 1; i++) {
    if (S.at(i) == S.at(i + 1)) {
      cout << i + 1 << " " << i + 2 << endl;
      break;
    }
    if (i <= S.size() - 3) {
      if (S.at(i) == S.at(i + 2)) {
        cout << i + 1 << " " << i + 3 << endl;
        break;
      }
    } else if (i == S.size() - 2) {
      cout << -1 << " " << -1 << endl;
    }
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  for (int i = 0; i < S.size() - 1; i++) {
    if (S.at(i) == S.at(i + 1)) {
      cout << i + 1 << " " << i + 2 << endl;
      break;
    }
    if (S.size() == 2) {
      cout << -1 << " " << -1 << endl;
      break;
    }
    if (i <= S.size() - 3) {
      if (S.at(i) == S.at(i + 2)) {
        cout << i + 1 << " " << i + 3 << endl;
        break;
      }
    } else if (i == S.size() - 2) {
      cout << -1 << " " << -1 << endl;
    }
  }
}
Problem p04026 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;

int main() {
  string S;
  cin >> S;
  int s = -1, t = -1;
  if ((S.size() == 2) & (S[0] == S[1])) {
    s = 1;
    t = 2;
  }
  for (int i = 0; i < S.size() - 3; ++i) {
    if ((S[i] == S[i + 1]) | (S[i] == S[i + 2]) | (S[i + 1] == S[i + 2])) {
      s = i + 1;
      t = i + 3;
    }
  }
  cout << s << " " << t << endl;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;

int main() {
  string S;
  cin >> S;
  int s = -1, t = -1;
  if (S.size() == 2) {
    if (S[0] == S[1]) {
      s = 1;
      t = 2;
    }
  } else {
    for (int i = 0; i < S.size() - 3; ++i) {
      if ((S[i] == S[i + 1]) | (S[i] == S[i + 2]) | (S[i + 1] == S[i + 2])) {
        s = i + 1;
        t = i + 3;
      }
    }
  }
  cout << s << " " << t << endl;
}
Problem p04026 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  std::string s;
  std::cin >> s;
  for (int a = 0; a < int(s.length()); ++a) {
    int b = a + 1;
    int count[26] = {};
    count[s[a] - 'a'] = 1;
    while (b < int(s.length())) {
      ++count[s[b] - 'a'];
      if (count[s[b] - 'a'] * 2 > b - a + 1) {
        std::cout << a + 1 << ' ' << b + 1 << std::endl;
        return 0;
      }
      ++b;
    }
  }
  std::cout << "-1 -1" << std::endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  std::string s;
  std::cin >> s;
  for (int i = 0; i < int(s.length()) - 1; ++i) {
    if (s[i] == s[i + 1]) {
      std::cout << i + 1 << ' ' << i + 2 << std::endl;
      return 0;
    }
  }
  for (int i = 0; i < int(s.length()) - 2; ++i) {
    if (s[i] == s[i + 2]) {
      std::cout << i + 1 << ' ' << i + 3 << std::endl;
      return 0;
    }
  }
  std::cout << "-1 -1" << std::endl;
  return 0;
}