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

Buggy submission (status: Time Limit Exceeded):
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  vector<ll> a(n), b(n), a_cnt(n + 1), b_cnt(n + 1);
  REP(i, 0, n) {
    cin >> a[i];
    a_cnt[a[i]]++;
  }
  REP(i, 0, n) {
    cin >> b[i];
    b_cnt[b[i]]++;
  }

  vector<int> idx(n + 1);
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(),
       [&](int i, int j) { return a_cnt[i] > a_cnt[j]; });

  deque<pair<int, int>> dq;
  REP(i, 0, n + 1) {
    if (b_cnt[idx[i]] > 0)
      dq.emplace_back(idx[i], b_cnt[idx[i]]);
  }

  map<int, vector<int>> mp;
  REP(i, 0, n + 1) {
    if (a_cnt[idx[i]] == 0)
      break;
    int x = idx[i];
    while (!dq.empty() && dq.front().first == x) {
      dq.push_back(dq.front());
      dq.pop_front();
    }
    REP(_, 0, a_cnt[x]) {
      if (dq.front().first == x) {
        cout << "No" << endl;
        return 0;
      }
      mp[x].emplace_back(dq.front().first);
      dq.front().second--;
      if (dq.front().second == 0)
        dq.pop_front();
    }
  }

  cout << "Yes\n";
  REP(i, 0, n) {
    cout << mp[a[i]].back() << " ";
    mp[a[i]].pop_back();
  }
  cout << endl;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  vector<ll> a(n), b(n), a_cnt(n + 1), b_cnt(n + 1);
  REP(i, 0, n) {
    cin >> a[i];
    a_cnt[a[i]]++;
  }
  REP(i, 0, n) {
    cin >> b[i];
    b_cnt[b[i]]++;
  }

  vector<int> idx(n + 1);
  iota(idx.begin(), idx.end(), 0);
  sort(idx.begin(), idx.end(),
       [&](int i, int j) { return a_cnt[i] > a_cnt[j]; });

  deque<pair<int, int>> dq;
  REP(i, 0, n + 1) {
    if (b_cnt[idx[i]] > 0)
      dq.emplace_back(idx[i], b_cnt[idx[i]]);
  }

  map<int, vector<int>> mp;
  REP(i, 0, n + 1) {
    if (a_cnt[idx[i]] == 0)
      break;
    int x = idx[i];
    if (!dq.empty() && dq.front().first == x) {
      dq.push_back(dq.front());
      dq.pop_front();
    }
    REP(_, 0, a_cnt[x]) {
      if (dq.front().first == x) {
        cout << "No" << endl;
        return 0;
      }
      mp[x].emplace_back(dq.front().first);
      dq.front().second--;
      if (dq.front().second == 0)
        dq.pop_front();
    }
  }

  cout << "Yes\n";
  REP(i, 0, n) {
    cout << mp[a[i]].back() << " ";
    mp[a[i]].pop_back();
  }
  cout << endl;
}
Problem p02557 (C++)

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

int main() {
  int n;
  cin >> n;
  map<int, int> ma, mb;
  vi aa(n), bb(n);
  rep(i, n) {
    int a;
    cin >> a;
    ma[a]++;
    aa[i] = a;
  }
  queue<int> que;
  rep(i, n) {
    int b;
    cin >> b;
    mb[b]++;
    bb[i] = b;
  }
  for (auto x : ma) {
    if (x.second + mb[x.first] > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  vi ans;
  cout << "Yes" << endl;
  int i = 0;
  reverse(bb.begin(), bb.end());
  rep(i, n) { que.push(bb[i]); }
  while (!que.empty()) {
    if (que.front() != aa[i]) {
      ans.push_back(que.front());
      que.pop();
      i++;
    } else {
      que.push(que.front());
      que.pop();
    }
  }
  for (int x : ans)
    cout << x << " ";
  cout << endl;
}


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

int main() {
  int n;
  cin >> n;
  map<int, int> ma, mb;
  vi aa(n), bb(n);
  rep(i, n) {
    int a;
    cin >> a;
    ma[a]++;
    aa[i] = a;
  }
  queue<int> que;
  rep(i, n) {
    int b;
    cin >> b;
    mb[b]++;
    bb[i] = b;
  }
  for (auto x : ma) {
    if (x.second + mb[x.first] > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  vi ans;
  cout << "Yes" << endl;
  int i = 0;
  reverse(bb.begin(), bb.end());
  rep(i, n) {
    if (i % 3 == 0)
      que.push(bb[i]);
  }
  rep(i, n) {
    if (i % 3 == 1)
      que.push(bb[i]);
  }
  rep(i, n) {
    if (i % 3 == 2)
      que.push(bb[i]);
  }
  while (!que.empty()) {
    if (que.front() != aa[i]) {
      ans.push_back(que.front());
      que.pop();
      i++;
    } else {
      que.push(que.front());
      que.pop();
    }
  }
  for (int x : ans)
    cout << x << " ";
  cout << endl;
}
Problem p02557 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, a[200001], b[200001], ta[200001], tb[200001], l = 1, r = 1;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), ta[a[i]]++;
  for (int i = 1; i <= n; i++)
    scanf("%d", &b[i]), tb[b[i]]++;
  for (int i = 1; i <= n; i++)
    if (ta[i] + tb[i] > n)
      puts("No"), exit(0);
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= tb[i]; j++) {
      while (b[l])
        ++l;
      while (a[r] <= a[l] && r <= n)
        ++r;
      while (b[r])
        ++r;
      if (a[l] != i)
        b[l++] = i;
      else
        b[r++] = i;
    }
  }
  l = 1;
  for (int i = n + 1; b[i]; i++) {
    while (b[l])
      ++l;
    if (a[l] != b[i])
      a[l] = b[i];
    else {
      while (a[r = (rand() % n + 1)] == b[i] || b[r] == a[l])
        ;
      b[l] = b[r], b[r] = b[i];
    }
  }
  puts("Yes");
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, a[400001], b[400001], ta[400001], tb[400001], l = 1, r = 1;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]), ta[a[i]]++;
  for (int i = 1; i <= n; i++)
    scanf("%d", &b[i]), tb[b[i]]++;
  for (int i = 1; i <= n; i++)
    if (ta[i] + tb[i] > n)
      puts("No"), exit(0);
  memset(b, 0, sizeof(b));
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= tb[i]; j++) {
      while (b[l])
        ++l;
      while (a[r] <= a[l] && r <= n)
        ++r;
      while (b[r])
        ++r;
      if (a[l] != i)
        b[l++] = i;
      else
        b[r++] = i;
    }
  }
  l = 1;
  for (int i = n + 1; b[i]; i++) {
    while (b[l])
      ++l;
    if (a[l] != b[i])
      a[l] = b[i];
    else {
      while (a[r = (rand() % n + 1)] == b[i] || b[r] == a[l])
        ;
      b[l] = b[r], b[r] = b[i];
    }
  }
  puts("Yes");
  for (int i = 1; i <= n; i++)
    printf("%d ", b[i]);
  return 0;
}
Problem p02558 (C++)

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

