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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

int Z_algo(string s, int k) {
  int n = s.length();
  vector<int> z(n);
  int L = 0, R = 0;
  for (int i = 1; i < n; i++) {
    if (i > R) {
      L = R = i;
      while (R < n && s[R - L] == s[R])
        R++;
      z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (z[k] < R - i + 1)
        z[i] = z[k];
      else {
        L = i;
        while (R < n && s[R - L] == s[R])
          R++;
        z[i] = R - L;
        R--;
      }
    }
  }
  int mx = 0;
  for (int i = k; i < n; i++)
    mx = max(mx, z[i]);
  return mx;
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int mx = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      mx = max(mx, Z_algo(s.substr(i, j) + "#" + s.substr(j, n - j), j));
    }
  }
  cout << mx;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L

int Z_algo(string s, int k) {
  int n = s.length();
  vector<int> z(n);
  int L = 0, R = 0;
  for (int i = 1; i < n; i++) {
    if (i > R) {
      L = R = i;
      while (R < n && s[R - L] == s[R])
        R++;
      z[i] = R - L;
      R--;
    } else {
      int k = i - L;
      if (z[k] < R - i + 1)
        z[i] = z[k];
      else {
        L = i;
        while (R < n && s[R - L] == s[R])
          R++;
        z[i] = R - L;
        R--;
      }
    }
  }
  int mx = 0;
  for (int i = k; i < n; i++)
    mx = max(mx, z[i]);
  return mx;
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int mx = 0;
  for (int i = n - 1; i >= 0; i--) {
    mx = max(mx, Z_algo(s.substr(i, n - i) + "#" + s.substr(0, i), n - i));
  }
  cout << mx;
  return 0;
}
Problem p02913 (C++)

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

using namespace std;
typedef long long ll;

const int MAXLEN = 5 * 1e3 + 5;

int n;
string s;
int dp[MAXLEN][MAXLEN];

int solve(int i, int j, int lim) {
  if (i >= n || j >= n)
    return 0;
  if (i >= lim)
    return 0;

  if (dp[i][j] >= 0)
    return dp[i][j];

  if (s[i] != s[j])
    return 0;

  return 1 + solve(i + 1, j + 1, lim);
}

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

  memset(dp, -1, sizeof(dp));

  int len = 0;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      len = max(len, solve(i, j, j));
    }
  }

  cout << len;
}

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

using namespace std;
typedef long long ll;

const int MAXLEN = 5 * 1e3 + 5;

int n;
string s;
int dp[MAXLEN][MAXLEN];

int solve(int i, int j, int lim) {
  if (i >= n || j >= n)
    return 0;
  if (i >= lim)
    return 0;

  if (dp[i][j] >= 0)
    return dp[i][j];

  if (s[i] != s[j])
    return 0;

  dp[i][j] = 1 + solve(i + 1, j + 1, lim);
  return dp[i][j];
}

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

  memset(dp, -1, sizeof(dp));

  int len = 0;

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      len = max(len, solve(i, j, j));
    }
  }

  cout << len;
}
Problem p02913 (C++)

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

vector<int> zFunc(string s) {
  int n = (int)s.length();
  vector<int> z(n, 0);
  for (int i = 0, l = 0, r = 0; i < n; ++i) {
    if (i <= r)
      z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n and s[z[i]] == s[i + z[i]])
      ++z[i];
    if (i + z[i] - 1 > r)
      l = i, r = i + z[i] - 1;
  }
  return z;
}

int main() {
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  string S;
  cin >> S;

  string T = "";
  int ans = 0;
  FOR(i, 0, N - 1) {
    T = S[N - 1 - i] + T;

    vector<int> z = zFunc(T);
    FOR(j, 0, (int)T.length() - 1) ans = max(ans, min(j, z[j]));
  }
  cout << ans << '\n';
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

vector<int> zFunc(string s) {
  int n = (int)s.length();
  vector<int> z(n, 0);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r)
      z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n and s[z[i]] == s[i + z[i]])
      ++z[i];
    if (i + z[i] - 1 > r)
      l = i, r = i + z[i] - 1;
  }
  return z;
}

int main() {
  // freopen("in.txt", "r", stdin);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;
  string S;
  cin >> S;

  string T = "";
  int ans = 0;
  FOR(i, 0, N - 1) {
    T = S[N - 1 - i] + T;

    vector<int> z = zFunc(T);
    FOR(j, 0, (int)T.length() - 1) ans = max(ans, min(j, z[j]));
  }
  cout << ans << '\n';
}
Problem p02913 (C++)

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

const int MAXN = 5005;

int M[MAXN][MAXN];

int main() {
  std::ios_base::sync_with_stdio(0);
  int n;
  std::string s;
  std::cin >> n >> s;
  int result = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (s[i] == s[j]) {
        M[i][j] = std::min(M[i - 1][j - 1] + 1, j - i);
        result = std::max(result, M[i][j]);
      }
    }
  }
  std::cout << result;
  return 0;
}

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

const int MAXN = 5005;

int M[MAXN][MAXN];

