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

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

char f(int x) {
  char S;
  S = 'a' + x - 1;
  return S;
}

int main(void) {
  char s[11][2268000][11];
  int a[11][2268000];
  int c[11];
  int n, i, j, k, l, p;

  s[1][1][1] = 'a';
  a[1][1] = 1;
  c[1] = 1;

  for (i = 2; i <= 10; i++) {
    p = 0;
    for (j = 1; j <= c[i - 1]; j++) {
      for (k = 1; k <= a[i - 1][j] + 1; k++) {
        for (l = 1; l <= i - 1; l++) {
          s[i][p + k][l] = s[i - 1][j][l];
        }
        s[i][p + k][i] = f(k);
        if (k == a[i - 1][j] + 1) {
          a[i][p + k] = a[i - 1][j] + 1;
        } else {
          a[i][p + k] = a[i - 1][j];
        }
      }
      p = p + a[i - 1][j] + 1;
    }
    c[i] = p;
  }

  scanf("%d", &n);
  for (j = 1; j <= c[n]; j++) {
    for (l = 1; l <= n; l++) {
      printf("%c", s[n][j][l]);
    }
    printf("\n");
  }

  return 0;
}

Fixed submission:
#include <stdio.h>

char f(int x) {
  char S;
  S = 'a' + x - 1;
  return S;
}

int main(void) {
  char s[11][115976][11];
  int a[11][115976];
  int c[11];
  int n, i, j, k, l, p;

  s[1][1][1] = 'a';
  a[1][1] = 1;
  c[1] = 1;

  for (i = 2; i <= 10; i++) {
    p = 0;
    for (j = 1; j <= c[i - 1]; j++) {
      for (k = 1; k <= a[i - 1][j] + 1; k++) {
        for (l = 1; l <= i - 1; l++) {
          s[i][p + k][l] = s[i - 1][j][l];
        }
        s[i][p + k][i] = f(k);
        if (k == a[i - 1][j] + 1) {
          a[i][p + k] = a[i - 1][j] + 1;
        } else {
          a[i][p + k] = a[i - 1][j];
        }
      }
      p = p + a[i - 1][j] + 1;
    }
    c[i] = p;
  }

  scanf("%d", &n);
  for (j = 1; j <= c[n]; j++) {
    for (l = 1; l <= n; l++) {
      printf("%c", s[n][j][l]);
    }
    printf("\n");
  }

  return 0;
}
Problem p02744 (C++)

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

using namespace std;
typedef long long ll;

int gCount = 0;
string list[100000];

void addChar(string str, int level, int n) {
  if (str.length() == n) {
    list[gCount] = str;
    gCount++;
  } else {
    for (int i = 0; i < level + 2; i++) {
      addChar(str + (char)(97 + i), i > level ? i : level, n);
    }
  }
}

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

  string s = "a";

  addChar(s, 0, N);

  sort(list, list + gCount);

  for (int i = 0; i < gCount; i++) {
    printf("%s\n", list[i].c_str());
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>

using namespace std;
typedef long long ll;

int gCount = 0;
string list[120000];

void addChar(string str, int level, int n) {
  if (str.length() == n) {
    list[gCount] = str;
    gCount++;
  } else {
    for (int i = 0; i < level + 2; i++) {
      addChar(str + (char)(97 + i), i > level ? i : level, n);
    }
  }
}

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

  string s = "a";

  addChar(s, 0, N);

  sort(list, list + gCount);

  for (int i = 0; i < gCount; i++) {
    printf("%s\n", list[i].c_str());
  }
  return 0;
}
Problem p02744 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = {
    1: ["a"],
    2: ["aa", "ab"],
    3: ["aaa", "aab", "aba", "abb", "abc"],
    4: [
        "aaaa",
        "aaab",
        "aabb",
        "aabc",
        "abaa",
        "abab",
        "abac",
        "abba",
        "abbb",
        "abbc",
        "abca",
        "abcb",
        "abcc",
        "abcd",
    ],
    5: [
        "aaaaa",
        "aaaab",
        "aaaba",
        "aaabb",
        "aaabc",
        "aabba",
        "aabbb",
        "aabbc",
        "aabca",
        "aabcb",
        "aabcc",
        "aabcd",
        "abaaa",
        "abaab",
        "abaac",
        "ababa",
        "ababb",
        "ababc",
        "abaca",
        "abacb",
        "abacc",
        "abacd",
        "abbaa",
        "abbab",
        "abbac",
        "abbba",
        "abbbb",
        "abbbc",
        "abbca",
        "abbcb",
        "abbcc",
        "abbcd",
        "abcaa",
        "abcab",
        "abcac",
        "abcad",
        "abcba",
        "abcbb",
        "abcbc",
        "abcbd",
        "abcca",
        "abccb",
        "abccc",
        "abccd",
        "abcda",
        "abcdb",
        "abcdc",
        "abcdd",
        "abcde",
    ],
}
Ans = A[N]
for i in range(len(Ans)):
    print(Ans[i])


Fixed submission:
N = int(input())
D = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Ans = [["a"]]
for i in range(1, 10):
    before = Ans[i - 1]
    # print(before)
    next = []
    for j in before:
        L = set(list(j))
        # print(L)
        for k in range(len(L) + 1):
            # print(j)
            next.append(j + D[k])
    Ans.append(next)
# print(Ans)
print(*Ans[N - 1], sep="\n")
Problem p02745 (C++)

Buggy submission (status: Runtime Error):
//
// Created by Hideaki Imamura on 2020-03-14.
//
#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, b, c;

bool match(char c1, char c2) { return c1 == '?' || c2 == '?' || c1 == c2; }