using namespace std;

struct Unionfind {
  vector<int> par;
  vector<int> rank;

  void init(int n) {
    par.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; i++)
      par[i] = i;
  }

  int root(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y)
      return;
    else {
      if (rank[x] < rank[y])
        par[x] = y;
      else {
        par[y] = x;
        if (rank[x] == rank[y])
          rank[x]++;
      }
    }
  }

  bool issame(int x, int y) { return root(x) == root(y); }
};

int main() {
  int n, q;
  cin >> n >> q;
  Unionfind uf;
  uf.init(n);
  for (int i = 0; i < q; i++) {
    int query, a, b;
    cin >> query >> a >> b, a--, b--;
    if (query == 0)
      uf.unite(a, b);
    else
      cout << (uf.issame(a, b) ? 1 : 0) << endl;
  }
}

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

using namespace std;

struct Unionfind {
  vector<int> par;
  vector<int> rank;

  void init(int n) {
    par.resize(n);
    rank.resize(n);
    for (int i = 0; i < n; i++)
      par[i] = i;
  }

  int root(int x) {
    if (par[x] == x)
      return x;
    else
      return par[x] = root(par[x]);
  }

  void unite(int x, int y) {
    x = root(x), y = root(y);
    if (x == y)
      return;
    else {
      if (rank[x] < rank[y])
        par[x] = y;
      else {
        par[y] = x;
        if (rank[x] == rank[y])
          rank[x]++;
      }
    }
  }

  bool issame(int x, int y) { return root(x) == root(y); }
};

int main() {
  int n, q;
  cin >> n >> q;
  Unionfind uf;
  uf.init(n);
  for (int i = 0; i < q; i++) {
    int query, a, b;
    cin >> query >> a >> b;
    if (query == 0)
      uf.unite(a, b);
    else
      cout << (uf.issame(a, b) ? 1 : 0) << endl;
  }
}
Problem p02558 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fast                                                                   \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define int long long
using namespace std;

const int N = 1e5 + 5;
const int mod = 1e9 + 7;

int parent[N], siz[N];

void make_set(int v) { parent[v] = v; }

int find_set(int v) {
  while (v != parent[v])
    v = parent[v];
  return v;
}

void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (siz[a] < siz[b])
      swap(a, b);
    parent[b] = a;
    siz[a] += siz[b];
  }
}

int32_t main() {
  fast;
  memset(siz, 0, sizeof siz);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++)
    make_set(i);
  while (q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0)
      union_sets(u, v);
    else {
      if (find_set(u) == find_set(v))
        cout << 1 << endl;
      else
        cout << 0 << endl;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define fast                                                                   \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define int long long
using namespace std;

const int N = 2e5 + 5;
const int mod = 1e9 + 7;

int parent[N], siz[N];

void make_set(int v) { parent[v] = v; }

int find_set(int v) {
  while (v != parent[v])
    v = parent[v];
  return v;
}

void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (siz[a] < siz[b])
      swap(a, b);
    parent[b] = a;
    siz[a] += siz[b];
  }
}

int32_t main() {
  fast;
  memset(siz, 0, sizeof siz);
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n; i++)
    make_set(i);
  while (q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0)
      union_sets(u, v);
    else {
      if (find_set(u) == find_set(v))
        cout << 1 << endl;
      else
        cout << 0 << endl;
    }
  }
}
Problem p02558 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int n, m;

struct unionfind {
  int parent;
  int node;
  int edge;
};
unionfind g[100001];

void init() {
  for (int i = 0; i <= n; i++) {
    g[i].parent = i;
    g[i].node = 1;
    g[i].edge = 0;
  }
}

