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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INCANT                                                                 \
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0),                            \
      cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7LL;
const int INF = 2e9;
int n;
string S;
int c[101]; // 羊1, 狼0

bool dfs(int idx, int now, int pre) {
  if (idx == n - 1 && c[idx] != now)
    return false;
  if (idx == n)
    return c[0] == now;
  c[idx] = now;
  if (S[idx] == 'o') {
    if (now)
      return dfs(idx + 1, pre, now);
    else
      return dfs(idx + 1, !pre, now);
  } else {
    if (now)
      return dfs(idx + 1, !pre, now);
    else
      return dfs(idx + 1, pre, now);
  }
  return 0;
}

int main() {
  INCANT;
  cin >> n >> S;

  rep(i, 2) {
    rep(j, 2) {
      fill(c, c + n, -1);
      c[0] = j;
      if (S[0] == 'o')
        c[n - 1] = j ? i : !i;
      else
        c[n - 1] = j ? !i : i;
      if (dfs(1, i, j)) {
        rep(k, n) {
          char a = c[k] ? 'S' : 'W';
          cout << a;
        }
        cout << endl;
        return 0;
      }
    }
  }
  cout << -1 << "\n";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INCANT                                                                 \
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0),                            \
      cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7LL;
const int INF = 2e9;
int n;
string S;
int c[100001]; // 羊1, 狼0

bool dfs(int idx, int now, int pre) {
  if (idx == n - 1 && c[idx] != now)
    return false;
  if (idx == n)
    return c[0] == now;
  c[idx] = now;
  if (S[idx] == 'o') {
    if (now)
      return dfs(idx + 1, pre, now);
    else
      return dfs(idx + 1, !pre, now);
  } else {
    if (now)
      return dfs(idx + 1, !pre, now);
    else
      return dfs(idx + 1, pre, now);
  }
  return 0;
}

int main() {
  INCANT;
  cin >> n >> S;

  rep(i, 2) {
    rep(j, 2) {
      fill(c, c + n, -1);
      c[0] = j;
      if (S[0] == 'o')
        c[n - 1] = j ? i : !i;
      else
        c[n - 1] = j ? !i : i;
      if (dfs(1, i, j)) {
        rep(k, n) {
          char a = c[k] ? 'S' : 'W';
          cout << a;
        }
        cout << endl;
        return 0;
      }
    }
  }
  cout << -1 << "\n";
  return 0;
}
Problem p03801 (C++)

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

int N;
int A[101010];
LL ans[101010];
LL T[101010];
vector<int> V, id;

void update(int t) {
  while (t <= N) {
    T[t]++;
    t += t & -t;
  }
}

LL read(int t) {
  LL ret = 0;
  while (t) {
    ret += T[t];
    t -= t & -t;
  }
  return ret;
}

int main() {
  scanf("%d", &N);
  V.push_back(0);
  id.push_back(0);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    if (V.back() >= A[i]) {
      int k = upper_bound(V.begin(), V.end(), A[i]) - V.begin();
      if (k > 1)
        update(k - 1);
      ans[id[k]] += A[i] - V[k - 1];
    } else {
      if (!V.empty())
        update(V.size());
      V.push_back(A[i]);
      id.push_back(i);
    }
  }
  for (int i = 1; i < (int)V.size(); i++)
    ans[id[i]] += (read(N) - read(i - 1)) * (V[i] - V[i - 1]);
  for (int i = 1; i <= N; i++)
    printf("%lld\n", ans[i]);
  return 0;
}


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

int N;
int A[101010];
LL ans[101010];
LL T[101010];
vector<int> V, id;

void update(int t) {
  while (t <= N) {
    T[t]++;
    t += t & -t;
  }
}

LL read(int t) {
  LL ret = 0;
  while (t) {
    ret += T[t];
    t -= t & -t;
  }
  return ret;
}