int main() {
  std::ios_base::sync_with_stdio(0);
  int n;
  std::string s;
  std::cin >> n >> s;
  int result = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (s[i] == s[j]) {
        if (i == 0 || j == 0)
          M[i][j] = 1;
        else
          M[i][j] = std::min(M[i - 1][j - 1] + 1, j - i);
        result = std::max(result, M[i][j]);
      }
    }
  }
  std::cout << result;
  return 0;
}
Problem p02913 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  rep(i, N) {
    string s;
    for (int j = i; j < N - 1; j++) {
      s += S[j];
      int is = S.find(s, j + 1);
      if (is != string::npos)
        chmax(ans, (int)s.size());
      else
        break;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 1; i < N; i++) { // 2つの部分文字列の開始位置j,j+iの距離
    int cnt = 0;
    rep(j, N - i) {
      if (cnt < i && S[j] == S[j + i]) {
        cnt++;
        chmax(ans, cnt);
      } else
        cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02913 (C++)

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

int z[5001];
int res = 0;
int n;
string s;

void solve() {
  for (int i = 0; i < n; i++)
    z[i] = 0;
  int l = 0, r = 0;
  for (int i = 0; i < n; i++) {
    if (i <= r) {
      z[i] = min(r - i + 1, z[i - l]);
    }
    while (i + z[i] < n && s[z[i]] == s[i + z[i]])
      z[i]++;
    if (i + z[i] - 1 > r)
      l = i, r = i + z[i] - 1;
  }

  for (int i = 1; i < n; i++) {
    res = max(res, min(i, z[i]));
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> s;
  while (n > 0) {
    solve();
    n--;
    for (int i = 0; i < n; i++)
      s[i] = s[i + 1];
  }
  cout << res;
}


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

int z[5001];
int res = 0;
int n;
string s;

void solve() {
  for (int i = 0; i < n; i++)
    z[i] = 0;
  int l = 0, r = 0;
  for (int i = 1; i < n; i++) {
    if (i <= r) {
      z[i] = min(r - i + 1, z[i - l]);
    }
    while (i + z[i] < n && s[z[i]] == s[i + z[i]])
      z[i]++;
    if (i + z[i] - 1 > r)
      l = i, r = i + z[i] - 1;
  }

  for (int i = 1; i < n; i++) {
    res = max(res, min(i, z[i]));
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> s;
  while (n > 0) {
    solve();
    n--;
    for (int i = 0; i < n; i++)
      s[i] = s[i + 1];
  }
  cout << res;
}
Problem p02913 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define loop1(n, i) for (int i = 1; i <= n; i++)
#define rloop(n, i) for (int i = n; i; i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;

const long long mod1 = 999999937LL, mod2 = 1000000007LL, base = 9973;

int main() {
  int n;
  cin >> n;
  string S;
  cin >> S;
  V<ll> hash1(n), hash2(n);

  loop(n, i) {
    hash1[i] = S[i];
    hash2[i] = S[i];
  }

  int l = 0, r = n;
  while (r - l > 1) {
    int i = (l + r) / 2;
    int found = 0;
    unordered_set<ll> set1, set2;
    ll pow1 = 1, pow2 = 1;
    loop(i, j) {
      pow1 = (pow1 * base) % mod1;
      pow2 = (pow2 * base) % mod2;
    }
    hash1[0] = S[0] % mod1;
    hash2[0] = S[0] % mod2;
    loop1(n, j) {
      hash1[j] = (hash1[j - 1] * base + S[j]) % mod1;
      hash2[j] = (hash2[j - 1] * base + S[j]) % mod2;
      if (j - i >= 0) {
        hash1[j] -= (S[j - i] * pow1) % mod1;
        hash1[j] = (hash1[j] + mod1) % mod1;
        hash2[j] -= (S[j - i] * pow2) % mod2;
        hash2[j] = (hash2[j] + mod2) % mod2;
      }
    }
    for (int j = i; j < n; j++) {
      set1.insert(hash1[j - i]);
      set2.insert(hash2[j - i]);
      if (set1.find(hash1[j]) != set1.end() &&
          set2.find(hash2[j]) != set2.end()) {
        found = 1;
      }
    }
    if (found)
      l = i;
    else
      r = i;
  }
  cout << l << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define loop(n, i) for (int i = 0; i < n; i++)
#define loop1(n, i) for (int i = 1; i <= n; i++)
#define rloop(n, i) for (int i = n; i; i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T> using V = vector<T>;

const long long mod1 = 999999937LL, mod2 = 1000000007LL, base = 9973;

int main() {
  int n;
  cin >> n;
  string S;
  cin >> S;
  V<ll> hash1(n), hash2(n);

  loop(n, i) {
    hash1[i] = S[i];
    hash2[i] = S[i];
  }

  int l = 0, r = n;
  while (r - l > 1) {
    int i = (l + r) / 2;
    int found = 0;
    unordered_set<ll> set1, set2;
    ll pow1 = 1, pow2 = 1;
    loop(i, j) {
      pow1 = (pow1 * base) % mod1;
      pow2 = (pow2 * base) % mod2;
    }
    hash1[0] = S[0] % mod1;
    hash2[0] = S[0] % mod2;
    loop1(n - 1, j) {
      hash1[j] = (hash1[j - 1] * base + S[j]) % mod1;
      hash2[j] = (hash2[j - 1] * base + S[j]) % mod2;
      if (j - i >= 0) {
        hash1[j] -= (S[j - i] * pow1) % mod1;
        hash1[j] = (hash1[j] + mod1) % mod1;
        hash2[j] -= (S[j - i] * pow2) % mod2;
        hash2[j] = (hash2[j] + mod2) % mod2;
      }
    }
    for (int j = i; j < n; j++) {
      set1.insert(hash1[j - i]);
      set2.insert(hash2[j - i]);
      if (set1.find(hash1[j]) != set1.end() &&
          set2.find(hash2[j]) != set2.end()) {
        found = 1;
      }
    }
    if (found)
      l = i;
    else
      r = i;
  }
  cout << l << endl;

  return 0;
}
Problem p02913 (C++)

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

using namespace std;

#define N_MAX 5000

int dp[N_MAX + 1][N_MAX + 1];

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int main() {
  int N;
  string s;

  cin >> N;
  cin >> s;

  int men = 0;
  int mlen = 0;

  for (int k = 0; k < N - 1; k++) {
    string s1 = s.substr(k, N - k);
    string s2 = s1;

    Fill(dp, 0);

    int maxlen = 0;
    int endIdx = 0;
    for (int i = 0; i < N - k; i++) {
      for (int j = i + 1; j < N - k; j++) {
        if (s1[i] == s2[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
          if (dp[i + 1][j + 1] > j - i) {
            dp[i + 1][j + 1] = j - i;
          }
          if (dp[i + 1][j + 1] > maxlen) {
            maxlen = dp[i + 1][j + 1];
            endIdx = i + 1;
          }
        }
      }
    }

    if (mlen <= maxlen) {
      mlen = maxlen;
      men = endIdx + k;
    }
  }

  string com = s.substr(men - mlen, mlen);
  //  cout <<men << "," << mlen << endl;

  //  cout << com << endl;
  cout << mlen << endl;

  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

#define N_MAX 5000

int dp[N_MAX + 1][N_MAX + 1];

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}

int main() {
  int N;
  string s;

  cin >> N;
  cin >> s;

  int men = 0;
  int mlen = 0;

  //  for(int k=0; k<N-1; k++) {
  for (int k = 0; k < 1; k++) {
    string s1 = s.substr(k, N - k);
    string s2 = s1;

    Fill(dp, 0);

    int maxlen = 0;
    int endIdx = 0;
    for (int i = 0; i < N - k; i++) {
      for (int j = i + 1; j < N - k; j++) {
        if (s1[i] == s2[j]) {
          dp[i + 1][j + 1] = dp[i][j] + 1;
          if (dp[i + 1][j + 1] > j - i) {
            dp[i + 1][j + 1] = j - i;
          }
          if (dp[i + 1][j + 1] > maxlen) {
            maxlen = dp[i + 1][j + 1];
            endIdx = i + 1;
          }
        }
      }
    }

    if (mlen <= maxlen) {
      mlen = maxlen;
      men = endIdx + k;
    }
  }

  string com = s.substr(men - mlen, mlen);
  //  cout <<men << "," << mlen << endl;

  //  cout << com << endl;
  cout << mlen << endl;

  return 0;
}
Problem p02913 (C++)

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

using namespace std;

const int N_MAX = 5 * 1e3 + 10;

typedef struct cover {
  int first;
  int second;
  int len;
} Cover;

int checked[N_MAX][N_MAX] = {0};

int main() {
  int N;
  string S;

  cin >> N >> S;

  queue<Cover> que;

  for (int i = 0; i < S.length(); i++) {
    for (int j = i + 1; j < S.length(); j++) {
      if (S[i] == S[j]) {
        if (checked[i][j] == 0) {
          que.push(Cover{i, j, 1});
        }
        checked[i][j] = 1;
      }
    }
  }

  int ans = 0;
  while (!que.empty()) {
    Cover c = que.front();
    que.pop();

    if (ans < c.len)
      ans = c.len;

    int nf = c.first + c.len;
    int ns = c.second + c.len;

    if (nf >= S.length())
      continue;
    if (ns >= S.length())
      continue;
    if (nf >= c.second)
      continue;

    if (S[nf] == S[ns]) {
      c.len += 1;
      que.push(c);
    }
  }

  cout << ans << endl;
}


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

using namespace std;

const int N_MAX = 5 * 1e3 + 10;

typedef struct cover {
  int first;
  int second;
  int len;
} Cover;

int checked[N_MAX][N_MAX] = {0};

int main() {
  int N;
  string S;

  cin >> N >> S;

  queue<Cover> que;

  for (int i = 0; i < S.length(); i++) {
    for (int j = i + 1; j < S.length(); j++) {
      if (S[i] == S[j]) {
        if (i == 0 || j == 0) {
          que.push(Cover{i, j, 1});
        } else if (checked[i - 1][j - 1] == 0) {
          que.push(Cover{i, j, 1});
        }
        checked[i][j] = 1;
      }
    }
  }

  int ans = 0;
  while (!que.empty()) {
    Cover c = que.front();
    que.pop();

    if (ans < c.len)
      ans = c.len;

    int nf = c.first + c.len;
    int ns = c.second + c.len;

    if (nf >= S.length())
      continue;
    if (ns >= S.length())
      continue;
    if (nf >= c.second)
      continue;

    if (S[nf] == S[ns]) {
      c.len += 1;
      que.push(c);
    }
  }

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

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define chmax(x, y) x = max(x, y)
using namespace std;

int mx = 0;
int n;
string s;

int nextfree = 1;
class trie {
  uint32_t d[20] = {0};

public:
  int first;
  int depth;

  int nxt(int i) {
    int s = i * 24, t = s + 24;
    int sa = s / 32, sb = s % 32;
    int ta = t / 32, tb = t % 32;
    if (sa == ta) {
      return d[sa] & ((1 << 24) - 1);
    }
    return (d[sa] >> sb) | ((d[ta] & ((1 << tb) - 1)) << (24 - tb));
  }
  void setnxt(int i, uint32_t v) {
    int s = i * 24, t = s + 24;
    int sa = s / 32, sb = s % 32;
    int ta = t / 32, tb = t % 32;
    if (sa == ta) {
      d[sa] = v | ((d[sa] >> 24) << 24);
      return;
    }
    d[sa] = d[sa] & ((1 << sb) - 1) | (v << sb);
    d[ta] = ((d[ta] >> tb) << tb) | (v >> (24 - tb));
  }
  // trie(int f, int d): first(f), depth(d) {}
} t[5000 * 5001 / 2];

void f(int i_nxt, int first, trie &pre) {
  if (i_nxt >= n || i_nxt - first > n / 2)
    return;
  int tc = s[i_nxt] - 'a';
  if (pre.nxt(tc) == 0) {
    pre.setnxt(tc, nextfree++);
    t[pre.nxt(tc)].first = first;
    t[pre.nxt(tc)].depth = pre.depth + 1;
  }
  trie &now = t[pre.nxt(tc)];
  int d = now.depth;
  if (now.first + d <= first) {
    chmax(mx, d);
  }
  return f(i_nxt + 1, first, now);
}

int main() {
  cin >> n;
  cin >> s;
  rep(i, n) { f(i, i, t[0]); }
  cout << mx << endl;
}


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

int mx = 0;
int n;
string s;

int nextfree = 1;
class trie {
  uint32_t d[20] = {0};

public:
  int first;
  int depth;

  int nxt(int i) {
    int s = i * 24, t = s + 24;
    int sa = s / 32, sb = s % 32;
    int ta = t / 32, tb = t % 32;
    if (sa == ta) {
      return d[sa] & ((1 << 24) - 1);
    }
    return (d[sa] >> sb) | ((d[ta] & ((1 << tb) - 1)) << (24 - tb));
  }
  void setnxt(int i, uint32_t v) {
    int s = i * 24, t = s + 24;
    int sa = s / 32, sb = s % 32;
    int ta = t / 32, tb = t % 32;
    if (sa == ta) {
      d[sa] = v | ((d[sa] >> 24) << 24);
      return;
    }
    d[sa] = d[sa] & ((1 << sb) - 1) | (v << sb);
    d[ta] = ((d[ta] >> tb) << tb) | (v >> (24 - tb));
  }
  // trie(int f, int d): first(f), depth(d) {}
} t[5000 * 5001 / 2 * 5 / 6];

void f(int i_nxt, int first, trie &pre) {
  if (i_nxt >= n || i_nxt - first > n / 2)
    return;
  int tc = s[i_nxt] - 'a';
  if (pre.nxt(tc) == 0) {
    pre.setnxt(tc, nextfree++);
    t[pre.nxt(tc)].first = first;
    t[pre.nxt(tc)].depth = pre.depth + 1;
  }
  trie &now = t[pre.nxt(tc)];
  int d = now.depth;
  if (now.first + d <= first) {
    chmax(mx, d);
  }
  return f(i_nxt + 1, first, now);
}

int main() {
  cin >> n;
  cin >> s;
  rep(i, n) { f(i, i, t[0]); }
  cout << mx << endl;
}
Problem p02913 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 100;
int dp[maxn][maxn];
string str;
int main() {
  int N;
  cin >> N;
  cin >> str;
  for (int j = 1; j < N; ++j)
    dp[0][j] = (str[j] == str[0]);
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      dp[i][j] =
          min(min(j - i, i + 1), (str[j] == str[i]) * (dp[i - 1][j - 1] + 1));
    }
  }
  int ans = 0;
  for (int i = 0; i < N; ++i)
    for (int j = i + 1; j < N; ++j)
      ans = max(ans, dp[i][j]);
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 100;
int dp[maxn][maxn];
string str;
int main() {
  int N;
  cin >> N;
  cin >> str;
  for (int j = 1; j < N; ++j)
    dp[0][j] = (str[j] == str[0]);
  for (int i = 1; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      dp[i][j] =
          min(min(j - i, i + 1), (str[j] == str[i]) * (dp[i - 1][j - 1] + 1));
    }
  }
  int ans = 0;
  for (int i = 0; i < N; ++i)
    for (int j = i + 1; j < N; ++j)
      ans = max(ans, dp[i][j]);
  cout << ans << endl;
  return 0;
}
Problem p02913 (C++)

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

const int MAX = 2500;
const int INF = 1e6;

int n;
string s;

bool C(int x) {
  string M[MAX];
  if (x > n / 2)
    return false;
  for (int i = 0; i + x <= n; i++) {
    M[i] = s.substr(i, x);
  }
  for (int i = 0; i + x + x <= n; i++) {
    for (int j = i + x; j + x <= n; j++) {
      if (M[i] == M[j])
        return true;
    }
  }
  return false;
}

void solve() {
  int lb = 0, ub = INF;

  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (C(mid))
      lb = mid;
    else
      ub = mid;
  }

  printf("%d\n", lb);
}

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

  solve();
}

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

const int MAX = 5000;
const int INF = 1e6;

int n;
string s;

bool C(int x) {
  string M[MAX];
  if (x > n / 2)
    return false;
  for (int i = 0; i + x <= n; i++) {
    M[i] = s.substr(i, x);
  }
  for (int i = 0; i + x + x <= n; i++) {
    for (int j = i + x; j + x <= n; j++) {
      if (M[i] == M[j])
        return true;
    }
  }
  return false;
}

void solve() {
  int lb = 0, ub = INF;

  while (ub - lb > 1) {
    int mid = (lb + ub) / 2;
    if (C(mid))
      lb = mid;
    else
      ub = mid;
  }

  printf("%d\n", lb);
}

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

  solve();
}
Problem p02913 (C++)

Buggy submission (status: Runtime Error):
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
// #define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

// int dp[5005][5005];
int dp[5][5];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, ans = 0;
  string S;
  cin >> N >> S;

  for (int i = N - 1; i >= 0; i--) {
    for (int j = i + 1; j < N; j++) {
      if (S[i] == S[j]) {
        dp[i][j] = dp[i + 1][j + 1] + 1;
        ans = max(ans, min(dp[i][j], j - i));
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
// #define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

int dp[5005][5005];

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, ans = 0;
  string S;
  cin >> N >> S;

  for (int i = N - 1; i >= 0; i--) {
    for (int j = i + 1; j < N; j++) {
      if (S[i] == S[j]) {
        dp[i][j] = dp[i + 1][j + 1] + 1;
        ans = max(ans, min(dp[i][j], j - i));
      }
    }
  }
  cout << ans << endl;

  return 0;
}
Problem p02913 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int>> dp(n, vector<int>(n));
  for (int i = 0; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (s[i - 1] == s[j - 1]) {
        if (j - dp[i - 1][j - 1] != i)
          dp[i][j] = 1 + dp[i - 1][j - 1];
        else {
          dp[i][j] = dp[i - 1][j - 1];
        }
      } else {
        dp[i][j] = 0;
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 0;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<int>> dp(n + 1, vector<int>(n + 1));
  for (int i = 0; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (s[i - 1] == s[j - 1]) {
        if (j - dp[i - 1][j - 1] != i)
          dp[i][j] = 1 + dp[i - 1][j - 1];
        else {
          dp[i][j] = dp[i - 1][j - 1];
        }
      } else {
        dp[i][j] = 0;
      }
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02913 (Python)

Buggy submission (status: Time Limit Exceeded):
N = int(input())
S = input()

ans = 0
left, right = 0, 1

while right < N:
    s = S[left:right]
    if s in S[right:]:
        right += 1
        ans = max(ans, len(s))
    else:
        left = right - 1

print(ans)


Fixed submission:
N = int(input())
S = input()

ans = 0
left, right = 0, 1

while right < N:
    s = S[left:right]
    if s in S[right:]:
        right += 1
        ans = max(ans, len(s))
    else:
        left += 1

print(ans)
Problem p02913 (C++)

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

using namespace std;

// FILE *fi=freopen("1.txt","r",stdin);

int n;
char ch[5001];
string s, sam;

bool check(int k) {
  int dem = 1, vt = 0;
  vector<pair<string, int>> a;
  string s1;
  for (int i = 1; i <= k; ++i) {
    char c = ch[i];
    s1.push_back(ch[i]);
  }
  a.push_back({s1, 1});
  for (int i = k + 1; i <= n; ++i) {
    dem++;
    s1.erase(s1.begin());
    s1.push_back(ch[i]);
    a.push_back({s1, dem});
  }
  sort(a.begin(), a.end());
  while (vt < a.size()) {
    int j = vt;
    while (vt < a.size() - 1 && a[j].first == a[vt + 1].first) {
      if (a[j].second + k <= a[vt + 1].second)
        return true;
      vt++;
    }
    vt++;
  }
  return false;
}

void process() {
  int l = 0, r = n / 2 + 1, mid, kq = 0;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid)) {
      l = mid + 1;
      kq = mid;
    } else
      r = mid - 1;
  }
  cout << kq;
}

int main() {
  scanf("%d", &n);
  cin >> s;
  s = "1" + s;
  for (int i = 1; i <= n; ++i)
    ch[i] = s[i];
  process();
  return 0;
}


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

using namespace std;

// FILE *fi=freopen("1.txt","r",stdin);

int n;
char ch[5001];
string s, sam;

bool check(int k) {
  int dem = 1, vt = 0;
  vector<pair<string, int>> a;
  string s1;
  for (int i = 1; i <= k; ++i) {
    char c = ch[i];
    s1.push_back(ch[i]);
  }
  a.push_back({s1, 1});
  for (int i = k + 1; i <= n; ++i) {
    dem++;
    s1.erase(s1.begin());
    s1.push_back(ch[i]);
    a.push_back({s1, dem});
  }
  sort(a.begin(), a.end());
  while (vt < a.size()) {
    int j = vt;
    while (vt < a.size() - 1 && a[j].first == a[vt + 1].first) {
      if (a[j].second + k <= a[vt + 1].second)
        return true;
      vt++;
    }
    vt++;
  }
  return false;
}

void process() {
  int l = 1, r = n / 2, mid, kq = 0;
  while (l <= r) {
    mid = (l + r) / 2;
    if (check(mid)) {
      l = mid + 1;
      kq = mid;
    } else
      r = mid - 1;
  }
  cout << kq;
}

int main() {
  scanf("%d", &n);
  cin >> s;
  s = "1" + s;
  for (int i = 1; i <= n; ++i)
    ch[i] = s[i];
  process();
  return 0;
}
Problem p02913 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 5e3 + 5;
const ll LINF = 1e18 + 5;
int n;
char s[N];
int nxt[N];
void kmp_pre(char s[], int m, int nxt[]) {
  int i = 0, j = nxt[0] = -1;
  while (i < m) {
    while (j != -1 && s[i] != s[j])
      j = nxt[j];
    nxt[++i] = ++j;
  }
}
bool kmp_work(char s[], int n, char t[], int m) {
  int i = 0, j = 0;
  kmp_pre(s, n, nxt);
  while (i < m) {
    while (j != -1 && t[i] != s[j])
      j = nxt[j];
    i++;
    j++;
    if (j >= n)
      return 1;
  }
  return 0;
}
bool check(int x) {
  for (int i = 0; i + 2 * x - 1 < n; i++)
    for (int j = i + x; j + x - 1 < n; j++)
      if (kmp_work(s + i, x, s + j, n - j))
        return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  int l = 1, r = n / 2, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
const int INF = 0x3f3f3f3f, N = 5e3 + 5;
const ll LINF = 1e18 + 5;
int n;
char s[N];
int nxt[N];
void kmp_pre(char s[], int m, int nxt[]) {
  int i = 0, j = nxt[0] = -1;
  while (i < m) {
    while (j != -1 && s[i] != s[j])
      j = nxt[j];
    nxt[++i] = ++j;
  }
}
bool kmp_work(char s[], int n, char t[], int m) {
  int i = 0, j = 0;
  kmp_pre(s, n, nxt);
  while (i < m) {
    while (j != -1 && t[i] != s[j])
      j = nxt[j];
    i++;
    j++;
    if (j >= n)
      return 1;
  }
  return 0;
}
bool check(int x) {
  for (int i = 0; i + 2 * x - 1 < n; i++)
    if (kmp_work(s + i, x, s + i + x, n - i - x))
      return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> s;
  int l = 1, r = n / 2, ans = 0;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid))
      ans = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  cout << ans;
  return 0;
}
Problem p02913 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
int main() {
  ll n, len = 0, start = 0, tmp = 1;
  string s, t;
  cin >> n >> s;
  while (len < 2 / n || start < n - 1) {
    t = s.substr(start, tmp);
    for (ll i = start + tmp; i < n; i++) {
      if (t == s.substr(i, tmp)) {
        len = tmp;
        break;
      }
    }
    if (len == tmp)
      tmp++;
    else
      start++;
    if (start + tmp >= n)
      start++;
  }
  cout << len << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
int main() {
  ll n, len = 0, start = 0, tmp = 1;
  string s, t;
  cin >> n >> s;
  while (len < n / 2 && start < n - 1) {
    t = s.substr(start, tmp);
    for (ll i = start + tmp; i < n; i++) {
      if (t == s.substr(i, tmp)) {
        len = tmp;
        break;
      }
    }
    if (len == tmp)
      tmp++;
    else
      start++;
    if (start + tmp >= n)
      start++;
  }
  cout << len << endl;
}
Problem p02913 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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

  int N;
  cin >> N;
  string S;
  cin >> S;

  int kotae = 0;
  rep(p, N) {

    int Z[2000];
    Z[0] = N;
    int i = 1;
    int j = 0;
    while (i < N - p) {
      while (i + j < N - p && S[p + j] == S[p + i + j])
        j++;
      Z[i] = j;
      if (j == 0) {
        i++;
        continue;
      }
      int k = 1;
      while (i + k < N && k + Z[k] < j) {
        Z[i + k] = Z[k];
        k++;
      }
      i += k;
      j -= k;
    }

    rep(q, N - p) { kotae = max(kotae, min(Z[q], q)); }
  }
  co(kotae);

  Would you please return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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

  int N;
  cin >> N;
  string S;
  cin >> S;

  int kotae = 0;
  rep(p, N) {

    int Z[5000];
    Z[0] = N;
    int i = 1;
    int j = 0;
    while (i < N - p) {
      while (i + j < N - p && S[p + j] == S[p + i + j])
        j++;
      Z[i] = j;
      if (j == 0) {
        i++;
        continue;
      }
      int k = 1;
      while (i + k < N && k + Z[k] < j) {
        Z[i + k] = Z[k];
        k++;
      }
      i += k;
      j -= k;
    }

    rep(q, N - p) { kotae = max(kotae, min(Z[q], q)); }
  }
  co(kotae);

  Would you please return 0;
}
Problem p02913 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

int N;
string s;

bool exist(int l) {
  if (l == 0)
    return false;
  for (int i = 0; i < N; i++) {
    if (N - (i + l) < l)
      return false;
    string p = s.substr(i, l);
    for (int j = i + l; j + l <= N; j++) {
      string q = s.substr(j, l);
      if (p == q)
        return true;
    }
  }
  return false;
}

int main(void) {
  cin >> N;
  cin >> s;
  int left = 0, right = N / 2;

  while (abs(right - left) > 1) {
    int m = (right + left) / 2;
    if (exist(m))
      left = m;
    else
      right = m;
  }
  if (exist(right))
    cout << right << endl;
  else
    cout << left << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>

#define REP(i, n) for (int i = 0; i < (n); i++)
#define EPS (1e-7)
#define INF (3e9)

using namespace std;
typedef long long int ll;

int N;
string s;

bool exist(int l) {
  if (l == 0)
    return false;
  for (int i = 0; i < N; i++) {
    if (N - (i + l) < l)
      return false;
    string p = s.substr(i, l);
    string q = s.substr(i + l);
    if (q.find(p) != string::npos)
      return true;
  }
  return false;
}

int main(void) {
  cin >> N;
  cin >> s;
  int left = 0, right = N / 2;

  while (abs(right - left) > 1) {
    int m = (right + left) / 2;
    if (exist(m))
      left = m;
    else
      right = m;
  }
  if (exist(right))
    cout << right << endl;
  else
    cout << left << endl;

  return 0;
}
Problem p02914 (C++)

Buggy submission (status: Runtime Error):
/*
source: ABC 141 F Xor Sum 3
*/
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MXN = 10005;

int main() {
  int n;
  LL a[MXN], b[MXN], sum = 0;
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum ^= a[i];
  }
  for (int i = 0; i < n; ++i) {
    a[i] &= (~sum);
    for (int j = 60; j >= 0; --j) {
      if ((a[i] >> j) & 1) {
        if (b[j] == 0) {
          b[j] = a[i];
          break;
        } else {
          a[i] ^= b[j];
        }
      }
    }
  }
  LL x = 0;
  for (int i = 60; i >= 0; --i) {
    x = max(x, x ^ b[i]);
  }
  cout << (x + (x ^ sum)) << '\n';
}

Fixed submission:
/*
source: ABC 141 F Xor Sum 3
*/
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int MXN = 100005;

int main() {
  int n;
  LL a[MXN], b[MXN], sum = 0;
  memset(a, 0, sizeof(a));
  memset(b, 0, sizeof(b));
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum ^= a[i];
  }
  for (int i = 0; i < n; ++i) {
    a[i] &= (~sum);
    for (int j = 60; j >= 0; --j) {
      if ((a[i] >> j) & 1) {
        if (b[j] == 0) {
          b[j] = a[i];
          break;
        } else {
          a[i] ^= b[j];
        }
      }
    }
  }
  LL x = 0;
  for (int i = 60; i >= 0; --i) {
    x = max(x, x ^ b[i]);
  }
  cout << (x + (x ^ sum)) << '\n';
}
Problem p02914 (C++)

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

using namespace std;

long long mask = 0;

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

  int n;
  cin >> n;
  long long arr[n];
  for (auto &i : arr)
    cin >> i;
  for (auto i : arr)
    mask ^= i;
  mask = ~mask;
  sort(arr, arr + n,
       [](long long x, long long y) { return (x & mask) > (y & mask); });

  vector<long long> root;
  for (auto i : arr) {
    for (auto j : root)
      if ((i & mask) > ((i ^ j) & mask))
        i = i ^ j;
    if (i)
      root.push_back(i);
  }

  long long ans = 0;
  for (auto i : root) {
    if ((ans & mask) < ((ans ^ i) & mask))
      ans = ans ^ i;
  }

  cout << ans + (~mask ^ ans);
  return 0;
}


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

using namespace std;

long long mask = 0;

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

  int n;
  cin >> n;
  long long arr[n];
  for (auto &i : arr)
    cin >> i;
  for (auto i : arr)
    mask ^= i;
  mask = ~mask;
  sort(arr, arr + n,
       [](long long x, long long y) { return (x & mask) > (y & mask); });

  vector<long long> root;
  for (auto i : arr) {
    for (auto j : root)
      if ((i & mask) > ((i ^ j) & mask))
        i = i ^ j;
    if (i & mask)
      root.push_back(i);
  }

  long long ans = 0;
  for (auto i : root) {
    if ((ans & mask) < ((ans ^ i) & mask))
      ans = ans ^ i;
  }

  cout << ans + (~mask ^ ans);
  return 0;
}
Problem p02914 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
  return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
  return (b < a) ? (a = b, 1) : 0;
}
template <class C> void print(const C &c, std::ostream &os = std::cout) {
  std::copy(std::begin(c), std::end(c),
            std::ostream_iterator<typename C::value_type>(os, " "));
  os << std::endl;
}

