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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

// factorial&inverse factorial
ll fc[200010];
ll ifc[200010];

ll add(ll x, ll y) { return (x + y) % MOD; }
ll mlt(ll x, ll y) { return (x * y) % MOD; }

ll power(int x, int n) {
  ll ans = 1;
  while (n > 0) {
    if (n % 2 != 0) {
      ans = mlt(ans, x);
    }
    x = mlt(x, x);
    n /= 2;
  }
  return ans;
}

ll inv(ll x) { return power(x, MOD - 2); }

void fct() {
  fc[0] = 1;
  for (int i = 0; i < 200009; ++i) {
    fc[i + 1] = mlt(fc[i], i + 1);
  }
}

void ifct() {
  ifc[200009] = inv(fc[200009]);
  for (int i = 200009; i >= 1; --i) {
    ifc[i - 1] = mlt(ifc[i], i);
  }
}

ll comb(int n, int k) {
  if (n < 0 || k < 0 || k > n)
    return 0;
  return mlt(fc[n], mlt(ifc[k], ifc[n - k]));
}

int main() {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;

  ll dp[1010][1010] = {};
  dp[N][A - 1] = 1;
  fct();
  ifct();

  for (int j = A; j <= B; --j) {
    for (int i = 0; i <= N; ++i) {
      dp[i][j] = dp[i][j - 1];
      ll factor = 1;
      for (int k = 0; k++ < C - 1;) {
        factor = mlt(factor, comb(i + k * j, j));
      }

      for (int k = C; k <= D; ++k) {
        if (i + k * j > N)
          break;
        factor = mlt(factor, comb(i + k * j, j));
        dp[i][j] =
            add(dp[i][j], mlt(dp[i + k * j][j - 1], mlt(factor, ifc[k])));
      }
    }
  }

  cout << dp[0][B] << endl;
  return 0;
}


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

typedef long long ll;
const ll MOD = 1e9 + 7;

// factorial&inverse factorial
ll fc[200010];
ll ifc[200010];

ll add(ll x, ll y) { return (x + y) % MOD; }
ll mlt(ll x, ll y) { return (x * y) % MOD; }

ll power(int x, int n) {
  ll ans = 1;
  while (n > 0) {
    if (n % 2 != 0) {
      ans = mlt(ans, x);
    }
    x = mlt(x, x);
    n /= 2;
  }
  return ans;
}

ll inv(ll x) { return power(x, MOD - 2); }

void fct() {
  fc[0] = 1;
  for (int i = 0; i < 200009; ++i) {
    fc[i + 1] = mlt(fc[i], i + 1);
  }
}

void ifct() {
  ifc[200009] = inv(fc[200009]);
  for (int i = 200009; i >= 1; --i) {
    ifc[i - 1] = mlt(ifc[i], i);
  }
}

ll comb(int n, int k) {
  if (n < 0 || k < 0 || k > n)
    return 0;
  return mlt(fc[n], mlt(ifc[k], ifc[n - k]));
}

int main() {
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;

  ll dp[1010][1010] = {};
  dp[N][A - 1] = 1;
  fct();
  ifct();

  for (int j = A; j <= B; ++j) {
    for (int i = 0; i <= N; ++i) {
      dp[i][j] = dp[i][j - 1];
      ll factor = 1;
      for (int k = 0; k++ < C - 1;) {
        factor = mlt(factor, comb(i + k * j, j));
      }

      for (int k = C; k <= D; ++k) {
        if (i + k * j > N)
          break;
        factor = mlt(factor, comb(i + k * j, j));
        dp[i][j] =
            add(dp[i][j], mlt(dp[i + k * j][j - 1], mlt(factor, ifc[k])));
      }
    }
  }

  cout << dp[0][B] << endl;
  return 0;
}
Problem p03833 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <cstdio>
const int MAXN = 5e3 + 5;

int b[MAXN][MAXN], n, m;
long long a[MAXN], sum[MAXN][MAXN];
int l[MAXN];
int stack[MAXN], top;

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n - 1; i++)
    scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &b[i][j]);

  for (int j = 1; j <= m; j++) {
    top = 0;
    stack[top++] = 0;
    for (int i = 1; i <= n; i++) {
      while (top > 1 && b[stack[top - 1]][j] < b[i][j])
        top--;
      l[i] = stack[top - 1];
      stack[top++] = i;
    }
    top = 0;
    stack[top++] = n + 1;
    for (int i = n; i >= 1; i--) {
      while (top > 1 && b[stack[top - 1]][j] < b[i][j])
        top--;
      int r = stack[top - 1];
      sum[l[i] + 1][i] += b[i][j];
      sum[l[i] + 1][r] -= b[i][j];
      sum[i + 1][i] -= b[i][j];
      sum[i + 1][r] += b[i][j];
      stack[top++] = i;
    }
  }
  for (int i = 2; i <= n - 1; i++)
    a[i] += a[i - 1];
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      if (i <= j) {
        long long cur = a[j - 1] - a[i - 1];
        cur = sum[i][j] - cur;
        if (ans < cur)
          ans = cur;
      }
    }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <cstdio>
const int MAXN = 5e3 + 5;