int main() {
  scanf("%d", &N);
  V.push_back(0);
  id.push_back(0);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &A[i]);
    if (V.back() >= A[i]) {
      int k = upper_bound(V.begin(), V.end(), A[i]) - V.begin();
      if (k > 1)
        update(k - 1);
      if (k < V.size())
        ans[id[k]] += A[i] - V[k - 1];
    } else {
      if (!V.empty())
        update(V.size());
      V.push_back(A[i]);
      id.push_back(i);
    }
  }
  for (int i = 1; i < (int)V.size(); i++)
    ans[id[i]] += (read(N) - read(i - 1)) * (V[i] - V[i - 1]);
  for (int i = 1; i <= N; i++)
    printf("%lld\n", ans[i]);
  return 0;
}
Problem p03801 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  vector<vector<ll>> big; // a, index
  big.push_back({0, -1});
  ll temp = 0;
  for (ll i = 0; i < N; ++i) {
    if (temp < A.at(i)) {
      temp = A.at(i);
      big.push_back({A.at(i), i});
    }
  }
  A.push_back(0);
  sort(A.begin(), A.end());
  sort(big.begin(), big.end());
  ll sum = 0;
  vector<ll> ans(N, 0);
  ll index = 1;
  for (ll i = 0; i < N; ++i) {
    if (A.at(i) < big.at(index).at(0)) {
      ans.at(big.at(index).at(1)) += A.at(i) - big.at(index - 1).at(0);
    } else {
      index += 1;
    }
  }
  for (ll i = 0; i < big.size() - 1; ++i) {
    ans.at(big.at(i + 1).at(1)) +=
        (big.at(i + 1).at(0) - big.at(i).at(0)) *
        (A.end() - lower_bound(A.begin(), A.end(), big.at(i + 1).at(0)));
  }
  for (ll i = 0; i < ans.size(); ++i) {
    cout << ans.at(i) << "\n";
  }
  // ans.at(big.at(big.size() - 1).at(1)) += sum;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    cin >> A.at(i);
  }
  vector<vector<ll>> big; // a, index
  big.push_back({0, -1});
  ll temp = 0;
  for (ll i = 0; i < N; ++i) {
    if (temp < A.at(i)) {
      temp = A.at(i);
      big.push_back({A.at(i), i});
    }
  }
  A.push_back(0);
  sort(A.begin(), A.end());
  sort(big.begin(), big.end());
  ll sum = 0;
  vector<ll> ans(N, 0);
  ll index = 1;
  for (ll i = 0; i < N; ++i) {
    if (index == big.size()) {
      break;
    }
    if (A.at(i) < big.at(index).at(0)) {
      ans.at(big.at(index).at(1)) += A.at(i) - big.at(index - 1).at(0);
    } else {
      index += 1;
    }
  }
  for (ll i = 0; i < big.size() - 1; ++i) {
    ans.at(big.at(i + 1).at(1)) +=
        (big.at(i + 1).at(0) - big.at(i).at(0)) *
        (A.end() - lower_bound(A.begin(), A.end(), big.at(i + 1).at(0)));
  }
  for (ll i = 0; i < ans.size(); ++i) {
    cout << ans.at(i) << "\n";
  }
  // ans.at(big.at(big.size() - 1).at(1)) += sum;
}
Problem p03801 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n, nw, a[100005], b[100005];
long long ans[100005];
bool cmp(int x, int y) { return a[x] >= a[y]; }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; i++)
    b[i] = i;
  sort(b, b + n, cmp);
  b[n] = n;
  int nw = b[0];
  for (int i = 0; i < n; i++, nw = min(nw, b[i]))
    ans[nw] += 1ll * (a[b[i]] - a[b[i + 1]]) * (i + 1);
  for (int i = 0; i < n; i++)
    printf("%lld\n", ans[i]);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n, nw, a[100005], b[100005];
long long ans[100005];
bool cmp(int x, int y) { return a[x] > a[y] || (a[x] == a[y] && x < y); }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for (int i = 0; i < n; i++)
    b[i] = i;
  sort(b, b + n, cmp);
  b[n] = n;
  int nw = b[0];
  for (int i = 0; i < n; i++, nw = min(nw, b[i]))
    ans[nw] += 1ll * (a[b[i]] - a[b[i + 1]]) * (i + 1);
  for (int i = 0; i < n; i++)
    printf("%lld\n", ans[i]);
  return 0;
}
Problem p03801 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 60)
signed main() {
  int N;
  cin >> N;
  stack<pii> Q;
  vi A(N);
  rep(i, 0, N) cin >> A[i];
  reverse(ALL(A));
  Q.push(mp(0, N));
  REP(i, 1, N) {
    if (Q.top() < mp(A[N - i], N - i))
      Q.push(mp(A[N - i], N - i));
  }
  map<int, int, greater<int>> M;
  vi ans(N);
  int memo = 0, cnt = 0;
  while (Q.size() > 0) {
    int X = Q.top().first, Y = Q.top().second;
    Q.pop();
    for (cnt; cnt < Y; cnt++) {
      M[A[cnt]]++;
    }
    for (auto p : M) {
      if (p.first <= X)
        break;
      M[X] += p.second;
      ans[memo] += p.second * (p.first - X);
      M[p.first] = 0;
    }
    memo = Y;
  }
  reverse(ALL(ans));
  rep(i, 0, N) cout << ans[i] << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 60)
signed main() {
  int N;
  cin >> N;
  stack<pii> Q;
  vi A(N);
  rep(i, 0, N) cin >> A[i];
  reverse(ALL(A));
  Q.push(mp(0, N));
  REP(i, 1, N) {
    if (Q.top() < mp(A[N - i], N - i))
      Q.push(mp(A[N - i], N - i));
  }
  map<int, int, greater<int>> M;
  vi ans(N);
  int memo = 0, cnt = 0;
  while (Q.size() > 0) {
    int X = Q.top().first, Y = Q.top().second;
    Q.pop();
    for (cnt; cnt < Y; cnt++) {
      M[A[cnt]]++;
    }
    for (auto p : M) {
      if (p.first <= X)
        break;
      M[X] += p.second;
      ans[memo] += p.second * (p.first - X);
      M.erase(p.first);
    }
    memo = Y;
  }
  reverse(ALL(ans));
  rep(i, 0, N) cout << ans[i] << endl;
}
Problem p03801 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <stdio.h>
#include <utility>
typedef long long ll;
using namespace std;