int main() {
  int n;
  cin >> n;
  vl a(n);
  ll xorsum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    xorsum ^= a[i];
  }
  for (int i = 0; i < n; ++i) {
    a[i] &= ~xorsum;
  }
  vector<bool> used(60, false);
  for (ll i = 60; i >= 0; --i) {
    int idx = -1;
    for (int j = 0; j < n; ++j) {
      if (!used[j] && ((1LL << i) & a[j])) {
        idx = j;
        break;
      }
    }
    if (idx == -1)
      continue;
    used[idx] = true;
    for (int j = 0; j < n; ++j) {
      if (j == idx)
        continue;
      if (a[j] & (1LL << i))
        a[j] ^= a[idx];
    }
  }
  ll ret = xorsum;
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    sum ^= a[i];
  }
  cout << ret + 2LL * sum << "\n";

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T> bool chmax(T &a, const T &b) {
  return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
  return (b < a) ? (a = b, 1) : 0;
}
template <class C> void print(const C &c, std::ostream &os = std::cout) {
  std::copy(std::begin(c), std::end(c),
            std::ostream_iterator<typename C::value_type>(os, " "));
  os << std::endl;
}

int main() {
  int n;
  cin >> n;
  vl a(n);
  ll xorsum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    xorsum ^= a[i];
  }
  for (int i = 0; i < n; ++i) {
    a[i] &= ~xorsum;
  }
  vector<bool> used(n, false);
  for (ll i = 60; i >= 0; --i) {
    int idx = -1;
    for (int j = 0; j < n; ++j) {
      if (!used[j] && ((1LL << i) & a[j])) {
        idx = j;
        break;
      }
    }
    if (idx == -1)
      continue;
    used[idx] = true;
    for (int j = 0; j < n; ++j) {
      if (j == idx)
        continue;
      if (a[j] & (1LL << i))
        a[j] ^= a[idx];
    }
  }
  ll ret = xorsum;
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    sum ^= a[i];
  }
  cout << ret + 2LL * sum << "\n";

  return 0;
}
Problem p02915 (Python)

