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

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int sum[2001];
int main() {
  for (int i = 0; i < 1001; ++i) {
    for (int j = 0; j < 1001; ++j) {
      sum[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
      for (int j = 0; i + j <= n; ++j) {
        ans += sum[n - i - j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int sum[2001];
int main() {
  for (int i = 0; i < 1001; ++i) {
    for (int j = 0; j < 1001; ++j) {
      sum[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    long long ans = 0;
    for (int i = 0; i <= 1000; ++i) {
      for (int j = 0; j <= 1000; ++j) {
        if (n - i - j > 2001)
          continue;
        if (n - i - j < 0)
          break;
        ans += sum[n - i - j];
      }
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++)

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

using namespace std;

int ab[2050];

int main(void) {
  int n;

  for (int a = 0; a <= 1000; a++) {
    for (int b = 0; b <= 1000; b++) {
      ab[a + b]++;
    }
  }

  while (cin >> n) {
    if (cin.eof())
      break;

    int ret = 0;
    for (int cd = 0; cd <= 2000; cd++) {
      if (n - cd >= 0) {
        ret += ab[cd] * ab[n - cd];
      }
    }
    cout << ret << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int ab[2050];

int main(void) {
  int n;

  for (int a = 0; a <= 1000; a++) {
    for (int b = 0; b <= 1000; b++) {
      ab[a + b]++;
    }
  }

  while (cin >> n) {
    if (cin.eof())
      break;

    int ret = 0;
    for (int cd = 0; cd <= 2000; cd++) {
      if (n - cd >= 0 && n - cd <= 2000) {
        ret += ab[cd] * ab[n - cd];
      }
    }
    cout << ret << endl;
  }

  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cmath>
#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    long long cnt = 0;
    for (int i = max(0, n - 3000); i <= min(1000, n); i++) {
      for (int j = max(0, n - i - 2000); j <= min(1000, n); j++) {
        for (int k = max(0, n - i - j - 1000); k <= min(1000, n); k++) {
          if ((n - (i + j + k)) >= 0 && (n - (i + j + k)) <= 1000)
            cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

Fixed submission:
#include <cmath>
#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int main() {
  int n;
  while (cin >> n) {
    long long cnt = 0;
    for (int i = max(0, n - 3000); i <= min(1000, n); i++) {
      for (int j = max(0, n - i - 2000); j <= min(1000, n - i); j++) {
        cnt += (min(1000, n - i - j) - max(0, n - i - j - 1000) + 1);
      }
    }
    cout << cnt << endl;
  }
  return 0;
}
Problem p00096 (C++)

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

using namespace std;

int main() {
  int n;
  int AB[2001] = {0};
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      AB[i + j]++;
    }
  }

  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= 2000; i++) {
      if (n - i >= 0)
        ans += AB[i] * AB[n - i];
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int n;
  int AB[2001] = {0};
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      AB[i + j]++;
    }
  }

  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= 2000; i++) {
      if (n - i > 2000)
        continue;
      if (n - i >= 0)
        ans += AB[i] * AB[n - i];
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  int a[2001] = {};
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    long long int all = 0;
    for (int i = 0; i <= 1000; i++) {
      for (int j = 0; j <= 1000 && j <= n - i; j++) {
        all += a[n - i - j];
      }
    }
    cout << all << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a[4001] = {};
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a[i + j]++;
    }
  }
  int n;
  while (cin >> n) {
    long long int all = 0;
    for (int i = 0; i <= 1000; i++) {
      for (int j = 0; j <= 1000 && j <= n - i; j++) {
        all += a[n - i - j];
      }
    }
    cout << all << endl;
  }
  return 0;
}
Problem p00096 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int t[2001];
int n, sum;
int main() {
  for (int i = 0; i < 2001; i++) {
    if (i < 1001)
      t[i] = i + 1;
    else
      t[i] = 2001 - i;
  }
  while (cin >> n) {
    sum = 0;
    for (int i = 0; i < 2001; i++) {
      if (n - i >= 0)
        sum += t[i] * t[n - i];
    }
    cout << sum << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int t[2001];
int n, sum;
int main() {
  for (int i = 0; i < 2001; i++) {
    if (i < 1001)
      t[i] = i + 1;
    else
      t[i] = 2001 - i;
  }
  while (cin >> n) {
    sum = 0;
    for (int i = 0; i < 2001; i++) {
      if (n - i >= 0 && n - i <= 2000) {
        sum = sum + t[i] * t[n - i];
      }
    }
    cout << sum << endl;
  }
  return 0;
}
Problem p00096 (C++)

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

int main(int argc, char *argv[]) {
  int n;
  int a_add_b[2001] = {0};

  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a_add_b[i + j]++;
    }
  }

  while (scanf("%d", &n) != EOF) {
    long long int ans = 0;
    for (int i = 0; i <= n; i++) {
      ans += a_add_b[i] * a_add_b[n - i];
    }
    std::cout << ans << std::endl;
  }
  return 0;
}

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

int main(int argc, char *argv[]) {
  int n;
  int a_add_b[2001] = {0};

  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j <= 1000; j++) {
      a_add_b[i + j]++;
    }
  }

  while (scanf("%d", &n) != EOF) {
    long long int ans = 0;
    for (int i = 0; i <= 2000; i++) {
      if (0 <= n - i && n - i <= 2000)
        ans += a_add_b[i] * a_add_b[n - i];
    }
    std::cout << ans << std::endl;
  }
  return 0;
}
Problem p00097 (C++)

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

using lint = long long;

lint n, s;
lint dp[1001][101][101];

lint dfs(int sum = 0, int num = 0, int cnt = 0) {
  if (cnt == n)
    return sum == s;
  if (num > 100 || sum > s)
    return 0;

  lint &ret = dp[sum][num][cnt];
  if (~ret)
    return ret;

  ret = dfs(sum, num + 1, cnt) + dfs(sum + num, num + 1, cnt + 1);

  return ret;
}

int main() {
  while (cin >> n >> s, n + s) {
    memset(dp, -1, sizeof(dp));
    cout << dfs() << endl;
  }
}

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

using lint = long long;

lint n, s;
lint dp[1001][101][11];

lint dfs(int sum = 0, int num = 0, int cnt = 0) {
  if (cnt == n)
    return sum == s;
  if (num > 100 || sum > s)
    return 0;

  lint &ret = dp[sum][num][cnt];
  if (~ret)
    return ret;

  ret = dfs(sum, num + 1, cnt) + dfs(sum + num, num + 1, cnt + 1);

  return ret;
}

int main() {
  while (cin >> n >> s, n + s) {
    memset(dp, -1, sizeof(dp));
    cout << dfs() << endl;
  }
}
Problem p00097 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
// const int INF = 1e8;
using namespace std;

int main() {
  int n, s;
  while (cin >> n >> s, n) {
    long long dp[10][1005] = {{0}};
    dp[0][0] = 1;
    rep(j, 101) {
      for (int i = n; i >= 0; i--) {
        for (int k = s; k >= 0; k--) {
          dp[i + 1][k + j] += dp[i][k];
        }
      }
    }
    cout << dp[n][s] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
// const int INF = 1e8;
using namespace std;

int main() {
  int n, s;
  while (cin >> n >> s, n) {
    long long dp[10][2005] = {{0}};
    dp[0][0] = 1;
    rep(j, 101) {
      for (int i = n; i >= 0; i--) {
        for (int k = s; k >= 0; k--) {
          dp[i + 1][k + j] += dp[i][k];
        }
      }
    }
    cout << dp[n][s] << endl;
  }
}
Problem p00097 (C++)

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

using namespace std;

int main(void) {
  long long n, s, dp[102][11][1001];

  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 0; k < 1001; k++)
        dp[i][j][k] = 0;

  dp[0][0][0] = 1;

  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 1001; k++) {
        if (dp[i][j][k] == 0)
          continue;

        dp[i + 1][j][k] += dp[i][j][k];

        if (8 < j || 1000 < k + i)
          continue;

        dp[i + 1][j + 1][k + i] += dp[i][j][k];
      }
    }
  }

  while (cin >> n >> s, n | s)
    cout << dp[101][n][s] << endl;
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  static long long n, s, dp[102][11][1001];

  for (int i = 0; i < 101; i++)
    for (int j = 0; j < 10; j++)
      for (int k = 0; k < 1001; k++)
        dp[i][j][k] = 0;

  dp[0][0][0] = 1;

  for (int i = 0; i < 101; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 1001; k++) {
        if (dp[i][j][k] == 0)
          continue;

        dp[i + 1][j][k] += dp[i][j][k];

        if (8 < j || 1000 < k + i)
          continue;

        dp[i + 1][j + 1][k + i] += dp[i][j][k];
      }
    }
  }

  while (cin >> n >> s, n | s)
    cout << dp[101][n][s] << endl;
  return 0;
}
Problem p00097 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
long long int a[101][11][1100];

int main() {
  int n, s;
  a[0][0][0] = 1;
  a[0][1][0] = 1;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 1000; k++) {
        a[i + 1][j][k] += a[i][j][k];
        a[i + 1][j + 1][k + i + 1] += a[i][j][k];
      }
    }
  }
  while (1) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    cout << a[100][n][s] << endl;
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
long long int a[102][11][1100];

int main() {
  int n, s;
  a[0][0][0] = 1;
  a[0][1][0] = 1;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 9; j++) {
      for (int k = 0; k <= 1000; k++) {
        a[i + 1][j][k] += a[i][j][k];
        a[i + 1][j + 1][k + i + 1] += a[i][j][k];
      }
    }
  }
  while (1) {
    cin >> n >> s;
    if (n == 0 && s == 0)
      break;
    cout << a[100][n][s] << endl;
  }
  return 0;
}
Problem p00098 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;