bool cmp(pair<ll, ll> &a, pair<ll, ll> &b) {
  if (a.first > b.first)
    return true;
  if (a.first < b.first)
    return false;
  if (a.first < b.second)
    return true;
  return false;
}

int main(void) {
  ll i, j, k, n, cnt = 1, now = 0, max, sum = 0;
  scanf("%lld", &n);
  pair<ll, ll> a[n];
  ll ans[n];
  for (i = 0; i < n; ++i) {
    scanf("%lld", &a[i].first);
    a[i].second = i;
    ans[i] = 0;
  }
  sort(a, a + n, cmp);
  now = a[0].second, max = sum = a[0].first;
  for (i = 1; i < n; ++i) {
    if (now > a[i].second) {
      ans[now] = sum - cnt * a[i].first + (i - cnt) * (max - a[i].first);
      now = a[i].second, cnt = 1, max = sum = a[i].first;
    } else
      sum += a[i].first, cnt++;
  }
  ans[now] = sum + (n - cnt) * max;
  for (i = 0; i < n; ++i)
    printf("%lld\n", ans[i]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
#include <utility>
typedef long long ll;
using namespace std;

bool cmp(pair<ll, ll> &a, pair<ll, ll> &b) {
  if (a.first > b.first)
    return true;
  if (a.first < b.first)
    return false;
  if (a.second < b.second)
    return true;
  return false;
}

int main(void) {
  ll i, j, k, n, cnt = 1, now = 0, max, sum = 0;
  scanf("%lld", &n);
  pair<ll, ll> a[n];
  ll ans[n];
  for (i = 0; i < n; ++i) {
    scanf("%lld", &a[i].first);
    a[i].second = i;
    ans[i] = 0;
  }
  sort(a, a + n, cmp);
  now = a[0].second, max = sum = a[0].first;
  for (i = 1; i < n; ++i) {
    if (now > a[i].second) {
      ans[now] = sum - cnt * a[i].first + (i - cnt) * (max - a[i].first);
      now = a[i].second, cnt = 1, max = sum = a[i].first;
    } else
      sum += a[i].first, cnt++;
  }
  ans[now] = sum + (n - cnt) * max;
  for (i = 0; i < n; ++i)
    printf("%lld\n", ans[i]);
  return 0;
}
Problem p03801 (C++)

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

#define FOR(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define ALL(x) x.begin(), x.end()
template <typename T> bool chmax(T &a, const T &b) {
  return a < b ? (a = b, true) : false;
}
template <typename T> bool chmin(T &a, const T &b) {
  return b < a ? (a = b, true) : false;
}
typedef long long ll;

int N;

int main() {
  scanf("%d", &N);
  vector<ll> A(N);
  FOR(i, 0, N) { scanf("%lld", &A[i]); }
  ll acc = accumulate(ALL(A), 0ll);
  int idx = -1;
  vector<pair<ll, int>> v, w;
  FOR(i, 0, N) {
    if (idx == -1 || A[i] > A[idx]) {
      idx = i;
      v.push_back({A[i], i});
    } else {
      w.push_back({A[i], i});
    }
  }
  sort(ALL(v));

  vector<pair<ll, ll>> ans(N);
  FOR(i, 0, w.size()) {
    auto x = upper_bound(ALL(v), pair<ll, int>(w[i].first, 0));
    if (x == v.begin()) {
      continue;
    }
    auto y = x;
    y--;
    ans[x->second].first += w[i].first - y->first;
    ans[y->second].second++;
  }

  for (int i = v.size() - 1; i >= 0; i--) {
    ans[v[i].second].second++;
    ans[v[i].second].first +=
        ans[v[i].second].second * (v[i].first - v[i - 1].first);
    ans[v[i - 1].second].second += ans[v[i].second].second;
  }

  ll sum = 0;
  FOR(i, 1, N) { sum += ans[i].first; }
  ans[0].first = acc - sum;
  FOR(i, 0, N) { printf("%lld\n", ans[i].first); }

  return 0;
}


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

#define FOR(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define ALL(x) x.begin(), x.end()
template <typename T> bool chmax(T &a, const T &b) {
  return a < b ? (a = b, true) : false;
}
template <typename T> bool chmin(T &a, const T &b) {
  return b < a ? (a = b, true) : false;
}
typedef long long ll;

int N;

int main() {
  scanf("%d", &N);
  vector<ll> A(N);
  FOR(i, 0, N) { scanf("%lld", &A[i]); }
  ll acc = accumulate(ALL(A), 0ll);
  int idx = -1;
  vector<pair<ll, int>> v, w;
  FOR(i, 0, N) {
    if (idx == -1 || A[i] > A[idx]) {
      idx = i;
      v.push_back({A[i], i});
    } else {
      w.push_back({A[i], i});
    }
  }
  sort(ALL(v));

  vector<pair<ll, ll>> ans(N);
  FOR(i, 0, w.size()) {
    auto x = upper_bound(ALL(v), pair<ll, int>(w[i].first, 0));
    if (x == v.begin()) {
      continue;
    }
    auto y = x;
    y--;
    ans[x->second].first += w[i].first - y->first;
    ans[y->second].second++;
  }

  for (int i = v.size() - 1; i > 0; i--) {
    ans[v[i].second].second++;
    ans[v[i].second].first +=
        ans[v[i].second].second * (v[i].first - v[i - 1].first);
    ans[v[i - 1].second].second += ans[v[i].second].second;
  }

  ll sum = 0;
  FOR(i, 1, N) { sum += ans[i].first; }
  ans[0].first = acc - sum;
  FOR(i, 0, N) { printf("%lld\n", ans[i].first); }

  return 0;
}
Problem p03801 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
const int N = 1e5 + 5, INF = 1e9;
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>;
int n, a[N], f[N], s[N], prv[N], pos[N], tot;
set<pii> st;
pii ss[N];
signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    tot += a[i];
    ss[i] = {a[i], i};
  }
  sort(ss + 1, ss + n + 1);
  s[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    s[i] = s[i + 1] + ss[i].F;
    pos[ss[i].S] = i;
  }
  st.insert({a[1], 1});
  int mx = a[1], mxi = 1;
  for (int i = 2; i <= n; i++) {
    prv[i] = (*(--st.upper_bound({a[i], 0}))).S;
    prv[i] = (*(st.upper_bound({a[prv[i]], -1}))).S;
    st.insert({a[i], i});
    if (a[i] > mx) {
      mxi = i;
      mx = a[i];
    }
  }
  int idx = mxi, curr = 0, nxt;
  while (idx != 1) {
    int nidx = prv[idx];
    int cnt = n - pos[nidx];
    int suffsum = s[pos[nidx] + 1];
    nxt = suffsum - cnt * a[nidx];
    f[idx] = nxt - curr;
    curr = nxt;
    idx = nidx;
  }
  f[1] = tot - curr;
  for (int i = 1; i <= n; i++) {
    cout << f[i] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
const int N = 1e5 + 5, INF = 1e9;
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>;
int n, a[N], f[N], s[N], prv[N], pos[N], tot;
set<pii> st;
pii ss[N];
signed main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    tot += a[i];
    ss[i] = {a[i], i};
  }
  sort(ss + 1, ss + n + 1);
  s[n + 1] = 0;
  for (int i = n; i >= 1; i--) {
    s[i] = s[i + 1] + ss[i].F;
    pos[ss[i].S] = i;
  }
  st.insert({-INF, 0});
  st.insert({a[1], 1});
  int mx = a[1], mxi = 1;
  for (int i = 2; i <= n; i++) {
    prv[i] = (*(--st.upper_bound({a[i], 0}))).S;
    prv[i] = (*(st.upper_bound({a[prv[i]], -1}))).S;
    st.insert({a[i], i});
    if (a[i] > mx) {
      mxi = i;
      mx = a[i];
    }
  }
  int idx = mxi, curr = 0, nxt;
  while (idx != 1) {
    int nidx = prv[idx];
    int cnt = n - pos[nidx];
    int suffsum = s[pos[nidx] + 1];
    nxt = suffsum - cnt * a[nidx];
    f[idx] = nxt - curr;
    curr = nxt;
    idx = nidx;
  }
  f[1] = tot - curr;
  for (int i = 1; i <= n; i++) {
    cout << f[i] << endl;
  }
}
Problem p03801 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int n;
typedef long long ll;
struct pt {
  int idx;
  int val;
};