int find(int x) {
  if (x == g[x].parent) {
    return x;
  }
  int res = find(g[x].parent);
  g[x].node = g[res].node;
  g[x].edge = g[res].edge;
  g[x].parent = res;
  return res;
}

void merge(int x, int y) {
  if (x > y) {
    x ^= y;
    y ^= x;
    x ^= y;
  }
  g[x].node += g[y].node;
  g[x].edge += g[y].edge + 1;
  g[y].parent = x;
}

int main() {
  int q, a, u, v;
  cin >> n >> q;
  init();
  for (int i = 0; i < q; i++) {
    cin >> a >> u >> v;
    u = find(u);
    v = find(v);
    if (a == 0 && u != v) {
      merge(u, v);
    } else if (a == 1) {
      cout << (u == v ? 1 : 0) << endl;
    }
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int n, m;

struct unionfind {
  int parent;
  int node;
  int edge;
};
unionfind g[200001];

void init() {
  for (int i = 0; i <= n; i++) {
    g[i].parent = i;
    g[i].node = 1;
    g[i].edge = 0;
  }
}

int find(int x) {
  if (x == g[x].parent) {
    return x;
  }
  int res = find(g[x].parent);
  g[x].node = g[res].node;
  g[x].edge = g[res].edge;
  g[x].parent = res;
  return res;
}

void merge(int x, int y) {
  if (x > y) {
    x ^= y;
    y ^= x;
    x ^= y;
  }
  g[x].node += g[y].node;
  g[x].edge += g[y].edge + 1;
  g[y].parent = x;
}

int main() {
  int q, a, u, v;
  cin >> n >> q;
  init();
  for (int i = 0; i < q; i++) {
    cin >> a >> u >> v;
    u = find(u);
    v = find(v);
    if (a == 0 && u != v) {
      merge(u, v);
    } else if (a == 1) {
      cout << (u == v ? 1 : 0) << endl;
    }
  }
}
Problem p02558 (C++)

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

vector<int> root;
vector<int> Rank;

// 通常バージョン
int find(int x) {
  if (root[x] == x)
    return x;
  root[x] = find(root[x]);
  return root[x];
}

bool check(int x, int y) { return find(x) == find(y); }

void Union(int x, int y) {
  x = find(x);
  y = find(y);
  if (check(x, y)) {
    return;
  }
  if (Rank[x] >= Rank[y])
    root[y] = x;
  else
    root[x] = y;
  if (Rank[x] == Rank[y])
    Rank[x]++;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> set_root(n);
  for (int i = 0; i < n; i++)
    set_root[i] = i;
  root = set_root;
  vector<int> set_Rank(n, 0);
  Rank = set_Rank;
  for (int i = 0; i < m; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    u--;
    v--;
    if (t == 0)
      Union(u, v);
    if (t == 1)
      cout << check(u, v) << endl;
  }
}

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

vector<int> root;
vector<int> Rank;

// 通常バージョン
int find(int x) {
  if (root[x] == x)
    return x;
  root[x] = find(root[x]);
  return root[x];
}

bool check(int x, int y) { return find(x) == find(y); }

void Union(int x, int y) {
  x = find(x);
  y = find(y);
  if (check(x, y)) {
    return;
  }
  if (Rank[x] >= Rank[y])
    root[y] = x;
  else
    root[x] = y;
  if (Rank[x] == Rank[y])
    Rank[x]++;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> set_root(n);
  for (int i = 0; i < n; i++)
    set_root[i] = i;
  root = set_root;
  vector<int> set_Rank(n, 0);
  Rank = set_Rank;
  for (int i = 0; i < m; i++) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0)
      Union(u, v);
    if (t == 1)
      cout << check(u, v) << endl;
  }
}
Problem p02558 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  vector<int> par, size;
  UnionFind(int x) {
    par.resize(x);
    size.resize(x, 1);
    for (int i = 0; i < x; i++) {
      par[i] = i;
    }
  }
  int find(int x) {
    if (par[x] == x)
      return x;
    return par[x] = find(par[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int consize(int x) { return size[find(x)]; }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (size[x] < size[y]) {
      par[x] = y;
      size[y] += size[x];
    } else {
      par[y] = x;
      size[x] += size[y];
    }
  }
};
int main() {
  int N, M;
  cin >> N >> M;
  UnionFind Onion(M);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 0)
      Onion.unite(b, c);
    else
      cout << (Onion.same(b, c) ? 1 : 0) << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
struct UnionFind {
  vector<int> par, size;
  UnionFind(int x) {
    par.resize(x);
    size.resize(x, 1);
    for (int i = 0; i < x; i++) {
      par[i] = i;
    }
  }
  int find(int x) {
    if (par[x] == x)
      return x;
    return par[x] = find(par[x]);
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int consize(int x) { return size[find(x)]; }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y)
      return;
    if (size[x] < size[y]) {
      par[x] = y;
      size[y] += size[x];
    } else {
      par[y] = x;
      size[x] += size[y];
    }
  }
};
int main() {
  int N, M;
  cin >> N >> M;
  UnionFind Onion(N);
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 0)
      Onion.unite(b, c);
    else
      cout << (Onion.same(b, c) ? 1 : 0) << endl;
  }
}
Problem p02558 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
const int Mxn = 200005;
int p[Mxn];