int main() {
  cin >> a >> b >> c;
  int n_a = a.length(), n_b = b.length(), n_c = c.length();
  const int X = 4000;
  const int Y = 2000;
  bool ab[2 * X], ac[2 * X], bc[2 * X];

  for (int i = 0; i < n_a; ++i)
    for (int j = 0; j < n_b; ++j)
      if (!match(a[i], b[j]))
        ab[i - j + X] = true;
  for (int i = 0; i < n_a; ++i)
    for (int j = 0; j < n_c; ++j)
      if (!match(a[i], c[j]))
        ac[i - j + X] = true;
  for (int i = 0; i < n_b; ++i)
    for (int j = 0; j < n_c; ++j)
      if (!match(b[i], c[j]))
        bc[i - j + X] = true;

  int ans = 1e9;
  for (int i = -2 * Y; i <= 2 * Y; ++i) {
    for (int j = -2 * Y; j <= 2 * Y; ++j) {
      if (!ab[i + X] && !ac[j + X] && !bc[j - i + X]) {
        int L = min(0, min(i, j));
        int R = max(n_a, max(n_b + i, n_c + j));
        chmin(ans, R - L);
      }
    }
  }

  cout << ans << endl;
  return 0;
}

Fixed submission:
//
// Created by Hideaki Imamura on 2020-03-14.
//
#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, b, c;

bool match(char c1, char c2) { return c1 == '?' || c2 == '?' || c1 == c2; }

int main() {
  cin >> a >> b >> c;
  int n_a = a.length(), n_b = b.length(), n_c = c.length();
  const int X = 40000;
  const int Y = 2000;
  bool ab[2 * X], ac[2 * X], bc[2 * X];

  for (int i = 0; i < n_a; ++i)
    for (int j = 0; j < n_b; ++j)
      if (!match(a[i], b[j]))
        ab[i - j + X] = true;
  for (int i = 0; i < n_a; ++i)
    for (int j = 0; j < n_c; ++j)
      if (!match(a[i], c[j]))
        ac[i - j + X] = true;
  for (int i = 0; i < n_b; ++i)
    for (int j = 0; j < n_c; ++j)
      if (!match(b[i], c[j]))
        bc[i - j + X] = true;

  int ans = 1e9;
  for (int i = -2 * Y; i <= 2 * Y; ++i) {
    for (int j = -2 * Y; j <= 2 * Y; ++j) {
      if (!ab[i + X] && !ac[j + X] && !bc[j - i + X]) {
        int L = min(0, min(i, j));
        int R = max(n_a, max(n_b + i, n_c + j));
        chmin(ans, R - L);
      }
    }
  }

  cout << ans << endl;
  return 0;
}
Problem p02745 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for (int i = j; i <= k; i++)
#define dep(i, j, k) for (int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
#define PI acos(-1)
using namespace std;

const int N = 2e4 + 5, up = 4000;

char a[N], b[N], c[N];
bool ab[N], ac[N], bc[N];

int main() {
  scanf("%s", a);
  scanf("%s", b);
  scanf("%s", c);
  int lena = strlen(a);
  int lenb = strlen(b);
  int lenc = strlen(c);

  rep(i, 0, lena - 1)
      rep(j, 0, lenb - 1) if (!(a[i] == b[j] || a[i] == '?' || b[j] == '?'))
          ab[i - j + up] = 1;
  rep(i, 0, lena - 1)
      rep(j, 0, lenc - 1) if (!(a[i] == c[j] || a[i] == '?' || c[j] == '?'))
          ac[i - j + up] = 1;
  rep(i, 0, lenb - 1)
      rep(j, 0, lenc - 1) if (!(b[i] == c[j] || b[i] == '?' || c[j] == '?'))
          bc[i - j + up] = 1;

  int ans = INF;

  rep(i, -4000, 40000)
      rep(j, -4000, 4000) if (!ab[i + up] && !ac[j + up] && !bc[j - i + up]) {
    int L = min({0, i, j});
    int R = max({lena, lenb + i, lenc + j});
    ans = min(ans, R - L);
  }

  printf("%d\n", ans);

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define LL long long
#define mem(i, j) memset(i, j, sizeof(i))
#define rep(i, j, k) for (int i = j; i <= k; i++)
#define dep(i, j, k) for (int i = k; i >= j; i--)
#define pb push_back
#define make make_pair
#define INF INT_MAX
#define inf LLONG_MAX
#define PI acos(-1)
using namespace std;

const int N = 2e4 + 5, up = 4000;

char a[N], b[N], c[N];
bool ab[N], ac[N], bc[N];

int main() {
  scanf("%s", a);
  scanf("%s", b);
  scanf("%s", c);
  int lena = strlen(a);
  int lenb = strlen(b);
  int lenc = strlen(c);

  rep(i, 0, lena - 1)
      rep(j, 0, lenb - 1) if (!(a[i] == b[j] || a[i] == '?' || b[j] == '?'))
          ab[i - j + up] = 1;
  rep(i, 0, lena - 1)
      rep(j, 0, lenc - 1) if (!(a[i] == c[j] || a[i] == '?' || c[j] == '?'))
          ac[i - j + up] = 1;
  rep(i, 0, lenb - 1)
      rep(j, 0, lenc - 1) if (!(b[i] == c[j] || b[i] == '?' || c[j] == '?'))
          bc[i - j + up] = 1;

  int ans = INF;

  rep(i, -4000, 4000)
      rep(j, -4000, 4000) if (!ab[i + up] && !ac[j + up] && !bc[j - i + up]) {
    int L = min({0, i, j});
    int R = max({lena, lenb + i, lenc + j});
    ans = min(ans, R - L);
  }

  printf("%d\n", ans);

  return 0;
}
Problem p02745 (C++)

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

const int maxN = 4005;

int ans, tot;
int len[3];
bool f[3][3][maxN + 1];
char s[3][maxN + 1];

int main() {
  for (int i = 0; i < 3; i++)
    scanf("%s", s[i] + 1), len[i] = strlen(s[i] + 1);

  tot = ans = len[0] + len[1] + len[2];
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (i == j)
        continue;
      for (int p = 1; p <= tot; p++) {
        f[i][j][p] = true;
        for (int l = 1, r = p; l <= len[i] && r <= len[j]; l++, r++)
          if (s[i][l] != s[j][r] && s[i][l] != '?' && s[j][r] != '?') {
            f[i][j][p] = false;
            break;
          }
      }
    }

  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (i == j)
        continue;
      int k = 3 - i - j;
      for (int l = 1; l <= tot; l++) {
        if (!f[j][i][l])
          continue;
        for (int r = 1; r <= tot; r++) {
          if (!f[k][j][r])
            continue;
          int t = l + r - 1;
          if (!f[k][i][t])
            continue;
          ans = min(ans,
                    t - 1 + max(len[k], max(len[j] - r + 1, len[i] - t + 1)));
        }
      }
    }

  printf("%d", ans);
  return 0;
}


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