vector<pt> v;
vector<ll> ans;

bool cmp(pt a, pt b) {
  if (a.val != b.val) {
    return a.val > b.val;
  }
}

int main() {
  scanf("%d", &n);
  v.assign(n, pt());
  ans.assign(n, 0);
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i].val);
    v[i].idx = i;
  }
  sort(v.begin(), v.end(), cmp);
  int min_idx = 100020;
  v.push_back(pt());
  v[n].val = 0;
  for (int i = 0; i < n; i++) {
    min_idx = min(min_idx, v[i].idx);
    ans[min_idx] += (ll)(i + 1) * (v[i].val - v[i + 1].val);
  }

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

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int n;
typedef long long ll;
struct pt {
  int idx;
  int val;
};

vector<pt> v;
vector<ll> ans;

bool cmp(pt a, pt b) { return a.val > b.val; }

int main() {
  scanf("%d", &n);
  v.assign(n, pt());
  ans.assign(n, 0);
  for (int i = 0; i < n; i++) {
    scanf("%d", &v[i].val);
    v[i].idx = i;
  }
  sort(v.begin(), v.end(), cmp);
  int min_idx = 100020;
  v.push_back(pt());
  v[n].val = 0;
  for (int i = 0; i < n; i++) {
    min_idx = min(min_idx, v[i].idx);
    ans[min_idx] += (ll)(i + 1) * (v[i].val - v[i + 1].val);
  }

  for (int i = 0; i < n; i++) {
    printf("%lld\n", ans[i]);
  }
}
Problem p03801 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;