int main() {
  int n, a[100][100], rs[100][100], sum[100][100];
  cin >> n;
  rep(i, n) rep(j, n) cin >> a[i][j];

  rep(i, n) rs[0][i] = 0;
  rep(i, n) {
    rs[i + 1][0] = 0;
    rep(j, n) { rs[i + 1][j + 1] = rs[i + 1][j] + a[i][j]; }
  }

  rep(i, n + 1) {
    sum[0][i] = 0;
    rep(j, n) { sum[j + 1][i] = sum[j][i] + rs[j + 1][i]; }
  }

  int ans = -1000000000;
  rep(i, n) rep(j, n) rep(k, n + 1) rep(l, n + 1) {
    if (i < k && j < l) {
      ans = std::max(ans, sum[k][l] - sum[k][j] - sum[i][l] + sum[i][j]);
    }
  }
  cout << ans << endl;
}

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

int main() {
  int n, a[110][110], rs[110][110], sum[110][110];
  cin >> n;
  rep(i, n) rep(j, n) cin >> a[i][j];

  rep(i, n) rs[0][i] = 0;
  rep(i, n) {
    rs[i + 1][0] = 0;
    rep(j, n) { rs[i + 1][j + 1] = rs[i + 1][j] + a[i][j]; }
  }

  rep(i, n + 1) {
    sum[0][i] = 0;
    rep(j, n) { sum[j + 1][i] = sum[j][i] + rs[j + 1][i]; }
  }

  int ans = -1000000000;
  rep(i, n) rep(j, n) rep(k, n + 1) rep(l, n + 1) {
    if (i < k && j < l) {
      ans = std::max(ans, sum[k][l] - sum[k][j] - sum[i][l] + sum[i][j]);
    }
  }
  cout << ans << endl;
}
Problem p00098 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#define rep(i, N) for (i = 1; i <= N; i++)
using namespace std;