const int maxN = 6005;

int ans, tot;
int len[3];
bool f[3][3][maxN + 1];
char s[3][maxN + 1];

int main() {
  for (int i = 0; i < 3; i++)
    scanf("%s", s[i] + 1), len[i] = strlen(s[i] + 1);

  tot = ans = len[0] + len[1] + len[2];
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (i == j)
        continue;
      for (int p = 1; p <= tot; p++) {
        f[i][j][p] = true;
        for (int l = 1, r = p; l <= len[i] && r <= len[j]; l++, r++)
          if (s[i][l] != s[j][r] && s[i][l] != '?' && s[j][r] != '?') {
            f[i][j][p] = false;
            break;
          }
      }
    }

  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++) {
      if (i == j)
        continue;
      int k = 3 - i - j;
      for (int l = 1; l <= tot; l++) {
        if (!f[j][i][l])
          continue;
        for (int r = 1; r <= tot; r++) {
          if (!f[k][j][r])
            continue;
          int t = l + r - 1;
          if (!f[k][i][t])
            continue;
          ans = min(ans,
                    t - 1 + max(len[k], max(len[j] - r + 1, len[i] - t + 1)));
        }
      }
    }

  printf("%d", ans);
  return 0;
}
Problem p02745 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int ab[10000], bc[10000], ac[10000], ans = 6000, na, nb, nc, L, R;
string a, b, c;
bool ch(char a, char b) { return (a == b || a == '?' || b == '?'); }
int main(void) {
  cin >> a >> b >> c;
  na = a.size();
  nb = b.size();
  nc = c.size();
  for (int i = 0; i < na; i++) {
    for (int j = 0; j < nb; j++) {
      if (!ch(a[i], b[j]))
        ab[i - j + 5000] = 1;
    }
  }
  for (int i = 0; i < na; i++) {
    for (int j = 0; j < nc; j++) {
      if (!ch(a[i], c[j]))
        ac[i - j + 5000] = 1;
    }
  }
  for (int i = 0; i < nb; i++) {
    for (int j = 0; j < nc; j++) {
      if (!ch(b[i], c[j]))
        bc[i - j + 5000] = 1;
    }
  }
  for (int i = -4000; i <= 4000; i++) {
    for (int j = -4000; j <= 4000; j++) {
      if (ab[i + 5000] == 0 && bc[i + 5000] == 0 && ac[j - i + 5000] == 0) {
        L = min(0, min(i, j));
        R = max(na, max(i + nb, j + nc));
        // cout<<ans<<" "<<R<<L<<endl;
        ans = min(ans, R - L);
      }
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
int ab[10000], bc[10000], ac[10000], ans = 6000, na, nb, nc, L, R;
string a, b, c;
bool ch(char a, char b) { return (a == b || a == '?' || b == '?'); }
int main(void) {
  cin >> a >> b >> c;
  na = a.size();
  nb = b.size();
  nc = c.size();
  for (int i = 0; i < na; i++) {
    for (int j = 0; j < nb; j++) {
      if (!ch(a[i], b[j]))
        ab[i - j + 5000] = 1;
    }
  }
  for (int i = 0; i < na; i++) {
    for (int j = 0; j < nc; j++) {
      if (!ch(a[i], c[j]))
        ac[i - j + 5000] = 1;
    }
  }
  for (int i = 0; i < nb; i++) {
    for (int j = 0; j < nc; j++) {
      if (!ch(b[i], c[j]))
        bc[i - j + 5000] = 1;
    }
  }
  for (int i = -4000; i <= 4000; i++) {
    for (int j = -4000; j <= 4000; j++) {
      if (ab[i + 5000] == 0 && ac[j + 5000] == 0 && bc[j - i + 5000] == 0) {
        L = min(0, min(i, j));
        R = max(na, max(i + nb, j + nc));
        // cout<<ans<<" "<<R<<L<<endl;
        ans = min(ans, R - L);
      }
    }
  }
  cout << ans << endl;
}
Problem p02745 (C++)

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

int main() {
  // your code goes here
  char a[5][2005];
  ll l[5], r[5] = {0}, ans = 100000000;
  bool z[5015][5][5] = {0};
  cin >> a[0] >> a[1] >> a[2];
  rep(i, 0, 2) l[i] = strlen(a[i]);
  rep(i, 0, 2) {
    rep(j, 0, 2) {
      if (i == j)
        continue;
      rep(k, 0, l[i] - 1) {
        bool memo = true;
        rep(s, 0, min(l[j] - 1ll, l[i] - k - 1)) {
          if (a[i][k + s] == '?')
            continue;
          if (a[j][s] == '?')
            continue;
          if (a[i][k + s] != a[j][s])
            memo = false;
        }
        if (memo)
          z[k][i][j] = true;
        // if(memo) cout << i << " " << j << " " << k << endl;
      }
      rep(k, l[i], 5000) z[k][i][j] = true;
    }
  }
  vector<ll> p;
  p.push_back(0);
  p.push_back(1);
  p.push_back(2);
  do {
    rep(i, 0, l[p[0]]) {
      rep(j, 0, 2 * l[p[1]]) {
        if (z[i][p[0]][p[1]] && z[j][p[1]][p[2]] && z[i + j][p[0]][p[2]]) {
          ll mm = max(l[p[0]], max(i + l[p[1]], i + j + l[p[2]]));
          ans = min(ans, mm);
        }
      }
    }
  } while (next_permutation(p.begin(), p.end()));
  cout << ans << endl;
  return 0;
}

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

int main() {
  // your code goes here
  char a[5][2005];
  ll l[5], r[5] = {0}, ans = 100000000;
  bool z[5015][5][5] = {0};
  cin >> a[0] >> a[1] >> a[2];
  rep(i, 0, 2) l[i] = strlen(a[i]);
  rep(i, 0, 2) {
    rep(j, 0, 2) {
      if (i == j)
        continue;
      rep(k, 0, l[i] - 1) {
        bool memo = true;
        rep(s, 0, min(l[j] - 1ll, l[i] - k - 1)) {
          if (a[i][k + s] == '?')
            continue;
          if (a[j][s] == '?')
            continue;
          if (a[i][k + s] != a[j][s])
            memo = false;
        }
        if (memo)
          z[k][i][j] = true;
        // if(memo) cout << i << " " << j << " " << k << endl;
      }
      rep(k, l[i], 5000) z[k][i][j] = true;
    }
  }
  vector<ll> p;
  p.push_back(0);
  p.push_back(1);
  p.push_back(2);
  do {
    rep(i, 0, 3 * l[p[0]]) {
      rep(j, 0, min(3ll * l[p[1]], 4500ll - i)) {
        if (z[i][p[0]][p[1]] && z[j][p[1]][p[2]] && z[i + j][p[0]][p[2]]) {
          ll mm = max(l[p[0]], max(i + l[p[1]], i + j + l[p[2]]));
          ans = min(ans, mm);
        }
      }
    }
  } while (next_permutation(p.begin(), p.end()));
  cout << ans << endl;
  return 0;
}
Problem p02745 (C++)

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

using namespace std;

vector<string> x;

void gen(string a, string b) {
  int n = a.size();
  int m = b.size();
  for (int i = 0; i <= n; i++) {
    bool ok = 1;
    for (int j = 0; j < m; j++) {
      if (i + j >= n || a[i + j] == '?' || b[j] == '?')
        continue;
      if (a[i + j] != b[j]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      string t = a;
      for (int j = 0; j < m; j++) {
        if (i + j >= (int)t.size())
          t += '?';
        if (t[i + j] == '?')
          t[i + j] = b[j];
      }
      x.push_back(t);
    }
  }
}

string match(string a, string b) {
  int n = a.size();
  int m = b.size();
  for (int i = 0; i <= n; i++) {
    bool ok = 1;
    for (int j = 0; j < m; j++) {
      if (i + j >= n || a[i + j] == '?' || b[j] == '?')
        continue;
      if (a[i + j] != b[j]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      for (int j = 0; j < m; j++) {
        if (i + j >= (int)a.size())
          a += '?';
        if (a[i + j] == '?')
          a[i + j] = b[j];
      }
      break;
    }
  }
  return a;
}

int main() {
  ios::sync_with_stdio(false);
  vector<string> v(3);
  for (int i = 0; i < 3; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  int res = v[0].size() + v[1].size() + v[2].size();
  do {
    vector<string> t = v;
    gen(t[0], t[1]);
    for (auto a : x)
      res = min(res, (int)match(a, t[2]).size());
    x.clear();
  } while (next_permutation(v.begin(), v.end()));
  cout << res << endl;
  return 0;
}


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

using namespace std;

vector<string> x;

void gen(string a, string b) {
  int n = a.size();
  int m = b.size();
  for (int i = 0; i <= n; i++) {
    bool ok = 1;
    for (int j = 0; j < m; j++) {
      if (i + j >= n || a[i + j] == '?' || b[j] == '?')
        continue;
      if (a[i + j] != b[j]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      string t = a;
      for (int j = 0; j < m; j++) {
        if (i + j >= (int)t.size())
          t += '?';
        if (t[i + j] == '?')
          t[i + j] = b[j];
      }
      x.push_back(t);
    }
  }
}

string match(string a, string b) {
  int n = a.size();
  int m = b.size();
  for (int i = 0; i <= n; i++) {
    bool ok = 1;
    for (int j = 0; j < m; j++) {
      if (i + j >= n || a[i + j] == '?' || b[j] == '?')
        continue;
      if (a[i + j] != b[j]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      for (int j = 0; j < m; j++) {
        if (i + j >= (int)a.size())
          a += '?';
        if (a[i + j] == '?')
          a[i + j] = b[j];
      }
      break;
    }
  }
  return a;
}

int main() {
  ios::sync_with_stdio(false);
  vector<string> v(3);
  for (int i = 0; i < 3; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  int res = v[0].size() + v[1].size() + v[2].size();
  do {
    vector<string> t = v;
    gen(t[0], t[1]);
    for (auto a : x)
      if ((int)a.size() < res)
        res = min(res, (int)match(a, t[2]).size());
    x.clear();
  } while (next_permutation(v.begin(), v.end()));
  cout << res << endl;
  return 0;
}
Problem p02745 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define maxn 2010
using namespace std;
char a[maxn], b[maxn], c[maxn];
bool ab[maxn + maxn + maxn + maxn + maxn], ac[5 * maxn], bc[5 * maxn];
int match(char a, char b) {
  if (a == b || a == '?' || b == '?')
    return 1;
  return 0;
}
int main() {
  int i, j, A, B, C, L, R, ans = 5 * maxn;
  scanf("%s%s%s", a, b, c);
  A = strlen(a), B = strlen(b), C = strlen(c);
  for (i = 0; i < A; i++)
    for (j = 0; j < B; j++)
      if (!match(a[i], b[j]))
        ab[i - j + 2 * maxn] = 1;
  for (i = 0; i < A; i++)
    for (j = 0; j < C; j++)
      if (!match(a[i], c[j]))
        ac[i - j + 2 * maxn] = 1;
  for (i = 0; i < B; i++)
    for (j = 0; j < C; j++)
      if (!match(b[i], c[j]))
        bc[i - j + 2 * maxn] = 1;
  for (i = -(B + C); i <= A + B + C; i++)
    for (j = -(B + C); j <= A + B + C; j++)
      if (!ab[i + 2 * maxn] && !ac[j + 2 * maxn] && !bc[j - i + 2 * maxn]) {
        L = min(0, min(i, j)),
        R = max(A, max(B + i, C + j)); // min(i,j)>0表示在内部匹配，故取0
        ans = min(ans, R - L);
      }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define maxn 2010
using namespace std;
char a[maxn], b[maxn], c[maxn];
bool ab[maxn + maxn + maxn + maxn + maxn], ac[5 * maxn], bc[5 * maxn];
int match(char a, char b) {
  if (a == b || a == '?' || b == '?')
    return 1;
  return 0;
}
int main() {
  int i, j, A, B, C, L, R, ans = 5 * maxn;
  scanf("%s%s%s", a, b, c);
  A = strlen(a), B = strlen(b), C = strlen(c);
  for (i = 0; i < A; i++)
    for (j = 0; j < B; j++)
      if (!match(a[i], b[j]))
        ab[i - j + 2 * maxn] = 1;
  for (i = 0; i < A; i++)
    for (j = 0; j < C; j++)
      if (!match(a[i], c[j]))
        ac[i - j + 2 * maxn] = 1;
  for (i = 0; i < B; i++)
    for (j = 0; j < C; j++)
      if (!match(b[i], c[j]))
        bc[i - j + 2 * maxn] = 1;
  for (i = -(B + C); i <= B + C; i++)
    for (j = -(B + C); j <= B + C; j++)
      if (!ab[i + 2 * maxn] && !ac[j + 2 * maxn] && !bc[j - i + 2 * maxn]) {
        L = min(0, min(i, j)),
        R = max(A, max(B + i, C + j)); // min(i,j)>0表示在内部匹配，故取0
        ans = min(ans, R - L);
      }
  printf("%d\n", ans);
  return 0;
}
Problem p02746 (C++)

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

const ll s = pow(3, 29);
ll solve(ll a1, ll a2, ll b1, ll b2) {
  if (a2 > b2) {
    swap(a1, b1);
    swap(a2, b2);
  }
  ll res = abs(a1 - b1) + abs(a2 - b2);
  for (ll ss = s; ss >= 0; ss /= 3) {
    ll na1 = a1 / ss, nb1 = b1 / ss;
    if (na1 != nb1)
      break;
    ll na2 = a2 / ss, nb2 = b2 / ss;
    if (na1 % 3 == 1 && abs(nb2 - na2) > 1) {
      ll up = ss * na1 - 1;
      ll down = ss * (na1 + 1);
      ll loss = min(min(a1, b1) - up, down - max(a1, b1));
      res += 2 * loss;
      break;
    }
  }
  return res;
}

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

  int q;
  cin >> q;
  rep(i, q) {
    ll ai, aj, bi, bj;
    cin >> ai >> aj >> bi >> bj;
    --ai, --aj, --bi, --bj;
    ll ans = 0;
    ans = max(ans, solve(ai, aj, bi, bj));
    ans = max(ans, solve(aj, ai, bj, bi));
    cout << ans << endl;
  }
}

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

const ll s = pow(3, 29);
ll solve(ll a1, ll a2, ll b1, ll b2) {
  if (a2 > b2) {
    swap(a1, b1);
    swap(a2, b2);
  }
  ll res = abs(a1 - b1) + abs(a2 - b2);
  for (ll ss = s; ss > 0; ss /= 3) {
    ll na1 = a1 / ss, nb1 = b1 / ss;
    if (na1 != nb1)
      break;
    ll na2 = a2 / ss, nb2 = b2 / ss;
    if (na1 % 3 == 1 && abs(nb2 - na2) > 1) {
      ll up = ss * na1 - 1;
      ll down = ss * (na1 + 1);
      ll loss = min(min(a1, b1) - up, down - max(a1, b1));
      res += 2 * loss;
      break;
    }
  }
  return res;
}

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

  int q;
  cin >> q;
  rep(i, q) {
    ll ai, aj, bi, bj;
    cin >> ai >> aj >> bi >> bj;
    --ai, --aj, --bi, --bj;
    ll ans = 0;
    ans = max(ans, solve(ai, aj, bi, bj));
    ans = max(ans, solve(aj, ai, bj, bi));
    cout << ans << endl;
  }
}
Problem p02746 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int64_t len(int64_t a, int64_t b, int64_t c, int64_t d, int64_t p) {
  if (a / p != c / p && b / p != d / p)
    return abs(c - a) + abs(d - b);
  if (a / p == c / p && b / p == d / p)
    return len(a % p, b % p, c % p, d % p, p / 3);
  if (a / p == c / p)
    return len(c, d, a, b, p);
  int64_t xa = a;
  int64_t xc = c;
  int k = 0;
  while (abs(xc - xa) > 1) {
    k++;
    xc /= 3;
    xa /= 3;
  }
  int64_t x = (b + d) / 2;
  vector<int> t;
  while (x > 0) {
    t.push_back(x % 3);
    x /= 3;
  }
  int64_t l = 0;
  int64_t g = 0;
  bool f = 0;
  for (int i = (int)t.size() - 1; i >= 0; i--) {
    l *= 3;
    g *= 3;
    if (f) {
      l += 2;
      continue;
    }
    if (i < k && t.at(i) == 1) {
      g += 2;
      f = 1;
      continue;
    }
    l += t.at(i);
    g += t.at(i);
  }
  return min(abs(c - a) + abs(l - b) + abs(l - d),
             abs(c - a) + abs(g - b) + abs(g - d));
}
int main() {
  int q;
  cin >> q;
  for (int _ = 0; _ < q; _++) {
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    int64_t p = 1;
    while (p <= max({a, b, c, d}))
      p *= 3;
    cout << len(a, b, c, d, p / 3) << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int64_t len(int64_t a, int64_t b, int64_t c, int64_t d, int64_t p) {
  if (a / p != c / p && b / p != d / p)
    return abs(c - a) + abs(d - b);
  if (a / p == c / p && b / p == d / p)
    return len(a % p, b % p, c % p, d % p, p / 3);
  if (a / p == c / p)
    return len(b, a, d, c, p);
  int64_t xa = a;
  int64_t xc = c;
  int k = 0;
  while (abs(xc - xa) > 1) {
    k++;
    xc /= 3;
    xa /= 3;
  }
  int64_t x = (b + d) / 2;
  vector<int> t;
  while (x > 0) {
    t.push_back(x % 3);
    x /= 3;
  }
  int64_t l = 0;
  int64_t g = 0;
  bool f = 0;
  for (int i = (int)t.size() - 1; i >= 0; i--) {
    l *= 3;
    g *= 3;
    if (f) {
      l += 2;
      continue;
    }
    if (i < k && t.at(i) == 1) {
      g += 2;
      f = 1;
      continue;
    }
    l += t.at(i);
    g += t.at(i);
  }
  return min(abs(c - a) + abs(l - b) + abs(l - d),
             abs(c - a) + abs(g - b) + abs(g - d));
}
int main() {
  int q;
  cin >> q;
  for (int _ = 0; _ < q; _++) {
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    b--;
    c--;
    d--;
    int64_t p = 1;
    while (p <= max({a, b, c, d}))
      p *= 3;
    cout << len(a, b, c, d, p / 3) << endl;
  }
}
Problem p02747 (C++)

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

int main() {
  string s;

  cin >> s;

  bool flag = true;
  for (int i = 0; i < s.length(); i = i + 2) {

    if (s.at(i) != 'h' || s.at(i + 1) != 'i') {
      flag = false;
    }
  }

  if (s.length() % 2 != 0)
    flag = false;

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

int main() {
  string s;

  cin >> s;

  bool flag = true;
  for (int i = 0; i < s.length() - 1; i = i + 2) {

    if (s.at(i) != 'h' || s.at(i + 1) != 'i') {
      flag = false;
    }
  }

  if (s.length() % 2 != 0)
    flag = false;

  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02747 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

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

  bool h = true;
  for (auto &it : s) {
    if (h && it == 'h') {
      h = false;
    } else if (!h && it == 'i') {
      h = true;
    } else {
      cout << "No";
      return 1;
    }
  }

  if (h)
    cout << "Yes";
  else
    cout << "No";
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

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

  bool h = true;
  for (auto &it : s) {
    if (h && it == 'h') {
      h = false;
    } else if (!h && it == 'i') {
      h = true;
    } else {
      cout << "No";
      return 0;
    }
  }

  if (h)
    cout << "Yes";
  else
    cout << "No";
}
Problem p02747 (C++)

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

int main() {

  string ans = "Yes";
  string s;
  cin >> s;

  for (int i = 0; i < s.size(); i = i + 2) {
    if (!(s.at(i) == 'h' && s.at(i + 1) == 'i'))
      ans = "No";
  }

  cout << ans << "\n";
  return 0;
}


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

int main() {

  string ans = "Yes";
  string s;
  cin >> s;

  if (s.size() % 2 == 1) {
    ans = "No";
    cout << ans << "\n";
    return 0;
  }

  for (int i = 0; i < s.size(); i = i + 2) {
    if (!(s.at(i) == 'h' && s.at(i + 1) == 'i'))
      ans = "No";
  }

  cout << ans << "\n";
  return 0;
}
Problem p02747 (C++)

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

int main() {
  string S;
  cin >> S;
  while (S.size() != 0) {
    if (S.at(0) == 'h' && S.at(1) == 'i') {
      S = S.substr(2);
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main() {
  string S;
  cin >> S;
  if (S.size() % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  while (S.size() != 0) {
    if (S.at(0) == 'h' && S.at(1) == 'i') {
      S = S.substr(2);
    } else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}
Problem p02747 (C++)

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

using namespace std;
typedef long long ll;

int main() {
  string S;

  cin >> S;

  string ans = "Yes", hi = "hi";

  while (S.length() > 0) {
    if (S.substr(S.length() - 2, 2) == hi) {
      S = S.substr(0, S.length() - 2);
    } else {
      ans = "No";
      break;
    }
  }

  cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

int main() {
  string S;

  cin >> S;

  string ans = "Yes", hi = "hi";

  while (S.length() > 0) {
    if (S.length() % 2 == 1) {
      ans = "No";
      break;
    }
    if (S.substr(S.length() - 2, 2) == hi) {
      S = S.substr(0, S.length() - 2);
    } else {
      ans = "No";
      break;
    }
  }

  cout << ans << endl;
}
Problem p02747 (C++)

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

int main() {
  string s;
  cin >> s;
  int c = 1;
  for (int i = 0; i <= (s.length() - 1) / 2; i++) {
    if ((s.at(i * 2) == 'h') && (s.at(i * 2 + 1) == 'i')) {
      c = c * 1;
    } else {
      c = 0;
    }
  }

  if (c > 0 && s.length() % 2 == 0) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

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

int main() {
  string s;
  cin >> s;
  if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" ||
      s == "hihihihihi") {
    cout << "Yes";
  } else {
    cout << "No";
  }
}
Problem p02747 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define inf 1e18 + 9
using namespace std;
int32_t main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0);
  string st;
  cin >> st;
  int n = st.size();
  if (n % 2) {
    cout << "No";
    return 0;
  }
  int f = 1;
  for (int i = 0; i < n; i++) {
    if (i % 2 and st[i] != 'i')
      f = 0;
    if (i % 2 == 0 and st[i] != 'h')
      f = 0;
  }
  if (f)
    cout << "Yes";
  else
    cout << "No";
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
#define inf 1e18 + 9
using namespace std;
int32_t main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0);
  string st;
  cin >> st;
  int n = st.size();
  if (n % 2) {
    cout << "No";
    return 0;
  }
  int f = 1;
  for (int i = 0; i < n; i++) {
    if (i % 2 and st[i] != 'i')
      f = 0;
    if (i % 2 == 0 and st[i] != 'h')
      f = 0;
  }
  if (f)
    cout << "Yes";
  else
    cout << "No";
}
Problem p02747 (C++)

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

int main(void) {
  char S[10];

  cin >> S;
  int flag = 0;
  int result = 1;
  int i = 0;
  while (S[i] != NULL) {
    if (i % 2 == 0) {
      if (S[i] != 'h') {
        result = 0;
        break;
      } else
        flag = 1;
    } else {
      if (S[i] != 'i') {
        result = 0;
        break;
      } else
        flag = 2;
    }

    i += 1;
  }
  if (flag != 2)
    result = 0;
  if (result == 1)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}


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

int main(void) {
  char S[11];

  cin >> S;
  int flag = 0;
  int result = 1;
  int i = 0;
  while (S[i] != NULL) {
    if (i % 2 == 0) {
      if (S[i] != 'h') {
        result = 0;
        break;
      } else
        flag = 1;
    } else {
      if (S[i] != 'i') {
        result = 0;
        break;
      } else
        flag = 2;
    }

    i += 1;
  }
  if (flag != 2)
    result = 0;
  if (result == 1)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}
Problem p02747 (C++)

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

int main() {
  string S;
  cin >> S;
  for (int i = 0; i < 4; i++) {
    if (S.at(2 * i) != 'h' || S.at(2 * i + 1) != 'i') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

int main() {
  string S;
  cin >> S;
  int n = 0;
  n = (S.size()) / 2;
  if (S.size() % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  if (S.size() == 0) {
    cout << "No" << endl;
    return 0;
  }
  if (S.size() == 1) {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (S.at(2 * i) != 'h' || S.at((2 * i) + 1) != 'i') {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p02747 (C++)

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

int main() {
  string S;
  cin >> S;
  bool flag = true;

  if (S.size() > 10) {
    cout << "No";
    return 0;
  }

  for (int i = 0; i < S.size(); i += 2) {
    if (S.at(i) != 'h' || S.at(i + 1) != 'i')
      flag = false;
  }
  if (flag)
    cout << "Yes";
  else
    cout << "No";
}

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

int main() {
  string S;
  cin >> S;
  bool flag = true;

  if (S.size() % 2 != 0) {
    cout << "No";
    return 0;
  }

  for (int i = 0; i < S.size(); i += 2) {
    if (S.at(i) != 'h' || S.at(i + 1) != 'i')
      flag = false;
  }
  if (flag)
    cout << "Yes";
  else
    cout << "No";
}
Problem p02747 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
// #include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
signed main() {
  string s;
  cin >> s;
  int t = 0;
  while (t + 1 < s.size()) {
    if (s[t] == 'h' && s[t + 1] == 'i')
      t += 2;
  }
  cout << (t == s.size() ? "Yes" : "No") << endl;
  ;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
// #include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
signed main() {
  string s;
  cin >> s;
  int t = 0;
  while (t + 1 < s.size()) {
    if (s[t] == 'h' && s[t + 1] == 'i')
      t += 2;
    else
      break;
  }
  cout << (t == s.size() ? "Yes" : "No") << endl;
  ;
}
Problem p02747 (C++)

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  freopen("Input.txt", "r", stdin);
  freopen("Output.txt", "w", stdout);

  string S;
  cin >> S;

  // cout<<S.length()<<endl;

  if (S.length() % 2 == 0) {
    int flag = 1;

    for (int i = 0; i < S.length(); i++) {
      if (i % 2 == 0) {
        if (S[i] != 'h') {
          flag = 0;
          break;
        }
      }

      else {
        if (S[i] != 'i') {
          flag = 0;
          break;
        }
      }
    }

    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  else
    cout << "No" << endl;
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;

  // cout<<S.length()<<endl;

  if (S.length() % 2 == 0) {
    int flag = 1;

    for (int i = 0; i < S.length(); i++) {
      if (i % 2 == 0) {
        if (S[i] != 'h') {
          flag = 0;
          break;
        }
      }

      else {
        if (S[i] != 'i') {
          flag = 0;
          break;
        }
      }
    }

    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }

  else
    cout << "No" << endl;
}
Problem p02747 (C++)

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

int main() {
  string s;
  cin >> s;
  bool at = false;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s[i] == 'h' && s[i + 1] == 'i') {
      at = true;
      break;
    }
  }
  if (at == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main() {
  string s;
  cin >> s;
  bool at = true;
  if (s.size() % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  for (int i = 0; i < s.size() - 1; i += 2) {
    if (s[i] != 'h' || s[i + 1] != 'i') {
      at = false;
      break;
    }
  }
  if (at == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02747 (C++)

Buggy submission (status: Time Limit Exceeded):
// A.cpp

#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  bool flag;
  cin >> s;
  if (s.size() % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  string st;
  for (int i = 0; i != s.size(); i = +2) {
    st += "hi";
  }
  if (s == st) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
// A.cpp

#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  bool flag;
  cin >> s;
  if (s.size() % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }
  string st;
  for (int i = 0; i != s.size(); i += 2) {
    st += "hi";
  }
  if (s == st) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02747 (C++)

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

int main() {
  string W, H;
  cin >> W;
  H = "Yes";
  if ((W.size() - 1) % 2 == 0) {
    rep(i, (W.size() - 1) / 2) {
      if (W.at(i * 2 - 1) != 'h' || W.at(i * 2) != 'i') {
        H = "No";
      }
    }
  } else {
    H = "No";
  }
  cout << H << endl;
}


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

int main() {
  string W, H;
  cin >> W;
  H = "Yes";
  if ((W.size()) % 2 == 0) {
    rep(i, (W.size()) / 2) {
      if (W.at(i * 2) != 'h' || W.at(i * 2 + 1) != 'i') {
        H = "No";
      }
    }
  } else {
    H = "No";
  }
  cout << H << endl;
}
Problem p02747 (Python)

Buggy submission (status: Runtime Error):
S = input()
ok = True
for i in range(0, len(S), 2):
    if not (S[i] == "h" and S[i + 1] == "i"):
        ok = False
        break
print("Yes" if ok else "No")


Fixed submission:
S = input()
ok = True
for i in range(0, len(S), 2):
    try:
        if not (S[i] == "h" and S[i + 1] == "i"):
            ok = False
            break
    except IndexError:
        ok = False
        break
print("Yes" if ok else "No")
Problem p02748 (C++)

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> va(a);
  vector<int> vb(b);
  for (int i = 0; i < a; i++)
    cin >> va.at(i);
  for (int i = 0; i < b; i++)
    cin >> vb.at(i);
  int ans = 2000001;
  for (int i = 0; i < m; i++) {
    int m1, m2, m3;
    cin >> m1 >> m2 >> m3;
    ans = min(ans, va.at(m1 - 1) + vb.at(m2 - 1) - m3);
  }
  for (int i = 0; i < a; i++)
    for (int j = 0; j < b; j++)
      ans = min(ans, va.at(i) + vb.at(j));
  cout << ans << endl;
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> va(a);
  vector<int> vb(b);
  for (int i = 0; i < a; i++)
    cin >> va.at(i);
  for (int i = 0; i < b; i++)
    cin >> vb.at(i);
  int ans = 2000001;
  for (int i = 0; i < m; i++) {
    int m1, m2, m3;
    cin >> m1 >> m2 >> m3;
    ans = min(ans, va.at(m1 - 1) + vb.at(m2 - 1) - m3);
  }
  sort(va.begin(), va.end());
  sort(vb.begin(), vb.end());
  ans = min(ans, va.at(0) + vb.at(0));
  cout << ans << endl;
  return 0;
}
Problem p02748 (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;

signed main(void) {
  int A, B, m;
  cin >> A >> B >> m;
  int a[A], b[B];
  int x[m], y[m], c[m];
  int ans = 1e9;
  rep(i, A) cin >> a[i];
  rep(i, B) cin >> b[i];
  rep(i, A) rep(j, B) ans = min(ans, a[i] + b[j]);
  rep(i, m) {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--;
    y[i]--;
    ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
  }
  cout << ans << endl;
  return 0;
}


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

signed main(void) {
  int A, B, m;
  cin >> A >> B >> m;
  int a[A], b[B];
  int x[m], y[m], c[m];
  int ans, min_a, min_b;
  min_a = min_b = 1e9;
  rep(i, A) {
    cin >> a[i];
    min_a = min(a[i], min_a);
  }
  rep(i, B) {
    cin >> b[i];
    min_b = min(b[i], min_b);
  }
  ans = min_a + min_b;
  rep(i, m) {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--;
    y[i]--;
    ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
  }
  cout << ans << endl;
  return 0;
}
Problem p02748 (C++)

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

int n, m, z;
int a[10010], b[10010];
int out = 1000000, min2 = 1000000;

int main() {
  cin >> n >> m >> z;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    out = min(out, a[i]);
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    min2 = min(min2, b[i]);
  }
  out += min2;
  for (int i = 1; i <= z; i++) {
    int in1, in2, in3;
    cin >> in1 >> in2 >> in3;
    out = min(out, a[in1] + b[in2] - in3);
  }
  cout << out;
  return 0;
}


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

int n, m, z;
int a[100010], b[100010];
int out = 1000000, min2 = 1000000;

int main() {
  cin >> n >> m >> z;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    out = min(out, a[i]);
  }
  for (int i = 1; i <= m; i++) {
    cin >> b[i];
    min2 = min(min2, b[i]);
  }
  out += min2;
  for (int i = 1; i <= z; i++) {
    int in1, in2, in3;
    cin >> in1 >> in2 >> in3;
    out = min(out, a[in1] + b[in2] - in3);
  }
  cout << out;
  return 0;
}
Problem p02748 (C++)

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

int main() {
  int A, a, B, b, M;
  cin >> A >> B >> M;
  a = 100000;
  b = 100000;
  vector<int> vA(A + 1);
  for (int i = 1; i <= A; i++) {
    cin >> vA.at(i);
  }
  vector<int> vB(B + 1);
  for (int i = 1; i <= B; i++) {
    cin >> vB.at(i);
  }
  for (int i = 1; i < A; i++) {
    a = min(a, vA.at(i));
  }
  for (int i = 1; i < B; i++) {
    b = min(b, vB.at(i));
  }
  a += b;
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    a = min(a, vA.at(x) + vA.at(y) - c);
  }
  cout << a << endl;
}


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

int main() {
  int A, a, B, b, M;
  cin >> A >> B >> M;
  a = 100000;
  b = 100000;
  vector<int> vA(A + 1);
  for (int i = 1; i <= A; i++) {
    cin >> vA.at(i);
  }
  vector<int> vB(B + 1);
  for (int i = 1; i <= B; i++) {
    cin >> vB.at(i);
  }
  for (int i = 1; i < A; i++) {
    a = min(a, vA.at(i));
  }
  for (int i = 1; i < B; i++) {
    b = min(b, vB.at(i));
  }
  a += b;
  for (int i = 0; i < M; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    a = min(a, vA.at(x) + vB.at(y) - c);
  }
  cout << a << endl;
}
Problem p02748 (Python)

Buggy submission (status: Runtime Error):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s = []
s.append(min(a) + min(b))

for i in range(M):
    x_i, y_i, c_i = map(int, input().split())
    minus = a[x_i - 1] + a[y_i - 1] - c_i
    s.append(minus)

print(min(s))


Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

s = []
s.append(min(a) + min(b))

for i in range(M):
    x_i, y_i, c_i = map(int, input().split())
    minus = a[x_i - 1] + b[y_i - 1] - c_i
    s.append(minus)

print(min(s))