int main() {
  ll n;
  cin >> n;
  vector<pll> a(n);
  for (ll i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  ll cnt = 0;
  ll mn = inf;
  vec ans(n + 1);
  for (ll i = n; i; i--) {
    cnt++;
    mn = min(mn, a[i].second);
    ans[mn] += abs(a[i].first - a[i - 1].first) * cnt;
  }
  for (ll i = 1; i <= n; i++)
    cout << ans[i] << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll, ll> pll;
const ll mod = 1e9 + 7;
// const ll mod=998244353;
const ll inf = 1LL << 61;

int main() {
  ll n;
  cin >> n;
  vector<pll> a(n + 1);
  for (ll i = 1; i <= n; i++) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(a.begin(), a.end());
  ll cnt = 0;
  ll mn = inf;
  vec ans(n + 1);
  for (ll i = n; i; i--) {
    cnt++;
    mn = min(mn, a[i].second);
    ans[mn] += abs(a[i].first - a[i - 1].first) * cnt;
  }
  for (ll i = 1; i <= n; i++)
    cout << ans[i] << endl;
}
Problem p03801 (C++)

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)

int main() {
  int N;
  cin >> N;
  vector<long long> a(N);
  REP(i, N) cin >> a[i];

  vector<long long> ans(N);
  multiset<long long> set;
  REP(i, N) set.insert(a[i]);

  long long max_a = 0;
  REP(i, N) {
    if (a[i] > max_a) {
      auto itr = set.begin();
      while (*itr <= a[i]) {
        ans[i] += *itr - max_a;
        set.erase(itr++);
      }
      ans[i] += set.size() * (a[i] - max_a);
      max_a = a[i];
    }
  }

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

  return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)

int main() {
  int N;
  cin >> N;
  vector<long long> a(N);
  REP(i, N) cin >> a[i];

  vector<long long> ans(N);
  multiset<long long> set;
  REP(i, N) set.insert(a[i]);

  long long max_a = 0;
  REP(i, N) {
    if (a[i] > max_a) {
      auto itr = set.begin();
      while (itr != set.end() and *itr <= a[i]) {
        ans[i] += *itr - max_a;
        set.erase(itr++);
      }
      ans[i] += set.size() * (a[i] - max_a);
      max_a = a[i];
    }
  }

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

  return 0;
}
Problem p03801 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = [(a, i) for i, a in enumerate(map(int, input().split()))]
A.sort(reverse=True)
A.append((0, 0))

ans = [0] * N
now = float("inf")

for j, (a, i) in enumerate(A[:N], start=1):
    now = min(now, a)
    ans[now] += j * (now - A[j][0])

print(*ans, sep="\n")


Fixed submission:
N = int(input())
A = [(a, i) for i, a in enumerate(map(int, input().split()))]
A.sort(reverse=True)
A.append((0, 0))

ans = [0] * N
now = float("inf")

for j, (a, i) in enumerate(A[:N], start=1):
    now = min(now, i)
    ans[now] += j * (a - A[j][0])

print(*ans, sep="\n")
Problem p03801 (C++)

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

#define int long long
typedef pair<int, int> P;

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int a[110000];
int sa[110000];
int ans[110000];

signed main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sa[i] = a[i];
  }
  vector<int> active;
  int m = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] > m) {
      m = a[i];
      active.push_back(i);
    }
  }
  sort(sa, sa + N);
  int prev = 0;
  int idx = 0;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (sa[i] == a[active[idx]]) {
      ans[active[idx]] = sum + (sa[i] - prev) * (N - i);
      sum = 0;
      prev = sa[i];
      idx++;
    } else {
      sum += sa[i] - prev;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}

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

#define int long long
typedef pair<int, int> P;

int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int N;
int a[110000];
int sa[110000];
int ans[110000];

signed main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    sa[i] = a[i];
  }
  vector<int> active;
  int m = 0;
  for (int i = 0; i < N; i++) {
    if (a[i] > m) {
      m = a[i];
      active.push_back(i);
    }
  }
  sort(sa, sa + N);
  int prev = 0;
  int idx = 0;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (sa[i] == a[active[idx]]) {
      ans[active[idx]] = sum + (sa[i] - prev) * (N - i);
      sum = 0;
      prev = sa[i];
      idx++;
      if (idx == active.size())
        break;
    } else {
      sum += sa[i] - prev;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i] << endl;
  }

  return 0;
}
Problem p03803 (C++)

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> s = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1};
  if (s.at(a) >= s.at(b)) {
    cout << "Alice";
  } else if (s.at(a) == s.at(b)) {
    cout << "Draw";
  } else {
    cout << "Bob";
  }
}

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