Buggy submission (status: Runtime Error):
N = int(input().split())

print(N * N * N)


Fixed submission:
N = int(input())

print(N * N * N)
Problem p02915 (Python)

Buggy submission (status: Runtime Error):
a = input()
print(a**3)


Fixed submission:
a = int(input())
print(a**3)
Problem p02915 (Python)

Buggy submission (status: Runtime Error):
N = input(int())
print(N**3)


Fixed submission:
N = int(input())
print(N**3)
Problem p02915 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define pob pop_back();
#define for_t                                                                  \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define MOD 1000000007
#define fi first
#define se second
#define le length
#define debug(n1) cout << n1 << endl
#define set_bits(n) __builtin_popcount(n);
#define rep(i, j, n) for (ll i = j; i <= n; i++)
#define per(i, j, n) for (ll i = j; i >= n; i--)
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef map<int, int> mapp;

int stoif(string num) {
  stringstream geek(num);
  int x = 0;
  geek >> x;
  return x;
}

int main() {
  SPEED;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int n;
  cin >> n;
  int ans = n * n * n;
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define pob pop_back();
#define for_t                                                                  \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define MOD 1000000007
#define fi first
#define se second
#define le length
#define debug(n1) cout << n1 << endl
#define set_bits(n) __builtin_popcount(n);
#define rep(i, j, n) for (ll i = j; i <= n; i++)
#define per(i, j, n) for (ll i = j; i >= n; i--)
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef map<int, int> mapp;

int stoif(string num) {
  stringstream geek(num);
  int x = 0;
  geek >> x;
  return x;
}

int main() {
  SPEED;
  int n;
  cin >> n;
  int ans = n * n * n;
  cout << ans;
  return 0;
}
Problem p02915 (Python)

Buggy submission (status: Runtime Error):
len = input()
print(len**3)


Fixed submission:
len = int(input())
print(len**3)
Problem p02915 (C++)

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

int main() {
  int N;
  scanf("%d", N);
  printf("%d", N * N * N);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  printf("%d\n", n * n * n);
  return 0;
}
Problem p02915 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n) for (ll i = 0; i < (n); i++)
int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> vec(10000000);
  for (ll i = 0; i < 1000; i++) {
    for (ll j = 0; j < 10000; j++) {
      for (int k = 0; k < 500; k++) {
        vec.at(i + j + k)++;
      }
    }
  }
  cout << n * n * n << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, n) for (ll i = 0; i < (n); i++)
int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> vec(10000000);
  for (ll i = 0; i < 1000; i++) {
    for (ll j = 0; j < 10000; j++) {
      for (int k = 0; k < 50; k++) {
        vec.at(i + j + k)++;
      }
    }
  }
  cout << n * n * n << endl;
}
Problem p02915 (C++)

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

using namespace std;
int main() {
  int n;
  cin >> n;

  return n * n * n;
}

Fixed submission:
#include <iostream>

using namespace std;
int main() {
  int n;
  cin >> n;

  cout << n * n * n << endl;
  return 0;
}
Problem p02915 (C++)

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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
//

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())

// main function here

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("C:/Users/Saurav Kumar Singh/Desktop/cp/input.txt", "r", stdin);
  freopen("C:/Users/Saurav Kumar Singh/Desktop/cp/output.txt", "w", stdout);
#endif
  ll n;
  cin >> n;
  cout << n * n * n << "\n";
  return 0;
}


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

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
//

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())

// main function here

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

  ll n;
  cin >> n;
  cout << n * n * n << "\n";
  return 0;
}