int n;
int data[102][102];
int rui[102][102]; // rui[i][j] = (1,1)を左上とするi*j行列の要素和

int main() {
  int i, j, k, l;
  cin >> n;
  rep(i, n) {
    rep(j, n) { cin >> data[i][j]; }
  }

  // 左→右
  rep(i, n) {
    rep(j, n) { rui[i][j] = rui[i][j - 1] + data[i][j]; }
  }
  // 上→下
  rep(j, n) {
    rep(i, n) { rui[i][j] = rui[i - 1][j] + rui[i][j]; }
  }

  int ans = -1145141919;
  rep(i, n) {
    rep(j, n) {
      for (k = i; k < n; k++) {
        for (l = j; k < n; l++) {
          // 左上(i,j), 右下(k,l)とする行列の要素和を求める
          int mats =
              rui[k][l] - rui[k][j - 1] - rui[i - 1][l] + rui[i - 1][j - 1];
          ans = max(ans, mats);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

/*Σ(k=a, k=b)A[k]を知りたい！
愚直に計算O(b-a)

先に
Σ(k=1, k=n)A[k] = rui[n]としておく.
すると、
Σ(k=a, k=b)A[k] = rui[b] - rui[a];
で計算できる。
O(1)
*/

Fixed submission:
#include <iostream>
#define rep(i, N) for (i = 1; i <= N; i++)
using namespace std;

int n;
int data[102][102];
int rui[102][102]; // rui[i][j] = (1,1)を左上とするi*j行列の要素和

int main() {
  int i, j, k, l;
  cin >> n;
  rep(i, n) {
    rep(j, n) { cin >> data[i][j]; }
  }

  // 左→右
  rep(i, n) {
    rep(j, n) { rui[i][j] = rui[i][j - 1] + data[i][j]; }
  }
  // 上→下
  rep(j, n) {
    rep(i, n) { rui[i][j] = rui[i - 1][j] + rui[i][j]; }
  }

  int ans = -1145141919;
  rep(i, n) {
    rep(j, n) {
      for (k = i; k <= n; k++) {
        for (l = j; l <= n; l++) {
          // 左上(i,j), 右下(k,l)とする行列の要素和を求める
          int mats =
              rui[k][l] - rui[k][j - 1] - rui[i - 1][l] + rui[i - 1][j - 1];
          ans = max(ans, mats);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

/*Σ(k=a, k=b)A[k]を知りたい！
愚直に計算O(b-a)

先に
Σ(k=1, k=n)A[k] = rui[n]としておく.
すると、
Σ(k=a, k=b)A[k] = rui[b] - rui[a];
で計算できる。
O(1)
*/
Problem p00099 (C++)

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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  static int num[100001];
  multiset<pair<int, int>> S;
  S.insert(make_pair(0, 0));
  rep(_, q) {
    int a, v;
    scanf("%d%d", &a, &v);
    if (num[a] > 0)
      S.erase(S.find(make_pair(-num[a], a)));
    num[a] += v;
    if (num[a] > 0)
      S.insert(make_pair(-num[a], a));
    printf("%d %d\n", S.begin()->second, -S.begin()->first);
  }

  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  static int num[1000001];
  set<pair<int, int>> S;
  S.insert(make_pair(0, 1));
  rep(_, q) {
    int a, v;
    scanf("%d%d", &a, &v);
    if (num[a] > 0)
      S.erase(S.find(make_pair(-num[a], a)));
    num[a] += v;
    if (num[a] > 0)
      S.insert(make_pair(-num[a], a));
    printf("%d %d\n", S.begin()->second, -S.begin()->first);
  }

  return 0;
}
Problem p00099 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int d[1000001];
set<pii> st;

signed main() {
  int n, q;
  cin >> n >> q;
  rep(i, 0, n) { st.insert(make_pair(0, i)); }
  rep(i, 0, q) {
    int a, v;
    cin >> a >> v;
    a--;
    st.erase(st.find(make_pair(d[a], a)));
    d[a] -= v;
    st.insert(make_pair(d[a], a));
    set<pii>::iterator it = st.begin();
    cout << it->se + 1 << " " << -it->fi << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int d[1000001];
set<pii> st;

signed main() {
  int n, q;
  cin >> n >> q;
  rep(i, 0, n) { st.insert(make_pair(0, i)); }
  rep(i, 0, q) {
    int a, v;
    cin >> a >> v;
    a--;
    st.erase(st.find(make_pair(d[a], a)));
    d[a] -= v;
    st.insert(make_pair(d[a], a));
    set<pii>::iterator it = st.begin();
    cout << it->se + 1 << " " << -it->fi << endl;
  }
}
Problem p00099 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) a > b ? a : b

typedef long long int ll;

using namespace std;
pair<int, int> tree[2000001];
int n, q;

pair<int, int> pmax(pair<int, int> a, pair<int, int> b) {
  pair<int, int> ret = MAX(a, b);
  if (a.first == b.first) {
    ret.second = min(a.second, b.second);
  }
  return ret;
}

void init(int k, int l, int r) {
  if (r - l == 1)
    tree[k] = tree[l];
  else {
    int chl = 2 * k + 1, chr = 2 * k + 2;
    int m = (int)((l + r) / 2);
    init(chl, l, m);
    init(chr, m, r);
    tree[k] = pmax(tree[chl], tree[chr]);
  }
}

void update(int k, int a) {
  k += n;
  tree[k].first += a;
  while (k > 0) {
    k = (k - 1) / 2;
    tree[k] = pmax(tree[2 * k + 1], tree[2 * k + 2]);
  }
}

int main() {
  // pair<int,int> ma(-100000000,-1);
  cin >> n >> q;
  REP(i, 2 * n) tree[n + i] = pair<int, int>(0, 0);
  REP(i, n) { tree[n + i].second = i + 1; }
  vector<pair<int, int>> ar(n);
  vector<bool> u(q, false);
  REP(i, q) {
    int a, v;
    cin >> a >> v;
    update(a - 1, v);
    cout << tree[0].second << " " << tree[0].first << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = n - 1; i >= 0; i--)

#define PB push_back
#define INF INT_MAX / 3
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) a > b ? a : b

typedef long long int ll;

using namespace std;
pair<int, int> tree[3000001];
int n, q;

pair<int, int> pmax(pair<int, int> a, pair<int, int> b) {
  pair<int, int> ret = MAX(a, b);
  if (a.first == b.first) {
    ret.second = min(a.second, b.second);
  }
  return ret;
}

void init(int k, int l, int r) {
  if (r - l == 1)
    tree[k] = tree[l];
  else {
    int chl = 2 * k + 1, chr = 2 * k + 2;
    int m = (int)((l + r) / 2);
    init(chl, l, m);
    init(chr, m, r);
    tree[k] = pmax(tree[chl], tree[chr]);
  }
}

void update(int k, int a) {
  k += n;
  tree[k].first += a;
  while (k > 0) {
    k = (k - 1) / 2;
    tree[k] = pmax(tree[2 * k + 1], tree[2 * k + 2]);
  }
}

int main() {
  // pair<int,int> ma(-100000000,-1);
  cin >> n >> q;
  REP(i, 2 * n) tree[n + i] = pair<int, int>(0, 0);
  REP(i, n) { tree[n + i].second = i + 1; }
  vector<pair<int, int>> ar(n);
  vector<bool> u(q, false);
  REP(i, q) {
    int a, v;
    cin >> a >> v;
    update(a - 1, v);
    cout << tree[0].second << " " << tree[0].first << endl;
  }
  return 0;
}
Problem p00099 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int MAX_N = 1000010;

int N, Q;
P v[2 * MAX_N - 1];

void init(int _n) {
  N = 1;
  while (N < _n)
    N *= 2;
  REP(i, 2 * N - 1) v[i] = P(0, 0);
  REP(i, _n) v[i + N - 1].second = i * -1;
}

void update(int k, int a) {
  k += N - 1;
  v[k].first += a;
  while (k > 0) {
    k = (k - 1) / 2;
    v[k] = max(v[k * 2 + 1], v[k * 2 + 2]);
  }
}

int main() {
  cin >> N >> Q;
  init(N);
  REP(i, Q) {
    int a, b;
    cin >> a >> b;
    update(a - 1, b);
    cout << v[0].second * -1 + 1 << " " << v[0].first << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i, j) for (int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for (int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int MAX_N = 2000010;

int N, Q;
P v[2 * MAX_N - 1];

void init(int _n) {
  N = 1;
  while (N < _n)
    N *= 2;
  REP(i, 2 * N - 1) v[i] = P(0, 0);
  REP(i, _n) v[i + N - 1].second = i * -1;
}

void update(int k, int a) {
  k += N - 1;
  v[k].first += a;
  while (k > 0) {
    k = (k - 1) / 2;
    v[k] = max(v[k * 2 + 1], v[k * 2 + 2]);
  }
}

int main() {
  cin >> N >> Q;
  init(N);
  REP(i, Q) {
    int a, b;
    cin >> a >> b;
    update(a - 1, b);
    cout << v[0].second * -1 + 1 << " " << v[0].first << endl;
  }
  return 0;
}
Problem p00099 (C++)

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

  bool operator<(const P &t) const {
    if (v == t.v)
      return a > t.a;
    return v < t.v;
  }
};

int n;
P dat[2000000];

void update(int i, int x) {
  i += n - 1;
  dat[i].v += x;
  while (i > 0) {
    i = (i - 1) / 2;
    dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);
  }
}

int main() {
  int q;
  scanf("%d %d", &n, &q);

  for (int i = 1;; i *= 2) {
    if (n <= i) {
      n = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    dat[i + n - 1].a = i;
  }

  for (int i = 0; i < q; i++) {
    int a, v;
    scanf("%d %d", &a, &v);
    a--;
    update(a, v);
    printf("%d %d\n", dat[0].a + 1, dat[0].v);
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct P {
  int a, v;

  bool operator<(const P &t) const {
    if (v == t.v)
      return a > t.a;
    return v < t.v;
  }
};

int n;
P dat[10000000];

void update(int i, int x) {
  i += n - 1;
  dat[i].v += x;
  while (i > 0) {
    i = (i - 1) / 2;
    dat[i] = max(dat[i * 2 + 1], dat[i * 2 + 2]);
  }
}

int main() {
  int q;
  scanf("%d %d", &n, &q);

  for (int i = 1;; i *= 2) {
    if (n <= i) {
      n = i;
      break;
    }
  }
  for (int i = 0; i < n; i++) {
    dat[i + n - 1].a = i;
  }

  for (int i = 0; i < q; i++) {
    int a, v;
    scanf("%d %d", &a, &v);
    a--;
    update(a, v);
    printf("%d %d\n", dat[0].a + 1, dat[0].v);
  }

  return 0;
}
Problem p00099 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;

int main() {
  int n, q, fig, value;
  cin >> n >> q;
  vector<int> memo(n + 1);
  fill(memo.begin(), memo.end(), 0);
  priority_queue<pair<int, int>> que;
  que.push(make_pair(0, -1));
  while (q--) {
    cin >> fig >> value;
    memo[fig] += value;
    for (int i = 1; i <= n; i++)
      que.push(make_pair(memo[i], -i));
    for (;;) {
      if (que.top().first == memo[-que.top().second]) {
        cout << -que.top().second << " " << que.top().first << endl;
        break;
      }
      que.pop();
    }
  }
}

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

int main() {
  int n, q, fig, value;
  cin >> n >> q;
  vector<int> memo(n + 1);
  fill(memo.begin(), memo.end(), 0);
  priority_queue<pair<int, int>> que;
  que.push(make_pair(0, -1));
  while (q--) {
    cin >> fig >> value;
    memo[fig] += value;
    que.push(make_pair(memo[fig], -fig));
    for (;;) {
      if (que.top().first == memo[-que.top().second]) {
        cout << -que.top().second << " " << que.top().first << endl;
        break;
      }
      que.pop();
    }
  }
}
Problem p00099 (C++)

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

#pragma warning(disable : 4996)

using namespace std;

int n, q, c[1000000], a, v;

int main() {
  scanf("%d", &n);
  scanf("%d", &q);

  priority_queue<pair<int, int>> que;

  for (int i = 0; i < q; i++) {
    scanf("%d", &a);
    scanf("%d", &v);

    c[a - 1] += v;
    que.push(make_pair(c[a - 1], -a));

    pair<int, int> maximum;

    while (true) {
      maximum = que.top();

      if (maximum.first != c[-maximum.second + 1]) {
        que.pop();
      } else {
        break;
      }
    }

    printf("%d %d\n", -maximum.second, maximum.first);
  }

  return 0;
}

Fixed submission:
#include <cstdio>
#include <queue>

#pragma warning(disable : 4996)

using namespace std;

int n, q, c[1000000], a, v;

int main() {
  scanf("%d", &n);
  scanf("%d", &q);

  priority_queue<pair<int, int>> que;

  for (int i = 0; i < q; i++) {
    scanf("%d", &a);
    scanf("%d", &v);

    c[a - 1] += v;
    que.push(make_pair(c[a - 1], -a));

    pair<int, int> maximum;

    while (true) {
      maximum = que.top();

      if (maximum.first != c[-maximum.second - 1]) {
        que.pop();
      } else {
        break;
      }
    }

    printf("%d %d\n", -maximum.second, maximum.first);
  }

  return 0;
}
Problem p00099 (C++)

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

typedef pair<int, int> P;

int main() {
  int a, n, q, v, m_a = 0;
  cin >> n >> q;
  vector<int> fish(n, 0);
  priority_queue<P> pq;
  pq.push(P(1, 0));
  for (int i = 0; i < q; i++) {
    cin >> a >> v;
    fish[a] += v;
    pq.push(P(fish[a], -a));
    while (fish[-pq.top().second] != pq.top().first)
      pq.pop();
    cout << -pq.top().second << ' ' << pq.top().first << endl;
  }
  return 0;
}

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

typedef pair<int, int> P;

int main() {
  int a, n, q, v, m_a = 0;
  cin >> n >> q;
  vector<int> fish(n + 1, 0);
  priority_queue<P> pq;
  pq.push(P(1, 0));
  for (int i = 0; i < q; i++) {
    cin >> a >> v;
    fish[a] += v;
    pq.push(P(fish[a], -a));
    while (fish[-pq.top().second] != pq.top().first)
      pq.pop();
    cout << -pq.top().second << ' ' << pq.top().first << endl;
  }
  return 0;
}
Problem p00100 (C++)

Buggy submission (status: Runtime Error):
#include <memory.h>
#include <stdio.h>
int main() {
  int n, i, j, k, e[100], p[100], q[100];
  int c[100], count = 0, count2 = 0;
  int gokei = 0;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &e[i], &p[i], &q[i]);
      gokei = p[i] * q[i];
      for (j = 0; j < i; j++) {
        if (e[i] == e[j]) {
          gokei += p[j] * q[j];
        }
      }
      for (k = 0; k < count; k++) {
        if (e[i] == c[k]) {
          goto a;
        }
      }
      if (gokei >= 1000000) {
        c[count] = e[i];
        count++;
      }
    a:
      gokei = 0;
    }
    for (i = 0; i < count; i++) {
      printf("%d\n", c[i]);
    }
    if (count == 0) {
      printf("NA\n");
    }
    count = 0;
    memset(c, 0, sizeof(c));
  }

  return 0;
}

Fixed submission:
#include <memory.h>
#include <stdio.h>
int main() {
  int n, i, j, k, e[1000], p[1000], q[1000];
  int c[1000], count = 0, count2 = 0;
  int gokei = 0;
  while (1) {
    scanf("%d", &n);
    if (n == 0)
      break;
    for (i = 0; i < n; i++) {
      scanf("%d %d %d", &e[i], &p[i], &q[i]);
      gokei = p[i] * q[i];
      for (j = 0; j < i; j++) {
        if (e[i] == e[j]) {
          gokei += p[j] * q[j];
        }
      }
      for (k = 0; k < count; k++) {
        if (e[i] == c[k]) {
          goto a;
        }
      }
      if (gokei >= 1000000) {
        c[count] = e[i];
        count++;
      }
    a:
      gokei = 0;
    }
    for (i = 0; i < count; i++) {
      printf("%d\n", c[i]);
    }
    if (count == 0) {
      printf("NA\n");
    }
    count = 0;
    memset(c, 0, sizeof(c));
  }

  return 0;
}
Problem p00100 (C++)

Buggy submission (status: Runtime Error):
// 2011/01/12 Tazoe

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    int emp[4000][3];
    for (int i = 0; i < 4000; i++) {
      emp[i][0] = i + 1;
      emp[i][1] = 0;
      emp[i][2] = 5000;
    }

    int ord = 1;
    for (int i = 0; i < n; i++) {
      int id, p, q;
      cin >> id >> p >> q;
      if (1000000 / p + 1 <= q)
        emp[id - 1][1] = 1000000;
      else if (emp[id - 1][1] < 1000000)
        emp[id - 1][1] += p * q;
      if (emp[id - 1][2] == 5000) {
        emp[id - 1][2] = ord;
        ord++;
      }
    }

    for (int i = 0; i < 3999; i++)
      for (int j = i + 1; j < 4000; j++)
        if (emp[i][2] > emp[j][2]) {
          int tmp1 = emp[i][0];
          int tmp2 = emp[i][1];
          int tmp3 = emp[i][2];
          emp[i][0] = emp[j][0];
          emp[i][1] = emp[j][1];
          emp[i][2] = emp[j][2];
          emp[j][0] = tmp1;
          emp[j][1] = tmp2;
          emp[j][2] = tmp3;
        }

    int cnt = 0;
    for (int i = 0; emp[i][2] != 5000 && i < 4000; i++)
      if (emp[i][1] >= 1000000) {
        cout << emp[i][0] << endl;
        cnt++;
      }
    if (cnt == 0)
      cout << "NA" << endl;
  }

  return 0;
}

Fixed submission:
// 2011/01/12 Tazoe

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0)
      break;

    int emp[4000][3];
    for (int i = 0; i < 4000; i++) {
      emp[i][0] = i + 1;
      emp[i][1] = 0;
      emp[i][2] = 5000;
    }

    int ord = 1;
    for (int i = 0; i < n; i++) {
      int id, p, q;
      cin >> id >> p >> q;
      if (p != 0 && 1000000 / p + 1 <= q)
        emp[id - 1][1] = 1000000;
      else if (emp[id - 1][1] < 1000000)
        emp[id - 1][1] += p * q;
      if (emp[id - 1][2] == 5000) {
        emp[id - 1][2] = ord;
        ord++;
      }
    }

    for (int i = 0; i < 3999; i++)
      for (int j = i + 1; j < 4000; j++)
        if (emp[i][2] > emp[j][2]) {
          int tmp1 = emp[i][0];
          int tmp2 = emp[i][1];
          int tmp3 = emp[i][2];
          emp[i][0] = emp[j][0];
          emp[i][1] = emp[j][1];
          emp[i][2] = emp[j][2];
          emp[j][0] = tmp1;
          emp[j][1] = tmp2;
          emp[j][2] = tmp3;
        }

    int cnt = 0;
    for (int i = 0; emp[i][2] != 5000 && i < 4000; i++)
      if (emp[i][1] >= 1000000) {
        cout << emp[i][0] << endl;
        cnt++;
      }
    if (cnt == 0)
      cout << "NA" << endl;
  }

  return 0;
}
Problem p00100 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
  ll n;
  while (scanf("%d\n", &n), n) {
    vector<pair<ll, ll>> v;
    rep(i, n) {
      ll x, y, z;
      cin >> x >> y >> z;
      bool f = false;
      for (int j = 0; j < v.size(); ++j) {
        if (v[j].first == x) {
          v[j].second += y * z;
          f = true;
          break;
        }
      }
      if (!f) {
        v.push_back(make_pair(x, y * z));
      }
    }
    bool flag = false;
    for (int j = 0; j < v.size(); ++j) {
      if (v[j].second >= 1000000) {
        flag = true;
        cout << v[j].first << endl;
      }
    }
    if (!flag)
      cout << "NA" << endl;
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
int main() {
  int n;
  while (scanf("%d\n", &n), n) {
    vector<pair<ll, ll>> v;
    rep(i, n) {
      ll x, y, z;
      cin >> x >> y >> z;
      bool f = false;
      for (int j = 0; j < v.size(); ++j) {
        if (v[j].first == x) {
          v[j].second += y * z;
          f = true;
          break;
        }
      }
      if (!f) {
        v.push_back(make_pair(x, y * z));
      }
    }
    bool flag = false;
    for (int j = 0; j < v.size(); ++j) {
      if (v[j].second >= 1000000) {
        flag = true;
        cout << v[j].first << endl;
      }
    }
    if (!flag)
      cout << "NA" << endl;
  }
  return 0;
}
Problem p00101 (C++)

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

int main() {
  string str;
  int n;
  cin >> n;
  getline(cin, str);
  for (int i = 0; i < n; i++) {
    getline(cin, str);
    for (int j = 0; j < str.size() - 6; j++) {
      if (str[j] == 'H') {
        if (str.substr(j + 1, 6) == "oshino")
          str.replace(j, 7, "Hoshina");
        else if (str.substr(j + 1, 6) == "oshina")
          str.replace(j, 7, "Hoshino");
      }
    }
    cout << str << endl;
  }
}


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

int main() {
  string str;
  int n;
  cin >> n;
  getline(cin, str);
  for (int i = 0; i < n; i++) {
    getline(cin, str);
    for (int j = 0; j < int(str.size()) - 6; j++) {
      if (str.substr(j, 7) == "Hoshino")
        str.replace(j, 7, "Hoshina");
    }
    cout << str << endl;
  }
}
Problem p00101 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <typeinfo>
#include <vector>
#define INF 100000000
#define rep(i, a) for (int i = 0; i < (a); i++)

using namespace std;
typedef long long ll;

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

  rep(i, n) {
    string s;
    getline(cin, s);
    for (int i = 0; i < s.size() - 6; i++) {
      if (s[i] == 'H' && s[i + 1] == 'o' && s[i + 2] == 's' &&
          s[i + 3] == 'h' && s[i + 4] == 'i' && s[i + 5] == 'n' &&
          s[i + 6] == 'o') {
        s[i + 6] = 'a';
      }
    }
    cout << s << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <typeinfo>
#include <vector>
#define INF 100000000
#define rep(i, a) for (int i = 0; i < (a); i++)

using namespace std;
typedef long long ll;

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

  rep(i, n) {
    string s;
    getline(cin, s);
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'H' && s[i + 1] == 'o' && s[i + 2] == 's' &&
          s[i + 3] == 'h' && s[i + 4] == 'i' && s[i + 5] == 'n' &&
          s[i + 6] == 'o') {
        s[i + 6] = 'a';
      }
    }
    cout << s << endl;
  }
  return 0;
}
Problem p00101 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

void solve() {
  int n;
  scanf("%d\n", &n);
  string name = "Hoshino";
  while (n--) {
    string s;
    getline(cin, s);
    for (int i = 0; i < s.length() - name.length() + 1; ++i) {
      bool flag = true;
      for (int j = 0; j < name.length(); ++j) {
        if (s[i + j] != name[j]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        s[i + name.length() - 1] = 'a';
      } else {
        continue;
      }
    }
    cout << s << endl;
  }
}

int main() {
  solve();
  return (0);
}

Fixed submission:
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

void solve() {
  int n;
  scanf("%d\n", &n);
  string name = "Hoshino";
  while (n--) {
    string s;
    getline(cin, s);
    int length = s.length() - name.length() + 1;
    for (int i = 0; i < length; ++i) {
      bool flag = true;
      for (int j = 0; j < name.length(); ++j) {
        if (s[i + j] != name[j]) {
          flag = false;
          break;
        }
      }
      if (flag) {
        s[i + name.length() - 1] = 'a';
      } else {
        continue;
      }
    }
    cout << s << endl;
  }
}

int main() {
  solve();
  return (0);
}
Problem p00101 (C++)

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

using namespace std;

int main() {
  string str;
  int n;

  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, str);
    for (int j = 0; j < (int)str.size(); j++) {
      string key = str.substr(j, 7), repl;
      if (key == "Hoshino") {
        repl = "Hoshina";
        for (int k = 0; k < n; k++) {
          str[j + k] = repl[k];
        }
      }
    }
    cout << str << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  string str;
  int n;

  cin >> n;
  cin.ignore();
  while (n--) {
    getline(cin, str);
    for (int j = 0; j < (int)str.size(); j++) {
      string key = str.substr(j, 7), repl;
      if (key == "Hoshino") {
        repl = "Hoshina";
        for (int k = 0; k < 7; k++) {
          str[j + k] = repl[k];
        }
      }
    }
    cout << str << endl;
  }
  return 0;
}
Problem p00101 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI = 6 * asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
static const int INF = 1 << 24;

template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}

int main() {
  int n;
  cin >> n;
  string t;
  getline(cin, t);
  rep(i, n) {
    string s;
    getline(cin, s);
    // cout<<s.size()<<endl;
    rep(j, s.size() - 6) {
      if (s.substr(j, 7) == "Hoshino") {
        // cout<<"hoge"<<endl;
        // cout<<s[j+6]<<endl;
        s[j + 6] = 'a';
      }
    }
    cout << s << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define reep(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) reep((i), 0, (n))
#define ALL(v) (v).begin(), (v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI = 6 * asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
static const int INF = 1 << 24;

template <class T>
void initvv(vector<vector<T>> &v, int a, int b, const T &t = T()) {
  v.assign(a, vector<T>(b, t));
}

int main() {
  int n;
  cin >> n;
  string t;
  getline(cin, t);
  rep(i, n) {
    string s;
    getline(cin, s);
    // cout<<s.size()<<endl;
    if (s.size() < 7) {
      cout << s << endl;
      continue;
    }
    rep(j, s.size() - 6) {
      if (s.substr(j, 7) == "Hoshino") {
        // cout<<"hoge"<<endl;
        // cout<<s[j+6]<<endl;
        s[j + 6] = 'a';
      }
    }
    cout << s << endl;
  }
  return 0;
}
Problem p00101 (C++)

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

#define int long long

signed main() {
  int n;
  scanf("%d%*c", &n);
  for (int i = 0; i < n; ++i) {
    string s;
    getline(cin, s);
    regex re("Hoshino");
    cout << regex_replace(s, re, "Hoshina") << endl;
  }
  return 0;
}

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

signed main() {
  int n;
  scanf("%d%*c", &n);
  for (int i = 0; i < n; ++i) {
    string s;
    getline(cin, s);
    regex re("Hoshino");
    cout << regex_replace(s, re, "Hoshina") << endl;
  }
  return 0;
}
Problem p00101 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const double PI = 3.14159265359;

typedef complex<double> P;

typedef long long int li;

int main() {
  int n;
  string hos = "Hoshino";

  cin >> n;
  cin.ignore();
  while (n--) {
    string s;
    getline(cin, s);

    for (int i = 0; i < s.size() + 1 - hos.size(); i++) {
      if (s.substr(i, hos.size()) == hos) {
        s[i + hos.size() - 1] = 'a';
      }
    }

    cout << s << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

const double EPS = 1e-9;
const double PI = 3.14159265359;

typedef complex<double> P;

typedef long long int li;

int main() {
  int n;
  string hos = "Hoshino";

  cin >> n;
  cin.ignore();
  while (n--) {
    string s;
    getline(cin, s);

    int k = s.size() + 1 - hos.size();
    for (int i = 0; i < k; i++) {
      if (s.substr(i, hos.size()) == hos) {
        s[i + hos.size() - 1] = 'a';
      }
    }

    cout << s << endl;
  }

  return 0;
}
Problem p00101 (C++)

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

int main() {
  const std::string str_false = "Hoshino";
  const std::string str_true = "Hoshina";

  u_int num_of_data;
  std::string text;
  std::cin >> num_of_data;
  std::cin.ignore();

  for (u_int i = 0; i < num_of_data; ++i) {
    getline(std::cin, text);
    u_int index = 0;

    while ((index = text.find(str_false, index)) != std::string::npos)
      text.replace(index, str_false.size(), str_true);
    std::cout << text << std::endl;
  }

  return 0;
}

Fixed submission:
#include <iostream>
#include <string>

int main() {
  const std::string str_false = "Hoshino";
  const std::string str_true = "Hoshina";

  u_int num_of_data;
  std::string text;
  std::cin >> num_of_data;
  std::cin.ignore();

  for (u_int i = 0; i < num_of_data; ++i) {
    getline(std::cin, text);
    int index = 0;

    while ((index = text.find(str_false, index)) != std::string::npos)
      text.replace(index, str_false.size(), str_true);
    std::cout << text << std::endl;
  }

  return 0;
}
Problem p00101 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i, n) for (int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>())
#define clr(a, b) memset((a), (b), sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P>> PQ;

int n;
string str;

int main() {
  cin >> n;
  cin.ignore();
  rep(i, n) {
    getline(cin, str);
    rep(j, str.size() - 6) {
      if (str[j] == 'H' && str[j + 1] == 'o' && str[j + 2] == 's' &&
          str[j + 3] == 'h' && str[j + 4] == 'i' && str[j + 5] == 'n' &&
          str[j + 6] == 'o') {
        str[j + 6] = 'a';
      }
    }
    cout << str << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define INF 100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i, n) for (int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>())
#define clr(a, b) memset((a), (b), sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P>> PQ;

int n;
string str;

int main() {
  cin >> n;
  cin.ignore();
  rep(i, n) {
    getline(cin, str);
    if (str.size() < 7) {
      cout << str << endl;
      continue;
    }
    rep(j, str.size() - 6) {
      if (str[j] == 'H' && str[j + 1] == 'o' && str[j + 2] == 's' &&
          str[j + 3] == 'h' && str[j + 4] == 'i' && str[j + 5] == 'n' &&
          str[j + 6] == 'o') {
        str[j + 6] = 'a';
      }
    }
    cout << str << endl;
  }
}
Problem p00101 (C++)

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

int main() {
  int n;
  cin >> n;
  cin.get();
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin, s);
    for (int j = 0; j <= s.size() - 7; j++) {
      if (s.substr(j, 7) == "Hoshino")
        s[j + 6] = 'a';
    }
    cout << s << endl;
  }
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  cin.get();
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin, s);
    for (int j = 0; j < s.size(); j++) {
      if (s.substr(j, 7) == "Hoshino")
        s[j + 6] = 'a';
    }
    cout << s << endl;
  }
  return 0;
}