int main() {
  int a, b;
  cin >> a >> b;
  vector<int> s = {0, 14, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
  if (s.at(a) > s.at(b)) {
    cout << "Alice";
  } else if (s.at(a) == s.at(b)) {
    cout << "Draw";
  } else {
    cout << "Bob";
  }
}
Problem p03803 (Python)

Buggy submission (status: Runtime Error):
def main():
    a, b = map(int, input().split())
    if a == b:
        ans = "Draw"
    elif a == 1:
        ans = "Alice"
    elif b == 1:
        ans = "Bob"
    elif a > b:
        ans = "Alice"
    elif b < a:
        ans = "Bob"
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    a, b = map(int, input().split())
    if a == b:
        ans = "Draw"
    elif a == 1:
        ans = "Alice"
    elif b == 1:
        ans = "Bob"
    elif a > b:
        ans = "Alice"
    elif a < b:
        ans = "Bob"
    print(ans)


if __name__ == "__main__":
    main()
Problem p03803 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <vector>

using namespace std;
typedef long long ll;
#define pl pair<ll, ll>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define foreach(itr, c)                                                        \
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); itr++)
#define dbg(x) cout << #x "=" << (x) << endl
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

int main() {
  ll a, b;
  cin >> a >> b;
  vector<ll> v(13);
  FOR(i, 1, 14) { v[i] = i + 1; }
  v[13] = 1;
  if (v[a] > v[b]) {
    cout << "Alice" << endl;
  } else if (a == b) {
    cout << "Draw" << endl;
  } else {
    cout << "Bob" << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <vector>

using namespace std;
typedef long long ll;
#define pl pair<ll, ll>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define foreach(itr, c)                                                        \
  for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); itr++)
#define dbg(x) cout << #x "=" << (x) << endl
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back(a)
#define in(x) cin >> x;
#define all(x) (x).begin(), (x).end()
#define INF 2147483600
#define fi first
#define se second

int main() {
  ll a, b;
  cin >> a >> b;
  vector<ll> v(14);
  FOR(i, 2, 14) { v[i] = i - 1; }
  v[1] = 13;
  if (v[a] > v[b]) {
    cout << "Alice" << endl;
  } else if (a == b) {
    cout << "Draw" << endl;
  } else {
    cout << "Bob" << endl;
  }
  return 0;
}
Problem p03803 (C++)

Buggy submission (status: Runtime Error):
/******* all required header files *******/
#include <algorithm>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;

/*****All definitions*******/
#define w(t)                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define vi vector<int>
#define vs vector<string>
#define mp make_pair
#define ll long long int
/***************************/

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

  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  cin >> a >> b;
  if (a == 1)
    a = a + 13;
  if (b == 1)
    b = b + 13;
  if (a > b)
    cout << "Alice";
  if (b > a)
    cout << "Bob";
  if (b == a)
    cout << "Draw";
  return 0;
}


Fixed submission:
/******* all required header files *******/
#include <algorithm>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;

/*****All definitions*******/
#define w(t)                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define vi vector<int>
#define vs vector<string>
#define mp make_pair
#define ll long long int
/***************************/

int main() {
  /*#ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
  #endif*/

  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  cin >> a >> b;
  if (a == 1)
    a = a + 13;
  if (b == 1)
    b = b + 13;
  if (a > b)
    cout << "Alice";
  if (b > a)
    cout << "Bob";
  if (b == a)
    cout << "Draw";
  return 0;
}
Problem p03803 (C++)

Buggy submission (status: Runtime Error):
/******* all required header files *******/
#include <algorithm>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;

/*****All definitions*******/
#define w(t)                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define vi vector<int>
#define vs vector<string>
#define mp make_pair
#define ll long long int
/***************************/

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

  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  cin >> a >> b;
  if (a == 1)
    a += 13;
  if (b == 1)
    b += 13;
  if (a > b)
    cout << "Alice" << endl;
  else if (a < b)
    cout << "Bob" << endl;
  else
    cout << "Draw" << endl;
  return 0;
}


Fixed submission:
/******* all required header files *******/
#include <algorithm>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>
using namespace std;

/*****All definitions*******/
#define w(t)                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define vi vector<int>
#define vs vector<string>
#define mp make_pair
#define ll long long int
/***************************/