int b[MAXN][205], n, m;
long long a[MAXN], sum[MAXN][MAXN];
int l[MAXN];
int stack[MAXN], top;

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n - 1; i++)
    scanf("%lld", &a[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &b[i][j]);

  for (int j = 1; j <= m; j++) {
    top = 0;
    stack[top++] = 0;
    for (int i = 1; i <= n; i++) {
      while (top > 1 && b[stack[top - 1]][j] < b[i][j])
        top--;
      l[i] = stack[top - 1];
      stack[top++] = i;
    }
    top = 0;
    stack[top++] = n + 1;
    for (int i = n; i >= 1; i--) {
      while (top > 1 && b[stack[top - 1]][j] < b[i][j])
        top--;
      int r = stack[top - 1];
      sum[l[i] + 1][i] += b[i][j];
      sum[l[i] + 1][r] -= b[i][j];
      sum[i + 1][i] -= b[i][j];
      sum[i + 1][r] += b[i][j];
      stack[top++] = i;
    }
  }
  for (int i = 2; i <= n - 1; i++)
    a[i] += a[i - 1];
  long long ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) {
      sum[i][j] += sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1];
      if (i <= j) {
        long long cur = a[j - 1] - a[i - 1];
        cur = sum[i][j] - cur;
        if (ans < cur)
          ans = cur;
      }
    }
  printf("%lld\n", ans);
  return 0;
}
Problem p03833 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define lol(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 5010
#define M 210
ll a[M][N], A[M][N], b[N], B[N], n, m;
int main() {
  cin >> n >> m;
  lol(i, n - 1) {
    cin >> B[i];
    b[i + 2] = B[i];
  }
  lol(i, n) lol(j, m) {
    // cin>>a[j][i];
    scanf("%lld", &a[i][j]);
  }
  lol(i, m) {
    A[i][0] = 0;
    ll maxi = 0;
    lol(j, n) {
      maxi = max(maxi, a[i][j]);
      A[i][j + 1] = maxi;
    }
  }
  b[0] = b[1] = 0;
  lol(i, n) b[i + 1] += b[i];
  lol(i, n + 1) {
    b[i] = -b[i];
    lol(j, m) b[i] += A[j][i];
    // cout<<b[i]<<" ";
  } // cout<<endl;
  ll ans = 0;

  lol(i, n) {
    ll gre = -1;
    for (int j = i + 1; j <= n; j++) {
      gre = max(gre, b[j]);
    }
    ans = max(ans, gre);
    // cout<<gre<<endl;
    lol(j, m) {
      ll maxi = -1;
      for (int k = i + 1; k < n; k++) {
        if (a[j][k] >= a[j][i])
          break;
        maxi = max(maxi, a[j][k]);
        b[k + 1] -= A[j][k + 1];
        A[j][k + 1] = maxi;
        b[k + 1] += A[j][k + 1];
      }
    }
    for (int j = i + 1; j <= n; j++)
      b[j] += B[i];
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define lol(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
#define N 5010
#define M 210
ll a[M][N], A[M][N], b[N], B[N], n, m;
int main() {
  cin >> n >> m;
  lol(i, n - 1) {
    cin >> B[i];
    b[i + 2] = B[i];
  }
  lol(i, n) lol(j, m) {
    // cin>>a[j][i];
    scanf("%lld", &a[j][i]);
  }
  lol(i, m) {
    A[i][0] = 0;
    ll maxi = 0;
    lol(j, n) {
      maxi = max(maxi, a[i][j]);
      A[i][j + 1] = maxi;
    }
  }
  b[0] = b[1] = 0;
  lol(i, n) b[i + 1] += b[i];
  lol(i, n + 1) {
    b[i] = -b[i];
    lol(j, m) b[i] += A[j][i];
    // cout<<b[i]<<" ";
  } // cout<<endl;
  ll ans = 0;

  lol(i, n) {
    ll gre = -1;
    for (int j = i + 1; j <= n; j++) {
      gre = max(gre, b[j]);
    }
    ans = max(ans, gre);
    // cout<<gre<<endl;
    lol(j, m) {
      ll maxi = -1;
      for (int k = i + 1; k < n; k++) {
        if (a[j][k] >= a[j][i])
          break;
        maxi = max(maxi, a[j][k]);
        b[k + 1] -= A[j][k + 1];
        A[j][k + 1] = maxi;
        b[k + 1] += A[j][k + 1];
      }
    }
    for (int j = i + 1; j <= n; j++)
      b[j] += B[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p03833 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
#define LL long long
int A[N], B[N][N], L[N], R[N], S[N];
LL sum[N][N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++)
    scanf("%d", &A[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &B[i][j]);
  for (int i = 1; i <= m; i++) {
    int top = 0;
    for (int j = 1; j <= n; j++) {
      while (top && B[j][i] > B[S[top]][i])
        R[S[top--]] = j;
      L[j] = S[top];
      S[++top] = j;
    }
    for (int j = 1; j <= top; j++)
      R[S[j]] = n + 1;
    /*for (int j = 1; j <= n; j++)
            printf("[%d,%d] ", L[j], R[j]);
    puts("");*/
    for (int j = 1; j <= n; j++) {
      sum[L[j] + 1][j] += B[j][i];
      sum[L[j] + 1][R[j]] -= B[j][i];
      sum[j + 1][j] -= B[j][i];
      sum[j + 1][R[j]] += B[j][i];
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      sum[i][j] += sum[i][j - 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      sum[i][j] += sum[i - 1][j];
  LL ans = 0;
  for (int i = 1; i <= n; i++) {
    LL tmp = 0;
    for (int j = i; j <= n; j++) {
      ans = max(ans, sum[i][j] - tmp);
      /*if (ans == 13) {
              printf("%d %d %d %d\n", i, j, sum[i][j], tmp);
              return 0;
      }*/
      tmp += A[j];
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 10;
#define LL long long
int A[N], B[N][210], L[N], R[N], S[N];
LL sum[N][N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; i++)
    scanf("%d", &A[i]);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%d", &B[i][j]);
  for (int i = 1; i <= m; i++) {
    int top = 0;
    for (int j = 1; j <= n; j++) {
      while (top && B[j][i] > B[S[top]][i])
        R[S[top--]] = j;
      L[j] = S[top];
      S[++top] = j;
    }
    for (int j = 1; j <= top; j++)
      R[S[j]] = n + 1;
    /*for (int j = 1; j <= n; j++)
            printf("[%d,%d] ", L[j], R[j]);
    puts("");*/
    for (int j = 1; j <= n; j++) {
      sum[L[j] + 1][j] += B[j][i];
      sum[L[j] + 1][R[j]] -= B[j][i];
      sum[j + 1][j] -= B[j][i];
      sum[j + 1][R[j]] += B[j][i];
    }
  }
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      sum[i][j] += sum[i][j - 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      sum[i][j] += sum[i - 1][j];
  LL ans = 0;
  for (int i = 1; i <= n; i++) {
    LL tmp = 0;
    for (int j = i; j <= n; j++) {
      ans = max(ans, sum[i][j] - tmp);
      /*if (ans == 13) {
              printf("%d %d %d %d\n", i, j, sum[i][j], tmp);
              return 0;
      }*/
      tmp += A[j];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03833 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct nod {
  int p, l, r;
  long long w;
  nod(int p = 0, int l = 0, int r = 0, long long w = 0)
      : p(p), l(l), r(r), w(w) {}
} a[1000005];
bool operator<(nod a, nod b) { return a.p < b.p; }
int n, m, L[5005], R[5005], cur = 1, t;
long long s[5005], c[5005], ans, dis[5005], b[5005][205];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; i++)
    scanf("%lld", &dis[i]), dis[i] += dis[i - 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%lld", &b[i][j]);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++)
      for (L[j] = j - 1; L[j] >= 1 && b[L[j]][i] < b[j][i]; L[j] = L[L[j]])
        ;
    for (int j = n; j >= 1; j--)
      for (R[j] = j + 1; R[j] <= n && b[R[j]][i] < b[j][i]; R[j] = R[R[j]])
        ;
    for (int j = 1; j <= n; j++)
      a[++t] = nod(L[j] + 1, j, R[j] - 1, b[j][i]),
      a[++t] = nod(j + 1, j, R[j] - 1, -b[j][i]);
  }
  sort(a + 1, a + t + 1);
  for (int i = 1; i <= n; i++) {
    for (memset(c, 0, sizeof(c)); cur <= t && a[cur].p == i; cur++)
      c[a[cur].l] += a[cur].w, c[a[cur].r + 1] -= a[cur].w;
    for (int j = 1; j <= n; j++)
      c[j] += c[j - 1], s[j] += c[j],
          ans = max(ans, j < i ? ans : s[j] - dis[j] + dis[i]);
  }
  printf("%lld\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
struct nod {
  int p, l, r;
  long long w;
  nod(int p = 0, int l = 0, int r = 0, long long w = 0)
      : p(p), l(l), r(r), w(w) {}
} a[2000005];
bool operator<(nod a, nod b) { return a.p < b.p; }
int n, m, L[5005], R[5005], cur = 1, t;
long long s[5005], c[5005], ans, dis[5005], b[5005][205];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; i++)
    scanf("%lld", &dis[i]), dis[i] += dis[i - 1];
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      scanf("%lld", &b[i][j]);
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= n; j++)
      for (L[j] = j - 1; L[j] >= 1 && b[L[j]][i] < b[j][i]; L[j] = L[L[j]])
        ;
    for (int j = n; j >= 1; j--)
      for (R[j] = j + 1; R[j] <= n && b[R[j]][i] < b[j][i]; R[j] = R[R[j]])
        ;
    for (int j = 1; j <= n; j++)
      a[++t] = nod(L[j] + 1, j, R[j] - 1, b[j][i]),
      a[++t] = nod(j + 1, j, R[j] - 1, -b[j][i]);
  }
  sort(a + 1, a + t + 1);
  for (int i = 1; i <= n; i++) {
    for (memset(c, 0, sizeof(c)); cur <= t && a[cur].p == i; cur++)
      c[a[cur].l] += a[cur].w, c[a[cur].r + 1] -= a[cur].w;
    for (int j = 1; j <= n; j++)
      c[j] += c[j - 1], s[j] += c[j],
          ans = max(ans, j < i ? ans : s[j] - dis[j] + dis[i]);
  }
  printf("%lld\n", ans);
}
Problem p03833 (C++)

Buggy submission (status: Memory Limit Exceeded):
// Ala be zekrellah tatmaenolgholoob ...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define MP make_pair
const int maxn = 5e3 + 9;
const ll mod = 1e9 + 7;

stack<int> st[205];
ll a[maxn], b[maxn][maxn], sum[maxn], dp[maxn][maxn];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    for (int t = 1; t <= m; t++)
      cin >> b[i][t];
  // dp
  for (int e = 1; e <= n; e++) {
    memset(sum, 0, sizeof sum);
    ll last = 0;
    for (int s = 1; s <= e; s++)
      dp[s][e] = dp[s][e - 1];
    for (int i = 1; i <= m; i++) {
      // add col[i] and update
      last = 0;
      sum[e] += b[e][i];
      while (st[i].size() && b[st[i].top()][i] < b[e][i]) {
        sum[st[i].top()] += last;
        last = b[st[i].top()][i];
        sum[st[i].top()] -= last;
        st[i].pop();
      }
      if (st[i].size()) {
        sum[st[i].top()] -= b[e][i];
        sum[st[i].top()] += last;
      }
      st[i].push(e);
    }
    // update from sum
    for (int s = e; s >= 1; s--) {
      sum[s] += sum[s + 1];
      dp[s][e] += sum[s];
    }
  }
  // ans
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll f = 0;
    for (int t = i; t <= n; t++) {
      ans = max(ans, dp[i][t] - f);
      f += a[t];
    }
  }
  cout << ans << "\n";
}


Fixed submission:
// Ala be zekrellah tatmaenolgholoob ...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define MP make_pair
const int maxn = 5e3 + 9;
const ll mod = 1e9 + 7;

stack<int> st[205];
ll a[maxn], b[maxn][205], sum[maxn], dp[maxn][maxn];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i < n; i++)
    cin >> a[i];
  for (int i = 1; i <= n; i++)
    for (int t = 1; t <= m; t++)
      cin >> b[i][t];
  // dp
  for (int e = 1; e <= n; e++) {
    memset(sum, 0, sizeof sum);
    ll last = 0;
    for (int s = 1; s <= e; s++)
      dp[s][e] = dp[s][e - 1];
    for (int i = 1; i <= m; i++) {
      // add col[i] and update
      last = 0;
      sum[e] += b[e][i];
      while (st[i].size() && b[st[i].top()][i] < b[e][i]) {
        sum[st[i].top()] += last;
        last = b[st[i].top()][i];
        sum[st[i].top()] -= last;
        st[i].pop();
      }
      if (st[i].size()) {
        sum[st[i].top()] -= b[e][i];
        sum[st[i].top()] += last;
      }
      st[i].push(e);
    }
    // update from sum
    for (int s = e; s >= 1; s--) {
      sum[s] += sum[s + 1];
      dp[s][e] += sum[s];
    }
  }
  // ans
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll f = 0;
    for (int t = i; t <= n; t++) {
      ans = max(ans, dp[i][t] - f);
      f += a[t];
    }
  }
  cout << ans << "\n";
}
Problem p03833 (C++)

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

#define st first
#define nd second

using namespace std;

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

const int MAXN = 533 + 10, MAXM = 2E2 + 10;

int n, m;
int a[MAXN];
int b[MAXN][MAXM];
ll c[MAXN][MAXN];

PII lst[MAXN];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i)
    scanf("%d", a + i);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      scanf("%d", b[i] + j);
  for (int i = 1; i <= m; ++i) {
    set<int> st;
    st.insert(0), st.insert(n + 1);
    for (int j = 1; j <= n; ++j) {
      lst[j] = PII(b[j][i], j);
      st.insert(j);
    }
    sort(lst + 1, lst + n + 1);
    for (int j = 1; j <= n; ++j) {
      int u = lst[j].nd;
      auto p = st.find(u);
      int l = *prev(p) + 1, r = *next(p) - 1;
      st.erase(p);
      c[l][u] += lst[j].st, c[u + 1][r + 1] += lst[j].st;
      c[l][r + 1] -= lst[j].st, c[u + 1][u] -= lst[j].st;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j)
      c[i][j] += c[i][j - 1];
    ll dist = 0;
    for (int j = i; j <= n; ++j) {
      c[i][j] += c[i - 1][j];
      ans = max(ans, c[i][j] - dist);
      dist += a[j];
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <set>
#include <utility>

#define st first
#define nd second

using namespace std;

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

const int MAXN = 5E3 + 10, MAXM = 2E2 + 10;

int n, m;
int a[MAXN];
int b[MAXN][MAXM];
ll c[MAXN][MAXN];

PII lst[MAXN];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n; ++i)
    scanf("%d", a + i);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= m; ++j)
      scanf("%d", b[i] + j);
  for (int i = 1; i <= m; ++i) {
    set<int> st;
    st.insert(0), st.insert(n + 1);
    for (int j = 1; j <= n; ++j) {
      lst[j] = PII(b[j][i], j);
      st.insert(j);
    }
    sort(lst + 1, lst + n + 1);
    for (int j = 1; j <= n; ++j) {
      int u = lst[j].nd;
      auto p = st.find(u);
      int l = *prev(p) + 1, r = *next(p) - 1;
      st.erase(p);
      c[l][u] += lst[j].st, c[u + 1][r + 1] += lst[j].st;
      c[l][r + 1] -= lst[j].st, c[u + 1][u] -= lst[j].st;
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j)
      c[i][j] += c[i][j - 1];
    ll dist = 0;
    for (int j = i; j <= n; ++j) {
      c[i][j] += c[i - 1][j];
      ans = max(ans, c[i][j] - dist);
      dist += a[j];
    }
  }
  printf("%lld\n", ans);
  return 0;
}
Problem p03833 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
#define N 5005
#define ll long long
using namespace std;
int n, m;
int st[N], top;
int a[N][N], l[N], r[N];
ll f[N][N];
void add(int x1, int y1, int x2, int y2, int z) {
  f[x1][y1] += z;
  f[x2 + 1][y2 + 1] += z;
  f[x1][y2 + 1] -= z;
  f[x2 + 1][y1] -= z;
}
ll sum[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; i++) {
    int tmp;
    scanf("%d", &tmp);
    sum[i] = sum[i - 1] + tmp;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 1; i <= m; i++) {
    memset(l, 0, sizeof(l));
    memset(r, 0, sizeof(r));
    top = 0;
    for (int j = 1; j <= n; j++) {
      while (top && a[st[top]][i] <= a[j][i])
        r[st[top--]] = j;
      st[++top] = j;
    }
    while (top)
      r[st[top]] = n + 1, top--;
    for (int j = n; j >= 1; j--) {
      while (top && a[st[top]][i] < a[j][i])
        l[st[top--]] = j;
      st[++top] = j;
    }
    for (int j = 1; j <= n; j++) {
      add(l[j] + 1, j, j, r[j] - 1, a[j][i]);
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      f[i][j] += -f[i - 1][j - 1] + f[i - 1][j] + f[i][j - 1];
      if (j >= i)
        ans = max(ans, f[i][j] - sum[j] + sum[i]);
    }
  }
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define N 5005
#define ll long long
using namespace std;
int n, m;
int st[N], top;
int a[N][205], l[N], r[N];
ll f[N][N];
void add(int x1, int y1, int x2, int y2, int z) {
  f[x1][y1] += z;
  f[x2 + 1][y2 + 1] += z;
  f[x1][y2 + 1] -= z;
  f[x2 + 1][y1] -= z;
}
ll sum[N];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 2; i <= n; i++) {
    int tmp;
    scanf("%d", &tmp);
    sum[i] = sum[i - 1] + tmp;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= m; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  for (int i = 1; i <= m; i++) {
    memset(l, 0, sizeof(l));
    memset(r, 0, sizeof(r));
    top = 0;
    for (int j = 1; j <= n; j++) {
      while (top && a[st[top]][i] <= a[j][i])
        r[st[top--]] = j;
      st[++top] = j;
    }
    while (top)
      r[st[top]] = n + 1, top--;
    for (int j = n; j >= 1; j--) {
      while (top && a[st[top]][i] < a[j][i])
        l[st[top--]] = j;
      st[++top] = j;
    }
    for (int j = 1; j <= n; j++) {
      add(l[j] + 1, j, j, r[j] - 1, a[j][i]);
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      f[i][j] += -f[i - 1][j - 1] + f[i - 1][j] + f[i][j - 1];
      if (j >= i)
        ans = max(ans, f[i][j] - sum[j] + sum[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03833 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<ll> A(N - 1);
  vector<vector<ll>> B(N + 1, vector<ll>(M));
  for (int i = 0; i < N - 1; ++i)
    cin >> A[i];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      cin >> B[i][j];
    }
  }
  vector<vector<ll>> C(N + 1, vector<ll>(M, 0));
  vector<ll> imos(N, 0);
  for (int j = 0; j < M; ++j) {
    stack<int> st;
    B[N][j] = 1 << 30;
    st.emplace(N);
    C[N][j] = N;
    for (int i = N - 1; i >= 0; --i) {
      while (!st.empty() && B[st.top()][j] < B[i][j])
        st.pop();
      C[i][j] = st.top();
      st.emplace(i);
    }
    for (int i = 0; i < N;) {
      imos[C[i][j]] += B[C[i][j]][j] - B[i][j];
      i = C[i][j];
    }
  }
  ll ans = 0;
  for (int l = 0; l < N; ++l) {
    ll sum = 0;
    for (int i = 0; i < M; ++i)
      sum += B[l][i];
    ans = max(ans, sum);
    for (int r = l + 1; r < N; ++r) {
      sum += imos[r] - A[r - 1];
      ans = max(ans, sum);
    }
    for (int i = 0; i < M; ++i) {
      int j = C[l][i];
      imos[j] -= B[j][i] - B[l][i];
      for (int k = l + 1; k < j;) {
        imos[C[k][i]] += B[C[k][i]][i] - B[k][i];
        k = C[k][i];
      }
    }
  }
  cout << ans << '\n';
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<ll> A(N - 1);
  vector<vector<ll>> B(N + 1, vector<ll>(M));
  for (int i = 0; i < N - 1; ++i)
    cin >> A[i];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < M; ++j) {
      cin >> B[i][j];
    }
  }
  vector<vector<ll>> C(N + 1, vector<ll>(M, 0));
  vector<ll> imos(N + 1, 0);
  for (int j = 0; j < M; ++j) {
    stack<int> st;
    B[N][j] = 1 << 30;
    st.emplace(N);
    C[N][j] = N;
    for (int i = N - 1; i >= 0; --i) {
      while (!st.empty() && B[st.top()][j] < B[i][j])
        st.pop();
      C[i][j] = st.top();
      st.emplace(i);
    }
    for (int i = 0; i < N;) {
      imos[C[i][j]] += B[C[i][j]][j] - B[i][j];
      i = C[i][j];
    }
  }
  ll ans = 0;
  for (int l = 0; l < N; ++l) {
    ll sum = 0;
    for (int i = 0; i < M; ++i)
      sum += B[l][i];
    ans = max(ans, sum);
    for (int r = l + 1; r < N; ++r) {
      sum += imos[r] - A[r - 1];
      ans = max(ans, sum);
    }
    for (int i = 0; i < M; ++i) {
      int j = C[l][i];
      imos[j] -= B[j][i] - B[l][i];
      for (int k = l + 1; k < j;) {
        imos[C[k][i]] += B[C[k][i]][i] - B[k][i];
        k = C[k][i];
      }
    }
  }
  cout << ans << '\n';
}
Problem p03833 (C++)

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

const int N = 5e3 + 7;
const int SS = 4 * N;
const int INF = 1e9 + 7;
const int M = 2e2 + 7;

ll mx[SS], lazy[SS];
ll a[M][N], x[N];
int n, m;
stack<int> st[M];

void update(int v, ll val) {
  mx[v] += val;
  lazy[v] += val;
}

void shift(int v) {
  update(2 * v, lazy[v]);
  update(2 * v + 1, lazy[v]);
  lazy[v] = 0;
}

void merge(int v) { mx[v] = max(mx[2 * v], mx[2 * v + 1]); }

void add(int l, int r, ll val, int s = 0, int e = n, int v = 1) {
  if (l >= e || r <= s)
    return;
  if (l <= s && e <= r) {
    update(v, val);
    return;
  }
  shift(v);
  int mid = (s + e) / 2;
  add(l, r, val, s, mid, 2 * v);
  add(l, r, val, mid, e, 2 * v + 1);
  merge(v);
}

int main() {
  ios::sync_with_stdio(false);

  cin >> n >> m;
  for (int i = 1; i < n; i++)
    cin >> x[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> a[i][j];
  for (int i = 0; i < m; i++)
    st[i].push(n);
  ll ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      ll cnt = 0;
      while (st[j].top() != n && a[st[j].top()][j] < a[i][j]) {
        add(i, st[j].top(), a[st[j].top()][j] - cnt);
        cnt = a[st[j].top()][j];
        st[j].pop();
      }
      add(i, st[j].top(), a[i][j] - cnt);
      st[j].push(i);
    }
    add(i + 1, n, -x[i + 1]);
    ans = max(ans, 1LL * mx[1]);
  }
  cout << ans << "\n";
  return 0;
}

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

const int N = 5e3 + 7;
const int SS = 4 * N;
const int INF = 1e9 + 7;
const int M = 2e2 + 7;

ll mx[SS], lazy[SS];
ll a[N][M], x[N];
int n, m;
stack<int> st[M];

void update(int v, ll val) {
  mx[v] += val;
  lazy[v] += val;
}

void shift(int v) {
  update(2 * v, lazy[v]);
  update(2 * v + 1, lazy[v]);
  lazy[v] = 0;
}

void merge(int v) { mx[v] = max(mx[2 * v], mx[2 * v + 1]); }

void add(int l, int r, ll val, int s = 0, int e = n, int v = 1) {
  if (l >= e || r <= s)
    return;
  if (l <= s && e <= r) {
    update(v, val);
    return;
  }
  shift(v);
  int mid = (s + e) / 2;
  add(l, r, val, s, mid, 2 * v);
  add(l, r, val, mid, e, 2 * v + 1);
  merge(v);
}

int main() {
  ios::sync_with_stdio(false);

  cin >> n >> m;
  for (int i = 1; i < n; i++)
    cin >> x[i];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> a[i][j];
  for (int i = 0; i < m; i++)
    st[i].push(n);
  ll ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < m; j++) {
      ll cnt = 0;
      while (st[j].top() != n && a[st[j].top()][j] < a[i][j]) {
        add(i, st[j].top(), a[st[j].top()][j] - cnt);
        cnt = a[st[j].top()][j];
        st[j].pop();
      }
      add(i, st[j].top(), a[i][j] - cnt);
      st[j].push(i);
    }
    add(i + 1, n, -x[i + 1]);
    ans = max(ans, 1LL * mx[1]);
  }
  cout << ans << "\n";
  return 0;
}
Problem p03833 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e3 + 10;
const int M = 220;
ll a[N], b[N][M], cnt[N][N];
int n, m, S[N], top, L[N][N], R[N][N];
inline int rd() {
  int x = 0;
  int f = 1;
  char s = getchar();
  while (!isdigit(s)) {
    if (s == '-')
      f = -1;
    s = getchar();
  }
  while (isdigit(s))
    x = (x << 1) + (x << 3) + s - '0', s = getchar();
  return x * f;
}

int main() {
  //	freopen("a.in","r",stdin);
  n = rd();
  m = rd();
  a[0] = a[1] = 0;
  for (int i = 2; i <= n; i++)
    a[i] = a[i - 1] + 1ll * rd();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      b[i][j] = 1ll * rd();
  for (int j = 1; j <= m; j++) {
    top = 0;
    for (int i = 1; i <= n; i++) {
      while (top && b[S[top]][j] < b[i][j])
        top--;
      L[i][j] = top ? S[top] + 1 : 1;
      S[++top] = i;
    }
    top = 0;
    for (int i = n; i >= 1; i--) {
      while (top && b[S[top]][j] < b[i][j])
        top--;
      R[i][j] = top ? S[top] - 1 : n;
      S[++top] = i;
    }
    for (int i = 1; i <= n; i++) {
      cnt[L[i][j]][i] += b[i][j];
      cnt[L[i][j]][R[i][j] + 1] -= b[i][j];
      cnt[i + 1][i] -= b[i][j];
      cnt[i + 1][R[i][j] + 1] += b[i][j];
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {

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

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 5e3 + 10;
const int M = 220;
ll a[N], b[N][M], cnt[N][N];
int n, m, S[N], top, L[N][M], R[N][M];
inline int rd() {
  int x = 0;
  int f = 1;
  char s = getchar();
  while (!isdigit(s)) {
    if (s == '-')
      f = -1;
    s = getchar();
  }
  while (isdigit(s))
    x = (x << 1) + (x << 3) + s - '0', s = getchar();
  return x * f;
}

int main() {
  //	freopen("a.in","r",stdin);
  n = rd();
  m = rd();
  a[0] = a[1] = 0;
  for (int i = 2; i <= n; i++)
    a[i] = a[i - 1] + 1ll * rd();
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      b[i][j] = 1ll * rd();
  for (int j = 1; j <= m; j++) {
    top = 0;
    for (int i = 1; i <= n; i++) {
      while (top && b[S[top]][j] < b[i][j])
        top--;
      L[i][j] = top ? S[top] + 1 : 1;
      S[++top] = i;
    }
    top = 0;
    for (int i = n; i >= 1; i--) {
      while (top && b[S[top]][j] < b[i][j])
        top--;
      R[i][j] = top ? S[top] - 1 : n;
      S[++top] = i;
    }
    for (int i = 1; i <= n; i++) {
      cnt[L[i][j]][i] += b[i][j];
      cnt[L[i][j]][R[i][j] + 1] -= b[i][j];
      cnt[i + 1][i] -= b[i][j];
      cnt[i + 1][R[i][j] + 1] += b[i][j];
    }
  }
  ll ans = 0;
  for (int i = 1; i <= n; i++) {

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

Buggy submission (status: Runtime Error):
k, s = map(int, input().rstrip("\n").split())
print(
    sum(
        [
            x + y + z == s
            for x in range(k + 1)
            for y in range(k + 1)
            for z in range(k + 1)
        ]
    )
)


Fixed submission:
print(input().replace(",", " "))
Problem p03834 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
ll mod = pow(10, 9) + 7;
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
char upper(char c) { return c - 0x20; }
char lower(char c) { return c + 0x20; }
int main() {
  string s;
  cout << s.substr(0, 5) << ' ' << s.substr(5, 7) << ' ' << s.substr(12, 5)
       << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;
ll mod = pow(10, 9) + 7;
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
char upper(char c) { return c - 0x20; }
char lower(char c) { return c + 0x20; }
int main() {
  string s;
  cin >> s;
  cout << s.substr(0, 5) << ' ' << s.substr(6, 7) << ' ' << s.substr(14, 5)
       << endl;
}
Problem p03834 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>

#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))

int main(void) {
  char c;

  while (c = getchar())
    putchar(c == ',' ? ' ' : c);
  puts("");
  return 0;
}

Fixed submission:
#include <stdio.h>

#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))

int main(void) {
  char c;

  for (int i = 0; i < 19; i++)
    putchar((c = getchar()) == ',' ? ' ' : c);
  puts("");
  return 0;
}
Problem p03834 (C++)

Buggy submission (status: Runtime Error):
/*
ID: ramil-p1
PROG: sprime
LANG: C++11
*/
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 100, inf = 2e9 + 100;

int main() {
#ifndef ONPC
  freopen("sprime.in", "r", stdin);
  freopen("sprime.out", "w", stdout);
#endif
  ios::sync_with_stdio(0);
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == ',')
      s[i] = ' ';
  cout << s;
}


Fixed submission:
/*
ID: ramil-p1
PROG: sprime
LANG: C++11
*/
#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 100, inf = 2e9 + 100;

int main() {
  ios::sync_with_stdio(0);
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++)
    if (s[i] == ',')
      s[i] = ' ';
  cout << s;
}
Problem p03834 (C++)

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

int main() {
  string s;
  s.at(5) = ' ';
  s.at(13) = ' ';
  cout << s << endl;
}

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

int main() {
  string s;
  cin >> s;
  s.at(5) = ' ';
  s.at(13) = ' ';
  cout << s << endl;
}
Problem p03834 (C++)

Buggy submission (status: Time Limit Exceeded):
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

int main() {
  string s;
  cin >> s;

  for (int i = 0; i < 19; ++i) {
    if ((i = 5) || (i = 12)) {
      cout << " ";
      continue;
    }
    cout << s[i];
  }

  return 0;
}


Fixed submission:
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

int main() {
  string s;
  cin >> s;

  s[5] = ' ';
  s[13] = ' ';

  cout << s << endl;

  return 0;
}
Problem p03834 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
#define ULL unsigned long long
using namespace std;

int main() {
  string str1, str2, str3;
  cin >> str1 >> str2 >> str3;
  for (int i = 0; i < str1.size() - 1; i++)
    cout << str1[i];
  cout << ' ';
  for (int i = 0; i < str2.size() - 1; i++)
    cout << str2[i];
  ;
  cout << ' ';
  for (int i = 0; i < str3.size() - 1; i++)
    cout << str3[i];
  ;
  cout << endl;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
#define ULL unsigned long long
using namespace std;

int main() {
  string str;
  cin >> str;
  str[5] = str[13] = ' ';
  cout << str;
  return 0;
}
Problem p03834 (C++)

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

using namespace std;

int main() {
  string a;
  char s = ',';
  cin >> a;
  for (int i = 0; i <= a.size(); i++) {
    if (a.at(i) == s) {
      a.at(i) = ' ';
    }
  }

  cout << a;
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  string a;
  char s = ',';
  cin >> a;
  for (int i = 0; i < a.size(); i++) {
    if (a.at(i) == s) {
      a.at(i) = ' ';
    }
  }

  cout << a;
  return 0;
}
Problem p03834 (C++)

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

int main() {
  string a;
  cin >> a;
  a.at(5) = ' ';
  a.at(13) = ' ';
  a.at(19) = ' ';
  cout << a << endl;
}

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

int main() {
  string a;
  cin >> a;
  a.at(5) = ' ';
  a.at(13) = ' ';
  cout << a << endl;
}
Problem p03834 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;
  char haiku[17];

  for (int i = 0; i < 19; i++) { // sの要素s[i]は文字として扱う
    if (s[i] == ',')
      haiku[i] = ' ';
    else
      haiku[i] = s[i];
  }

  for (int i = 0; i < 19; i++) {
    cout << haiku[i];
  }
  cout << endl;
}


Fixed submission:
#include <iostream>

using namespace std;

int main() {
  string s;
  cin >> s;
  char haiku[19];

  for (int i = 0; i < 19; i++) { // sの要素s[i]は文字として扱う
    if (s[i] == ',')
      haiku[i] = ' ';
    else
      haiku[i] = s[i];
  }

  for (int i = 0; i < 19; i++) {
    cout << haiku[i];
  }
  cout << endl;
}
Problem p03834 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  while (1) {
    char a;
    cin >> a;
    if (a != ',') {
      cout << a;
    } else {
      cout << " ";
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b, c, d;
  cin >> a;
  b = a.substr(0, 5);
  c = a.substr(6, 7);
  d = a.substr(14, 5);
  cout << b << " " << c << " " << d;
}
Problem p03834 (C++)

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

int main() {
  string S;
  cin >> S;
  cout << S.at(0) << S.at(1) << S.at(2) << S.at(3) << S.at(4) << " " << S.at(6)
       << S.at(7) << S.at(8) << S.at(9) << S.at(10) << S.at(11) << S.at(12)
       << " " << S.at(14) << S.at(15) << S.at(16) << S.at(17) << S.at(18)
       << S.at(19) << endl;
}


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

int main() {
  string S;
  cin >> S;
  cout << S.at(0) << S.at(1) << S.at(2) << S.at(3) << S.at(4) << " " << S.at(6)
       << S.at(7) << S.at(8) << S.at(9) << S.at(10) << S.at(11) << S.at(12)
       << " " << S.at(14) << S.at(15) << S.at(16) << S.at(17) << S.at(18)
       << endl;
}
Problem p03834 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define INF 1000000;
#include <map>
#include <math.h>

using ll = long long;
using namespace std;

int main() {
  string s1;
  cin >> s1;
  s1.at(5) = ' ';
  s1.at(13) = ' ';

  rep(i, 20) cout << s1.at(i);
  cout << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define INF 1000000;
#include <map>
#include <math.h>

using ll = long long;
using namespace std;

int main() {
  string s1;
  cin >> s1;
  s1.at(5) = ' ';
  s1.at(13) = ' ';

  rep(i, 19) cout << s1.at(i);
  cout << endl;
}
Problem p03834 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  s.at(5) == ' ';
  s.at(13) == ' ';
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  s.at(5) = ' ';
  s.at(13) = ' ';
  cout << s << endl;
}
Problem p03834 (C++)

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

int main() {
  char a[5], b[7], c[5];
  scanf("%s,%s,%s", &a, &b, &c);
  printf("%s %s %s", a, b, c);
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
typedef long long ll;

int main() {
  string s;
  getline(cin, s);
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == ',')
      s[i] = ' ';
  }

  cout << s;
  return 0;
}
Problem p03834 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  string a, b, c;
  scanf("%s,%s,%s", &a, &b, &c);
  cout << a << " " << b << " " << c << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  string a;
  cin >> a;
  for (int i = 0; i < a.length(); i++) {
    if (a[i] == ',')
      a[i] = ' ';
  }
  cout << a << endl;
}
Problem p03834 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main() {
  string S;
  cout << S.replace(all(S), ",", " ") << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;
template <typename T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
template <typename T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main() {
  string S;
  cin >> S;
  rep(i, S.size()) { cout << (S[i] == ',' ? ' ' : S[i]); }
  cout << endl;

  return 0;
}
Problem p03834 (C++)

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

  string X;
  char Z = ' ';
  scanf("%s", &X);
  for (int i = 0; i < X.length(); i++) {
    if (X[i] == ',')
      X[i] = Z;
  }
  cout << X;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {

  string X;
  char Z = ' ';
  cin >> X;
  for (int i = 0; i < X.length(); i++) {
    if (X[i] == ',')
      X[i] = Z;
  }
  cout << X;
}
Problem p03834 (Python)

Buggy submission (status: Runtime Error):
list = ["haiku", "atcorder", "pytho"]
print(list.replace(",", " "))


Fixed submission:
haiku = input()
print(haiku.replace(",", " "))
Problem p03834 (Python)

Buggy submission (status: Runtime Error):
k, s = [int(x) for x in input().split()]
cnt = 0
for x in range(k + 1):
    if x > s:
        continue
    for y in range(x, k + 1):
        if y > s:
            break
        for z in range(y, k + 1):
            if z > s:
                break
            if x + y + z == s:
                if x == y == z:
                    cnt += 1
                elif x == y or y == z:
                    cnt += 3
                else:
                    cnt += 3
print(cnt)


Fixed submission:
a, b, c = input().split(",")
print(a, b, c)
Problem p03834 (Python)

Buggy submission (status: Runtime Error):
s = input()
print(s.replase(",", " "))


Fixed submission:
s = input()
print(s.replace(",", " "))
Problem p03834 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep2(i, s, n) for (int i = s; i < n; ++i)
#define all(a) a.begin(), a.end()
using namespace std;

int main() {
  string s;
  string s1 = s.substr(0, 5), s2 = s.substr(6, 7), s3 = s.substr(14);
  cout << s1 << " " << s2 << " " << s3 << endl;
}

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

int main() {
  string s;
  cin >> s;
  string s1 = s.substr(0, 5), s2 = s.substr(6, 7), s3 = s.substr(14);
  cout << s1 << " " << s2 << " " << s3 << endl;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
  void solve(std::istream &in, std::ostream &out) {
    ll k, s;
    in >> k >> s;
    ll ans = 0;
    for (int x = 0; x <= k; x++) {
      if (s < x) {
        break;
      }
      for (int y = 0; y <= k; y++) {
        if (s < x + y) {
          break;
        }
        for (int z = 0; z <= k; z++) {
          if (s < x + y + z) {
            break;
          }
          ans += s == x + y + z;
        }
      }
    }
    out << ans << '\n';
  }
};
void solve(std::istream &in, std::ostream &out) {
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream &in = cin;
  ostream &out = cout;
  solve(in, out);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
  void solve(std::istream &in, std::ostream &out) {
    ll k, s;
    in >> k >> s;
    ll ans = 0;
    for (int x = 0; x <= k; x++) {
      if (s < x) {
        break;
      }
      for (int y = 0; y <= k; y++) {
        if (s < x + y) {
          break;
        }
        int z = s - x - y;
        ans += 0 <= z && z <= k;
      }
    }
    out << ans << '\n';
  }
};
void solve(std::istream &in, std::ostream &out) {
  out << std::setprecision(12);
  Solution solution;
  solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream &in = cin;
  ostream &out = cout;
  solve(in, out);
  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main(void) {
  int K, S;
  cin >> K >> S;

  int cnt = 0;
  for (int X = 0; X <= K; ++X) {
    for (int Y = 0; Y <= K; ++Y) {
      for (int Z = 0; Z <= K; ++Z) {
        if ((X + Y + Z) == S)
          ++cnt;
      }
    }
  }
  cout << cnt << endl;

  return 0;
}

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

int main(void) {
  int K, S;
  cin >> K >> S;

  int cnt = 0;
  for (int X = 0; X <= K; ++X) {
    for (int Y = 0; Y <= K; ++Y) {
      if (((X + Y) <= S) && ((X + Y) >= (S - K)))
        ++cnt;
    }
  }
  cout << cnt << endl;

  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>

using namespace std;

int main() {
  int max, sum;
  cin >> max >> sum;

  int counter = 0;
  for (int i = 0; i <= max; i++) {
    for (int j = 0; j <= max; j++) {
      for (int k = 0; k <= max; k++) {
        if (i + j + k == sum)
          counter++;
      }
    }
  }

  cout << counter << endl;

  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int max, sum;
  cin >> max >> sum;

  int counter = 0;
  for (int i = 0; i <= max; i++) {
    for (int j = 0; j <= max; j++) {
      if ((0 <= sum - i - j) & (sum - i - j <= max))
        counter++;
    }
  }

  cout << counter << endl;

  return 0;
}
Problem p03835 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

  int k, s;
  cin >> k >> s;

  int count = 0;
  REP(i, k + 1) REP(j, k + 1) REP(c, k + 1) {
    if (i + j + c == s)
      count++;
  }

  cout << count << '\n';
  return 0;
}

Fixed submission:
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

  int k, s;
  cin >> k >> s;

  int count = 0;
  REP(a, k + 1) REP(b, k + 1) {
    if (s - a - b >= 0 && s - a - b <= k)
      count++;
  }

  cout << count << '\n';
  return 0;
}