int par(int u) {
  if (p[u] == u)
    return u;

  return (p[u] = par(p[u]));
}

int uni(int a, int b) {
  int p1 = par(a);
  int p2 = par(b);
  p[p2] = p1;
}

int main() {
  fastio;
  int n, q;
  cin >> n >> q;

  for (int i = 1; i <= n; i++)
    p[i] = i;
  while (q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0) {
      uni(u, v);
    } else {
      cout << (par(u) == par(v) ? 1 : 0) << "\n";
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
const int Mxn = 200005;
int p[Mxn];

int par(int u) {
  if (p[u] == u)
    return u;

  return (p[u] = par(p[u]));
}

void uni(int a, int b) {
  int p1 = par(a);
  int p2 = par(b);
  p[p2] = p1;
}

int main() {
  fastio;
  int n, q;
  cin >> n >> q;

  for (int i = 1; i <= n; i++)
    p[i] = i;
  while (q--) {
    int t, u, v;
    cin >> t >> u >> v;
    if (t == 0) {
      uni(u, v);
    } else {
      cout << (par(u) == par(v) ? 1 : 0) << "\n";
    }
  }
  return 0;
}
Problem p02559 (C++)

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

const int nax = 5e5 + 5;
vector<long long> st(2 * nax);
int n;

void modify(int p, int v) {
  for (st[p += n] += v; p > 0; p--)
    st[p >> 1] = st[p] + st[p ^ 1];
}

long long sum(int l, int r) {
  l += n, r += n;
  long long ans = 0;
  while (l < r) {
    if (l & 1)
      ans += st[l++];
    if (r & 1)
      ans += st[--r];
    l >>= 1, r >>= 1;
  }
  return ans;
}

int main() {
  int q, a, b, t;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    st[i] = 0;
    cin >> st[i + n];
  }
  for (int i = n - 1; i > 0; i--)
    st[i] = st[2 * i] + st[2 * i + 1];
  while (q--) {
    cin >> t >> a >> b;
    if (!t) {
      modify(a, b);
    } else
      cout << sum(a, b) << endl;
  }
  return 0;
}


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

const int nax = 5e5 + 5;
vector<long long> st(2 * nax);
int n;

void modify(int p, int v) {
  for (st[p += n] += v; p > 0; p >>= 1)
    st[p >> 1] = st[p] + st[p ^ 1];
}

long long sum(int l, int r) {
  l += n, r += n;
  long long ans = 0;
  while (l < r) {
    if (l & 1)
      ans += st[l++];
    if (r & 1)
      ans += st[--r];
    l >>= 1, r >>= 1;
  }
  return ans;
}

int main() {
  int q, a, b, t;
  cin >> n >> q;
  for (int i = 0; i < n; i++) {
    st[i] = 0;
    cin >> st[i + n];
  }
  for (int i = n - 1; i > 0; i--)
    st[i] = st[2 * i] + st[2 * i + 1];
  while (q--) {
    cin >> t >> a >> b;
    if (!t) {
      modify(a, b);
    } else
      cout << sum(a, b) << endl;
  }
  return 0;
}
Problem p02559 (C++)

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

template <class T> struct fenwick_tree {
  // using U = internal::to_unsigned_t<T>;
  using U = T;

public:
  fenwick_tree() : _n(0) {}
  fenwick_tree(int n) : _n(n), data(n) {}

  void add(int p, T x) {
    assert(0 <= p && p < _n);
    p++;
    while (p <= _n) {
      data[p - 1] += U(x);
      p += p & -p;
    }
  }

  T sum(int l, int r) {
    assert(0 <= l && l <= r && r <= _n);
    return sum(r) - sum(l);
  }

private:
  int _n;
  std::vector<U> data;

  U sum(int r) {
    U s = 0;
    while (r > 0) {
      s += data[r - 1];
      r -= r & -r;
    }
    return s;
  }
};

int main() {
  int N, Q, q, p, l, r;
  cin >> N >> Q;
  fenwick_tree<ll> ft(N);
  ll a, x;
  for (int i = 0; i < Q; i++) {
    cin >> a;
    ft.add(i, a);
  }
  for (int i = 0; i < Q; i++) {
    cin >> q;
    if (q) {
      cin >> l >> r;
      cout << ft.sum(l, r) << "\n";
    } else {
      cin >> p >> x;
      ft.add(p, x);
    }
  }
  return 0;
}

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

template <class T> struct fenwick_tree {
  // using U = internal::to_unsigned_t<T>;
  using U = T;

public:
  fenwick_tree() : _n(0) {}
  fenwick_tree(int n) : _n(n), data(n) {}

  void add(int p, T x) {
    assert(0 <= p && p < _n);
    p++;
    while (p <= _n) {
      data[p - 1] += U(x);
      p += p & -p;
    }
  }

  T sum(int l, int r) {
    assert(0 <= l && l <= r && r <= _n);
    return sum(r) - sum(l);
  }

private:
  int _n;
  std::vector<U> data;

  U sum(int r) {
    U s = 0;
    while (r > 0) {
      s += data[r - 1];
      r -= r & -r;
    }
    return s;
  }
};

int main() {
  int N, Q, q, p, l, r;
  cin >> N >> Q;
  fenwick_tree<ll> ft(N);
  ll a, x;
  for (int i = 0; i < N; i++) {
    cin >> a;
    ft.add(i, a);
  }
  for (int i = 0; i < Q; i++) {
    cin >> q;
    if (q) {
      cin >> l >> r;
      cout << ft.sum(l, r) << "\n";
    } else {
      cin >> p >> x;
      ft.add(p, x);
    }
  }
  return 0;
}
Problem p02559 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
using ui = unsigned int;
using ul = unsigned long;
#pragma GCC optimize("Ofast")
#define loop(i, n) for (ui i = 0; i < n; i++)
ul bit[500001];
struct BIT {
  ui n;
  inline ul sum(ui x) {
    ul ret = 0;
    while (x > 0) {
      ret += bit[x];
      x -= x & -x;
    }
    return ret;
  }
  BIT(ui n0) : n(n0) {}
  inline ul sum(ui l, ui r) { return sum(r + 1) - sum(l); }
  inline void add(ui i, ul x) {
    i++;
    while (i <= n) {
      bit[i] += x;
      i += i & -i;
    }
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ui N, Q;
  cin >> N >> Q;
  BIT data(N);
  loop(i, N) {
    ul A;
    cin >> A;
    bit[i + 1] = A;
  }
  for (ui i = 1; i < N; i++)
    bit[i + (i & -i)] += bit[i];
  loop(i, Q) {
    ui a, b, c;
    cin >> a >> b >> c;
    if (a == 0)
      data.add(b, c);
    else
      cout << data.sum(b, c - 1) << "\n";
  }
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
using ui = unsigned int;
using ul = unsigned long;
#pragma GCC optimize("Ofast")
#define loop(i, n) for (ui i = 0; i < n; i++)
ul bit[550001];
struct BIT {
  ui n;
  inline ul sum(ui x) {
    ul ret = 0;
    while (x > 0) {
      ret += bit[x];
      x -= x & -x;
    }
    return ret;
  }
  BIT(ui n0) : n(n0) {}
  inline ul sum(ui l, ui r) { return sum(r + 1) - sum(l); }
  inline void add(ui i, ul x) {
    i++;
    while (i <= n) {
      bit[i] += x;
      i += i & -i;
    }
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ui N, Q;
  cin >> N >> Q;
  BIT data(N);
  loop(i, N) {
    ul A;
    cin >> A;
    bit[i + 1] = A;
  }
  for (ui i = 1; i < N; i++)
    bit[i + (i & -i)] += bit[i];
  loop(i, Q) {
    ui a, b, c;
    cin >> a >> b >> c;
    if (a == 0)
      data.add(b, c);
    else
      cout << data.sum(b, c - 1) << "\n";
  }
  return 0;
}
Problem p02559 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pvllvll pair<vector<ll>, vector<ll>>
#define ld long double
#define veci vector<int>
#define vecll vector<ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

ll fw[(int)2e5 + 10];
int n, q;

void upd(int p, ll val) {
  for (; p <= n; p += (p & -p))
    fw[p] += val;
}

ll sum(int r) {
  ll res = 0;
  for (; r > 0; r -= (r & -r))
    res += fw[r];
  return res;
}
void solve() {
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    ll x;
    cin >> x;
    upd(i, x);
  }
  while (q--) {
    int t, p, x;
    cin >> t >> p >> x;
    if (!t)
      upd(p + 1, x);
    else
      cout << sum(x) - sum(p) << '\n';
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  /// cin >> T;
  while (T--)
    solve(), cout << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pvllvll pair<vector<ll>, vector<ll>>
#define ld long double
#define veci vector<int>
#define vecll vector<ll>

const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

ll fw[(int)5e5 + 10];
int n, q;

void upd(int p, ll val) {
  for (; p <= n; p += (p & -p))
    fw[p] += val;
}

ll sum(int r) {
  ll res = 0;
  for (; r > 0; r -= (r & -r))
    res += fw[r];
  return res;
}
void solve() {
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    ll x;
    cin >> x;
    upd(i, x);
  }
  while (q--) {
    int t, p, x;
    cin >> t >> p >> x;
    if (!t)
      upd(p + 1, x);
    else
      cout << sum(x) - sum(p) << '\n';
  }
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T = 1;
  /// cin >> T;
  while (T--)
    solve(), cout << '\n';
  return 0;
}
Problem p02559 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db double
#define filename "SUBKGCD"
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a, int b) {
  int ans = 1;
  while (b) {
    if (b % 2)
      ans *= a;
    a *= a;
    b /= 2;
  }
  return (ans);
}
const int mxn = 2e5 + 3;
int n, q;
int ft[2 * mxn];
void upd(int i, int v) {
  while (i <= n) {
    ft[i] += v;
    i += i & -i;
  }
}
int que(int i) {
  int res = 0;
  while (i >= 1) {
    res += ft[i];
    i -= i & -i;
  }
  return (res);
}
signed main() {
  // freopen(filename".inp","r",stdin);
  // freopen(filename".out","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    upd(i, x);
  }
  while (q--) {
    int qu, a, b;
    cin >> qu >> a >> b;
    if (qu == 0) {
      upd(a + 1, b);
    } else
      cout << que(b) - que(a) << "\n";
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db double
#define filename "SUBKGCD"
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a, int b) {
  int ans = 1;
  while (b) {
    if (b % 2)
      ans *= a;
    a *= a;
    b /= 2;
  }
  return (ans);
}
const int mxn = 5e5 + 3;
int n, q;
int ft[2 * mxn];
void upd(int i, int v) {
  while (i <= n) {
    ft[i] += v;
    i += i & -i;
  }
}
int que(int i) {
  int res = 0;
  while (i >= 1) {
    res += ft[i];
    i -= i & -i;
  }
  return (res);
}
signed main() {
  // freopen(filename".inp","r",stdin);
  // freopen(filename".out","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    upd(i, x);
  }
  while (q--) {
    int qu, a, b;
    cin >> qu >> a >> b;
    if (qu == 0) {
      upd(a + 1, b);
    } else
      cout << que(b) - que(a) << "\n";
  }
  return 0;
}
Problem p02561 (Python)

Buggy submission (status: Runtime Error):
import sys
import itertools
import numpy as np
import networkx as nx

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
S = np.frombuffer(read(), "S1").reshape(N, -1)[:, :M].astype("U1")

A = []
B = []
E = []

for i, j in itertools.product(range(N), range(M)):
    if S[i, j] == "#":
        continue
    elif (i + j) & 1:
        A.append((i, j))
    else:
        B.append((i, j))

for i, j in A:
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        i1, j1 = i + dx, j + dy
        if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != "#":
            E.append(((i, j), (i1, j1)))

G = nx.Graph()
G.add_nodes_from(A, bipartite=0)
G.add_nodes_from(B, bipartite=1)
G.add_edges_from(E)

M = nx.bipartite.eppstein_matching(G)
for key, item in M.items():
    i, j = key
    i1, j1 = item
    if i1 == i + 1:
        a, b = "v", "^"
    elif i1 == i - 1:
        a, b = "^", "v"
    elif j1 == j + 1:
        a, b = ">", "<"
    else:
        a, b = "<", ">"
    S[i, j], S[i1, j1] = a, b

print(len(M) // 2)
for row in S:
    print("".join(row))


Fixed submission:
import sys
import itertools
import numpy as np
import networkx as nx

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, readline().split())
S = np.frombuffer(read(), "S1").reshape(N, -1)[:, :M].astype("U1")

A = []
B = []
E = []

for i, j in itertools.product(range(N), range(M)):
    if S[i, j] == "#":
        continue
    elif (i + j) & 1:
        A.append((i, j))
    else:
        B.append((i, j))

for i, j in A:
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        i1, j1 = i + dx, j + dy
        if 0 <= i1 < N and 0 <= j1 < M and S[i1, j1] != "#":
            E.append(((i, j), (i1, j1)))

G = nx.Graph()
G.add_nodes_from(A, bipartite=0)
G.add_nodes_from(B, bipartite=1)
G.add_edges_from(E)

M = nx.bipartite.eppstein_matching(G, A)
for key, item in M.items():
    i, j = key
    i1, j1 = item
    if i1 == i + 1:
        a, b = "v", "^"
    elif i1 == i - 1:
        a, b = "^", "v"
    elif j1 == j + 1:
        a, b = ">", "<"
    else:
        a, b = "<", ">"
    S[i, j], S[i1, j1] = a, b

print(len(M) // 2)
for row in S:
    print("".join(row))
Problem p02570 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  int d, t, s;
  printf("距離・待ち合わせ時刻・分速を入力...");
  scanf("%d $d %d", &d, &t, &s);
  if (d / s <= t) {
    printf("Yes");
  } else
    printf("No");
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int d, t, s;
  scanf("%d %d %d", &d, &t, &s);
  if (t * s >= d) {
    printf("Yes");
  } else
    printf("No");
  return 0;
}
Problem p02570 (C++)

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

int main(int args, char *argc[]) {
  int D = std::stoi(std::string(argc[1]));
  int T = std::stoi(std::string(argc[2]));
  int S = std::stoi(std::string(argc[3]));

  if (T * S >= D)
    std::cout << "Yes";
  else
    std::cout << "No";

  std::cout << std::endl;
  return 0;
}

Fixed submission:
#include <iostream>

int main(void) {
  int D, T, S;
  std::cin >> D >> T >> S;

  if (T * S >= D)
    std::cout << "Yes";
  else
    std::cout << "No";

  std::cout << std::endl;
  return 0;
}
Problem p02570 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int MAX = 1e5 + 10;
using namespace std;

int solve() {
  int d, t, s;
  cin >> d >> t >> s;
  cout << (t * s >= d ? "Yes" : "No") << endl;
}

signed main() {
  // ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int _ = 1;
  //    cin>>_;
  while (_--) {
    solve();
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
// #define int ll
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int MAX = 1e5 + 10;
using namespace std;

int solve() {
  int d, t, s;
  cin >> d >> t >> s;
  cout << (t * s >= d ? "Yes" : "No") << endl;
  return 0;
}

signed main() {
  // ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  int _ = 1;
  //    cin>>_;
  while (_--) {
    solve();
  }
  return 0;
}
Problem p02570 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  if (s * t >= d) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
  return 1;
}

Fixed submission:
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  if (s * t >= d) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
  return 0;
}
Problem p02570 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
int main() {
  float d, t, s;
  scanf("%f %f %f", &d, &t, &s);
  return (d / s <= t);
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
int main() {
  float d, t, s;
  scanf("%f %f %f", &d, &t, &s);
  if (d / s <= t) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}
Problem p02570 (C++)

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

#define ll long long int
#define mod 1000000007

/*
cout<<"\ndebugging\n";
*/

int main() {
  ios_base::sync_with_stdio(false); // Fast I/O
  cin.tie(NULL);

  double t, n, i, j, d, s;
  cin >> d >> t >> s;

  if (d <= s * t)
    return true;
  return false;

  return 0;
}


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

#define ll long long int
#define mod 1000000007

/*
cout<<"\ndebugging\n";
*/

int main() {
  ios_base::sync_with_stdio(false); // Fast I/O
  cin.tie(NULL);

  double t, n, i, j, d, s;
  cin >> d >> t >> s;

  if (d <= s * t)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}
Problem p02570 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main() {
  string s, t;
  cin >> s >> t;
  int ans = INT_MAX;
  for (int i = 0; i < s.length() - t.length() + 1; i++) {
    string str = s.substr(i, i + t.length());
    int c = 0;
    for (int j = 0; j < t.length(); j++) {
      if (t[j] != str[j])
        c++;
    }
    ans = min(c, ans);
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main() {
  int d, t, s;
  cin >> d >> t >> s;
  if (d <= (t * s)) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;
}
Problem p02570 (C++)

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

int main() {
  int d, t, s;
  scanf("%d %d %d", &d, &t, &s);

  return t * s >= d;
}

Fixed submission:
#include <cstdio>

int main() {
  int d, t, s;
  scanf("%d %d %d", &d, &t, &s);

  if (t * s >= d) {
    printf("Yes");
  } else {
    printf("No");
  }
}
Problem p02570 (Python)

Buggy submission (status: Runtime Error):
D, T, S = list(map(input().split()))

if D <= S * T:
    print("Yes")
else:
    print("No")


Fixed submission:
D, T, S = list(map(int, input().split()))

if D <= S * T:
    print("Yes")
else:
    print("No")
Problem p02570 (Python)

Buggy submission (status: Runtime Error):
d, t, s = int(input())
a = d / s
print("Yes" if a <= t else "No")


Fixed submission:
d, t, s = map(int, input().split())
a = d / s
print("Yes" if a <= t else "No")
Problem p02570 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s, t, u;
  int ans, c;
  cin >> s >> t;
  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    u = s.substr(i, t.size());
    c = 0;
    for (int j = 0; j < t.size(); j++) {
      if (u[j] != t[j]) {
        c++;
      }
    }
    ans = min(1000, c);
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  double a, b, c;
  cin >> a >> b >> c;
  if (b >= a / c) {
    cout << "Yes";
  } else
    cout << "No";
  return 0;
}
Problem p02570 (C++)

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

  int d, t, s;

  cin >> d >> t >> s;

  double speed = d / (t * 1.0);

  cout << (s >= speed ? "Yes" : "No");
  main();
  return 0;
}


Fixed submission:
#include <iostream>
using namespace std;
int main() {

  int d, t, s;

  cin >> d >> t >> s;

  double speed = d / (t * 1.0);

  cout << (s >= speed ? "Yes" : "No");

  return 0;
}
Problem p02570 (C++)

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

int main() {
  int D, T, S;
  cin >> D, T, S;
  if (D / S < T) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  int D, T, S;
  cin >> D >> T >> S;
  if (T * S >= D) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02571 (C++)

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

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

  int ns = s.size();
  int nt = t.size();
  vector<int> match(ns - nt + 1);
  match[0] = nt;

  for (int i = 0; i < ns - nt + 1; i++) {
    int mat = nt;
    for (int j = 0; j < nt; j++) {
      if (t[j] == s[i + j]) {
        mat--;
      }
    }
    match[i + 1] = min(match[i], mat);
  }

  cout << match[ns - nt + 1] << endl;
}


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

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

  int ns = s.size();
  int nt = t.size();
  vector<int> match(ns - nt + 2);
  match[0] = nt;

  for (int i = 0; i < ns - nt + 1; i++) {
    int mat = nt;
    for (int j = 0; j < nt; j++) {
      if (t[j] == s[i + j]) {
        mat--;
      }
    }
    match[i + 1] = min(match[i], mat);
  }

  cout << match[ns - nt + 1] << endl;
}
Problem p02571 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define FAST_IO                                                                \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define int long long int
#define nl "\n"
using namespace std;

void code() {
  string s, t;
  cin >> s >> t;
  int maxm = INT_MIN;
  for (int i = 0; i <= ((int)s.size() - (int)t.size()); i++) {
    int count = 0;
    for (int j = i; j < (int)t.size(); i++) {
      if (s[j] == t[j - i])
        count++;
    }
    maxm = max(maxm, count);
  }
  cout << (int)t.size() - maxm;
}
signed main()

{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  FAST_IO;
  int t = 1;

  // cin>>t;

  while (t--) {
    code();
  }

#ifndef ONLINE_JUDGE
  cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define FAST_IO                                                                \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define int long long int
#define nl "\n"
using namespace std;

void code() {
  string s, t;
  cin >> s >> t;
  int maxm = INT_MIN;
  for (int i = 0; i <= ((int)s.size() - (int)t.size()); i++) {
    int count = 0;
    for (int j = i; j < i + (int)t.size(); j++) {
      if (s[j] == t[j - i])
        count++;
    }
    maxm = max(maxm, count);
  }
  cout << (int)t.size() - maxm;
}
signed main()

{

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  FAST_IO;
  int t = 1;

  // cin>>t;

  while (t--) {
    code();
  }

#ifndef ONLINE_JUDGE
  cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif

  return 0;
}
Problem p02571 (C++)

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

int main(void) {
  string s, t;
  cin >> s >> t;

  int cost = -1;
  for (int i = 0; i < s.length() - t.length() - 1; i++) {
    int cnt = 0;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != t[j])
        cnt++;
    }
    if (cost > cnt || cost == -1) {
      cost = cnt;
    }
  }

  cout << cost << '\n';

  return 0;
}

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

int main(void) {
  string s, t;
  cin >> s >> t;

  int cost = -1;
  for (int i = 0; i < s.length() - t.length() + 1; i++) {
    int cnt = 0;
    for (int j = 0; j < t.length(); j++) {
      if (s[i + j] != t[j])
        cnt++;
    }
    if (cost > cnt || cost == -1) {
      cost = cnt;
    }
  }

  cout << cost << '\n';

  return 0;
}
Problem p02571 (C++)

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

int main() {
  string s, t;
  int i = 0;
  int z = t.size();
  while (s.size() - i >= t.size()) {
    int r = 0;
    for (int j = 0; j < t.size(); j++)
      if (s[i + j] != t[j])
        r++;

    if (r < z)
      z = r;
    i++;
  }
  cout << z << endl;
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int i = 0;
  int z = t.size();
  while (s.size() - i >= t.size()) {
    int r = 0;
    for (int j = 0; j < t.size(); j++)
      if (s[i + j] != t[j])
        r++;

    if (r < z)
      z = r;
    i++;
  }
  cout << z << endl;
}
Problem p02571 (C++)

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

int main() {
  string s;
  cin >> s;
  string t;
  cin >> t;
  int sl = s.length();
  int tl = t.length();
  vector<int> v(sl - tl);
  for (int i = 0; i < sl - tl; i++) {
    for (int j = 0; j < tl; j++) {
      if (s[i + j] == t[j])
        v[i]++;
    }
  }
  cout << tl - *max_element(v.begin(), v.end());
}

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

int main() {
  string s;
  cin >> s;
  string t;
  cin >> t;
  int sl = s.length();
  int tl = t.length();
  vector<int> v(sl - tl + 1);
  for (int i = 0; i <= sl - tl; i++) {
    for (int j = 0; j < tl; j++) {
      if (s[i + j] == t[j])
        v[i]++;
    }
  }
  cout << tl - *max_element(v.begin(), v.end());
}
Problem p02571 (C++)

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

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  int M = T.size();

  vector<int> V;
  int P = 0;
  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < M; j++) {
      if (S.at(i + j) == T.at(j))
        P++;
    }
    V.push_back(M - P);
    P = 0;
  }

  sort(V.begin(), V.end());
  cout << V.at(1) << endl;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  int M = T.size();

  vector<int> V;
  int P = 0;
  for (int i = 0; i < N - M + 1; i++) {
    for (int j = 0; j < M; j++) {
      if (S.at(i + j) == T.at(j))
        P++;
    }
    V.push_back(M - P);
    P = 0;
  }

  sort(V.begin(), V.end());
  cout << V.at(0) << endl;
}
Problem p02571 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int i, d = 0, c = 0, j;
  for (i = 0; i <= a.size() - b.size() - 1; i++) {
    c = 0;
    for (j = i; j <= i + b.size() - 1; j++) {
      if (a[j] == b[j - i]) {
        c++;
      }
    }
    if (c > d) {
      d = c;
    }
  }
  cout << b.size() - d;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int i, d = 0, c = 0, j;
  for (i = 0; i <= a.size() - b.size(); i++) {
    c = 0;
    for (j = i; j <= i + b.size() - 1; j++) {
      if (a[j] == b[j - i]) {
        c++;
      }
    }
    if (c > d) {
      d = c;
    }
  }
  cout << b.size() - d;
  return 0;
}
Problem p02571 (C++)

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