int main() {
  /*#ifndef ONLINE_JUDGE
          freopen("input.txt", "r", stdin);
          freopen("output.txt", "w", stdout);
  #endif*/

  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b;
  cin >> a >> b;
  if (a == 1)
    a += 13;
  if (b == 1)
    b += 13;
  if (a > b)
    cout << "Alice" << endl;
  else if (a < b)
    cout << "Bob" << endl;
  else
    cout << "Draw" << endl;
  return 0;
}
Problem p03803 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;
  while (1) {
    if (A > B) {
      cout << "Alice" << endl;
      cin >> B >> A;
    } else if (A < B) {
      cout << "Bob" << endl;
      cin >> A >> B;
    } else {
      cout << "Draw" << endl;
      cin >> B >> A;
    }
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main() {

  int a, b;
  cin >> a >> b;
  if (a > b && b != 1)
    cout << "Alice" << endl;
  else if (b > a && a != 1)
    cout << "Bob" << endl;
  else if (a == 1 && b != 1)
    cout << "Alice" << endl;
  else if (b == 1 && a != 1)
    cout << "Bob" << endl;
  else if (a == b)
    cout << "Draw" << endl;

  return 0;
}
Problem p03803 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A, B;
  scanf("%d%d", A, B);
  if (13 >= A >= 1 && 13 >= B >= 1) {
    if (A > B)
      puts("Alice");
    else if (B > A)
      puts("Bob");
    else if (A == B)
      puts("Draw ");
  } else
    puts("error");
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  if (a == 1 || b == 1) {
    if (a == 1 && b == 1)
      cout << "Draw" << endl;
    else if (a == 1)
      cout << "Alice" << endl;
    else
      cout << "Bob" << endl;
  } else {
    if (a > b)
      cout << "Alice" << endl;
    else if (a == b)
      cout << "Draw" << endl;
    else
      cout << "Bob" << endl;
  }
  //    main();
}
Problem p03803 (C++)

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

using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;

  if (a == 1) {
    a += 13;
  }
  if (b == 1) {
    b += 13;
  }

  if (a == b) {
    cout << "Draw" << endl;
    return 1;
  } else if (a < b) {
    cout << "Bob" << endl;
  } else {
    cout << "Alice" << endl;
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <complex>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(void) {
  int a, b;
  cin >> a >> b;

  if (a == 1) {
    a += 13;
  }
  if (b == 1) {
    b += 13;
  }

  if (a == b) {
    cout << "Draw" << endl;
  } else if (a < b) {
    cout << "Bob" << endl;
  } else {
    cout << "Alice" << endl;
  }

  return 0;
}
Problem p03803 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  vector<int> vec = {0, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
  if (vec.at(a) < vec.at(b)) {
    cout << "Bob" << endl;
  } else if (vec.at(a) > vec.at(b)) {
    cout << "Alice" << endl;
  } else {
    cout << "Draw" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  vector<int> vec = {0, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
  if (vec.at(a) < vec.at(b)) {
    cout << "Bob" << endl;
  } else if (vec.at(a) > vec.at(b)) {
    cout << "Alice" << endl;
  } else {
    cout << "Draw" << endl;
  }
}
Problem p03803 (C++)

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

int main(int argc, char const *argv[]) {

#if !ONLINE_JUDGE

  freopen("in1.txt", "r", stdin);
  freopen("out1.txt", "w", stdout);

#endif

  int a, b;
  cin >> a >> b;

  if (a == b) {
    cout << "Draw" << endl;
    return 1;
  }
  if (a == 1) {
    cout << "Alice" << endl;
  } else if (b == 1) {
    cout << "Bob" << endl;
  } else {
    if (a > b) {
      cout << "Alice" << endl;

    } else {
      cout << "Bob" << endl;
    }
  }

  return 0;
}

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

int main(int argc, char const *argv[]) {

#if !ONLINE_JUDGE

  freopen("in1.txt", "r", stdin);
  freopen("out1.txt", "w", stdout);

#endif

  int a, b;
  cin >> a >> b;

  if (a == b) {
    cout << "Draw" << endl;

  } else if (a == 1) {
    cout << "Alice" << endl;
  } else if (b == 1) {
    cout << "Bob" << endl;
  } else {
    if (a > b) {
      cout << "Alice" << endl;

    } else {
      cout << "Bob" << endl;
    }
  }

  return 0;
}
Problem p03804 (C++)

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

bool match(vector<string> nv, vector<string> mv, int x, int y) {
  for (int i = x; i < x + (mv.size() - 1); i++) {
    for (int j = y; j < y + (mv.size() - 1); j++) {
      if (mv[i][j] != nv[i][j])
        return false;
    }
  }
  return true;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> nv(n);
  vector<string> mv(m);
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    nv[i] = s;
  }
  for (int i = 0; i < m; i++) {
    cin >> s;
    mv[i] = s;
  }
  for (int i = 0; i < n - (m - 1); i++) {
    for (int j = 0; j < n - (m - 1); j++) {
      if (match(nv, mv, i, j)) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}


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

bool match(vector<string> nv, vector<string> mv, int x, int y) {
  for (int i = 0; i < mv.size(); i++) {
    for (int j = 0; j < mv.size(); j++) {
      if (mv[i][j] != nv[x + i][y + j])
        return false;
    }
  }
  return true;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> nv(n);
  vector<string> mv(m);
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    nv[i] = s;
  }
  for (int i = 0; i < m; i++) {
    cin >> s;
    mv[i] = s;
  }
  for (int i = 0; i < n - (m - 1); i++) {
    for (int j = 0; j < n - (m - 1); j++) {
      if (match(nv, mv, i, j)) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
  return 0;
}
Problem p03804 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  string A[N], B[M];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      bool valid = true;
      for (int k = 0; k < M; k++) {
        for (int l = 0; l < M; l++) {
          if (A[i + k][j + l] != B[k][l]) {
            valid = false;
          }
        }
      }
      if (valid) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  string A[N], B[M];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  for (int i = 0; i <= N - M; i++) {
    for (int j = 0; j <= N - M; j++) {
      bool valid = true;
      for (int k = 0; k < M; k++) {
        for (int l = 0; l < M; l++) {
          if (A[i + k][j + l] != B[k][l]) {
            valid = false;
          }
        }
      }
      if (valid) {
        cout << "Yes";
        return 0;
      }
    }
  }
  cout << "No";
}
Problem p03804 (C++)

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

#define for_(i, a, b) for (int i = (a); i < (b); ++i)

int main() {
  int n, m;
  cin >> n >> m;

  vector<string> A(n), B(m);
  for_(i, 0, n) cin >> A[i];
  for_(i, 0, m) cin >> B[i];

  for_(sy, 0, n) for_(sx, 0, n) {
    bool match = true;
    for_(dy, 0, m) for_(dx, 0, m) match &= (A[sy + dy][sx + dx] == B[dy][dx]);
    if (match) {
      puts("Yes");
      return 0;
    }
  }

  puts("No");
}

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

#define for_(i, a, b) for (int i = (a); i < (b); ++i)

int main() {
  int n, m;
  cin >> n >> m;

  vector<string> A(n), B(m);
  for_(i, 0, n) cin >> A[i];
  for_(i, 0, m) cin >> B[i];

  for_(sy, 0, n - m + 1) for_(sx, 0, n - m + 1) {
    bool match = true;
    for_(dy, 0, m) for_(dx, 0, m) match &= (A[sy + dy][sx + dx] == B[dy][dx]);
    if (match) {
      puts("Yes");
      return 0;
    }
  }

  puts("No");
}
Problem p03804 (C++)

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)
#define FOR(i, start, end) for (int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

int N, M;
vs A, B;

bool isMatch(int x, int y) {
  REP(i, M) {
    REP(j, M) {
      if (B[i][j] != A[y + i][x + j])
        return false;
    }
  }
  return true;
}

void solve() {
  cin >> N >> M;
  A = vs(N);
  B = vs(M);
  REP(i, N) cin >> A[i];
  REP(i, M) cin >> B[i];

  REP(i, N) {
    REP(j, N) {
      if (isMatch(j, i)) {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  cout << "No" << endl;
}

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

  return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)
#define FOR(i, start, end) for (int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;

int N, M;
vs A, B;

bool isMatch(int x, int y) {
  REP(i, M) {
    REP(j, M) {
      if (B[i][j] != A[y + i][x + j])
        return false;
    }
  }
  return true;
}

void solve() {
  cin >> N >> M;
  A = vs(N);
  B = vs(M);
  REP(i, N) cin >> A[i];
  REP(i, M) cin >> B[i];

  REP(i, N) {
    REP(j, N) {
      if (i + M > N || j + M > N)
        continue;
      if (isMatch(j, i)) {
        cout << "Yes" << endl;
        return;
      }
    }
  }
  cout << "No" << endl;
}

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

  return 0;
}
Problem p03804 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// const ll mod = 1000000007;
string A[55], B[55];

int main() {
  // cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);
  int M, N;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < M; i++)
    cin >> B[i];
  for (int h = 0; h < N; h++) {
    if (h + M - 1 >= N)
      continue;
    for (int w = 0; w < N; w++) {
      if (w + M - 1 >= N)
        continue;
      bool ok = true;
      for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
          if (B[i][j] != A[i + h][j + w])
            ok = false;
        }
      }
      if (ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// const ll mod = 1000000007;
string A[55], B[55];

int main() {
  // cout.precision(10);
  cin.tie(0);
  ios::sync_with_stdio(false);
  int M, N;
  cin >> N >> M;
  for (int i = 0; i < N; i++)
    cin >> A[i];
  for (int i = 0; i < M; i++)
    cin >> B[i];
  for (int h = 0; h < N; h++) {
    if (h + M - 1 >= N)
      continue;
    for (int w = 0; w < N; w++) {
      if (w + M - 1 >= N)
        continue;
      bool ok = true;
      for (int i = 0; i < M; i++) {
        for (int j = 0; j < M; j++) {
          if (B[i][j] != A[i + h][j + w])
            ok = false;
        }
      }
      if (ok) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}