int main() {
  string b, t;
  cin >> b >> t;
  int ct = 0;
  int minct = t.size();
  for (int i = 0; i < (int)b.size(); i++) {
    if (b.at(i) != t.at(0))
      continue;
    for (int j = 0; j < (int)t.size(); j++) {
      if (b.at(i + j) != t.at(j)) {
        ct++;
      }
    }
    minct = min(minct, ct);
    ct = 0;
  }
  cout << minct;
}

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

int main() {
  string b, t;
  cin >> b >> t;
  int ct = 0;
  int minct = t.size();
  for (int i = 0; i < (int)b.size(); i++) {
    if (i + (int)t.size() > (int)b.size())
      break;
    for (int j = 0; j < (int)t.size(); j++) {
      if (b.at(i + j) != t.at(j)) {
        ct++;
      }
    }
    minct = min(minct, ct);
    ct = 0;
  }
  cout << minct;
}
Problem p02571 (C++)

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

int main() {
  int ans = INF;
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < S.size() - T.size() - 1; i++) {
    int cnt = 0;
    for (int j = 0; j < T.size(); j++) {
      if (S[i + j] != T[j]) {
        cnt++;
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

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

typedef long long ll;

int main() {
  int ans = INF;
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < S.size() - T.size() + 1; i++) {
    int cnt = 0;
    for (int j = 0; j < T.size(); j++) {
      if (S[i + j] != T[j]) {
        cnt++;
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}