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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define IO_OP                                                                  \
  std::ios::sync_with_stdio(0);                                                \
  std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 1e5 + 7;

int dp[N], nxt[N][26], tran[N];

signed main() {
  IO_OP;

  string s;
  cin >> s;
  for (int j = 0; j < 26; j++)
    nxt[s.size()][j] = s.size();
  for (int i = s.size() - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++)
      nxt[i][j] = nxt[i + 1][j];
    nxt[i][s[i] - 'a'] = i;
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    dp[i] = INF;
    for (int j = 0; j < 26; j++) {
      int cur = dp[nxt[i + 1][j]] + 1;
      if (dp[i] > cur) {
        dp[i] = cur;
        tran[i] = j;
      }
    }
  }
  int mn = INF, st;
  for (int j = 0; j < 26; j++) {
    int cur = dp[nxt[0][j]] + 1;
    if (cur < mn) {
      mn = cur;
      st = j;
    }
  }
  string t;
  int pos = -1;
  for (int i = 0; i < mn; i++) {
    t.PB('a' + st);
    pos = nxt[pos + 1][st];
    st = tran[pos];
  }
  cout << t << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define IO_OP                                                                  \
  std::ios::sync_with_stdio(0);                                                \
  std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7, N = 2e5 + 7;

int dp[N], nxt[N][26], tran[N];

signed main() {
  IO_OP;

  string s;
  cin >> s;
  for (int j = 0; j < 26; j++)
    nxt[s.size()][j] = s.size();
  for (int i = s.size() - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++)
      nxt[i][j] = nxt[i + 1][j];
    nxt[i][s[i] - 'a'] = i;
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    dp[i] = INF;
    for (int j = 0; j < 26; j++) {
      int cur = dp[nxt[i + 1][j]] + 1;
      if (dp[i] > cur) {
        dp[i] = cur;
        tran[i] = j;
      }
    }
  }
  int mn = INF, st;
  for (int j = 0; j < 26; j++) {
    int cur = dp[nxt[0][j]] + 1;
    if (cur < mn) {
      mn = cur;
      st = j;
    }
  }
  string t;
  int pos = -1;
  for (int i = 0; i < mn; i++) {
    t.PB('a' + st);
    pos = nxt[pos + 1][st];
    st = tran[pos];
  }
  cout << t << endl;
}
Problem p03629 (C++)

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

constexpr int INF = 1e9;

int main() {
  string A;
  cin >> A;
  int const n = A.size();
  vector<vector<int>> pos(n + 1, vector<int>(26, INF));
  for (int i = n; i >= 0; --i) {
    if (i - 1 >= 0) {
      pos[i - 1] = pos[i];
      pos[i - 1][A[i - 1] - 'a'] = i;
    }
  }
  vector<bool> visited(n + 1);
  queue<pair<int, string>> que;
  que.push(make_pair(0, ""));
  string res;
  visited[0] = true;
  while (!que.empty()) {
    auto p = que.front();
    int v = p.first;
    que.pop();
    for (int i = 0; i < 26; ++i) {
      if (pos[v][i] == INF) {
        res = p.second + char('a' + i);
        cout << res << endl;
        return 0;
      }
    }
    for (int i = 0; i < 26; ++i) {
      int next_p = pos[v][i];
      if (visited[next_p]) {
        continue;
      }
      que.push(make_pair(next_p, p.second + char('a' + i)));
    }
  }
  cout << res << endl;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

constexpr int INF = 1e9;

int main() {
  string A;
  cin >> A;
  int const n = A.size();
  vector<vector<int>> pos(n + 1, vector<int>(26, INF));
  for (int i = n; i >= 0; --i) {
    if (i - 1 >= 0) {
      pos[i - 1] = pos[i];
      pos[i - 1][A[i - 1] - 'a'] = i;
    }
  }
  vector<bool> visited(n + 1);
  queue<pair<int, string>> que;
  que.push(make_pair(0, ""));
  string res;
  visited[0] = true;
  while (!que.empty()) {
    auto p = que.front();
    int v = p.first;
    que.pop();
    for (int i = 0; i < 26; ++i) {
      if (pos[v][i] == INF) {
        res = p.second + char('a' + i);
        cout << res << endl;
        return 0;
      }
    }
    for (int i = 0; i < 26; ++i) {
      int next_p = pos[v][i];
      if (visited[next_p]) {
        continue;
      }
      que.push(make_pair(next_p, p.second + char('a' + i)));
      visited[next_p] = true;
    }
  }
  cout << res << endl;
}
Problem p03629 (C++)

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

using namespace std;

string A;

int K[100005];
vector<int> cpos[26];

int main() {
  cin >> A;
  int used[26];
  int cnt = 0;
  int k = 1;
  memset(used, 0, sizeof(used));
  for (int i = A.length() - 1; i >= 0; i--) {
    char c = A[i];
    int n = c - 'a';
    cpos[n].insert(cpos[n].begin(), i);
    if (used[n] == 0) {
      used[n] = 1;
      cnt++;
    }
    if (cnt == 26) {
      memset(used, 0, sizeof(used));
      cnt = 0;
      k++;
    }
    K[i] = k;
  }
  string ans = "";
  int anslen = 0;
  int cp = 0;
  // cout << "K[0] = " << K[0] << endl;
  for (int i = 0; anslen != K[0];) {
    // cout << "i = " << i << endl;
    for (int j = 0; j < 26; j++) {

      int flag = 0;
      vector<int>::iterator r = cpos[j].begin();
      int p = -1;
      if (cpos[j].size() != 0) {
        r = lower_bound(cpos[j].begin(), cpos[j].end(), i);
        p = *r;
        if (K[p + 1] == K[i] - 1 || r == cpos[j].end()) {
          flag = 1;
        }
      } else {
        flag = 1;
      }
      if (flag == 1) {
        ans += j + 'a';
        anslen++;
        i = p + 1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

string A;

int K[200005];
vector<int> cpos[26];

int main() {
  cin >> A;
  int used[26];
  int cnt = 0;
  int k = 1;
  memset(used, 0, sizeof(used));
  for (int i = A.length() - 1; i >= 0; i--) {
    char c = A[i];
    int n = c - 'a';
    cpos[n].insert(cpos[n].begin(), i);
    if (used[n] == 0) {
      used[n] = 1;
      cnt++;
    }
    if (cnt == 26) {
      memset(used, 0, sizeof(used));
      cnt = 0;
      k++;
    }
    K[i] = k;
  }
  string ans = "";
  int anslen = 0;
  int cp = 0;
  // cout << "K[0] = " << K[0] << endl;
  for (int i = 0; anslen != K[0];) {
    // cout << "i = " << i << endl;
    for (int j = 0; j < 26; j++) {

      int flag = 0;
      vector<int>::iterator r = cpos[j].begin();
      int p = -1;
      if (cpos[j].size() != 0) {
        r = lower_bound(cpos[j].begin(), cpos[j].end(), i);
        p = *r;
        if (K[p + 1] == K[i] - 1 || r == cpos[j].end()) {
          flag = 1;
        }
      } else {
        flag = 1;
      }
      if (flag == 1) {
        ans += j + 'a';
        anslen++;
        i = p + 1;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03629 (C++)

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

using namespace std;

const int MAX_N = 1e5 + 10;

int n;
char s[MAX_N];

int dp[MAX_N];
char f[MAX_N];
int nt[MAX_N];
int last[26];

int main() {
  int i, j;
  scanf("%s", s + 1);
  n = strlen(s + 1);

  for (i = 0; i < 26; i++)
    last[i] = n + 1;

  dp[n + 1] = (1 << 30);
  dp[n + 2] = 0;

  for (i = n; i >= 1; i--) {
    dp[i] = (1 << 30);
    last[s[i] - 'a'] = i;
    for (j = 0; j < 26; j++) {
      if (dp[i] > (dp[last[j] + 1] + 1)) {
        dp[i] = dp[last[j] + 1] + 1;
        f[i] = char(j + 'a');
        nt[i] = last[j] + 1;
      }
    }
  }

  int x = 1;

  while (x <= n) {
    printf("%c", f[x]);
    x = nt[x];
  }
  printf("\n");

  return 0;
}


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

using namespace std;

const int MAX_N = 2e5 + 10;

int n;
char s[MAX_N];

int dp[MAX_N];
char f[MAX_N];
int nt[MAX_N];
int last[26];

int main() {
  int i, j;
  scanf("%s", s + 1);
  n = strlen(s + 1);

  for (i = 0; i < 26; i++)
    last[i] = n + 1;

  dp[n + 1] = (1 << 30);
  dp[n + 2] = 0;

  for (i = n; i >= 1; i--) {
    dp[i] = (1 << 30);
    last[s[i] - 'a'] = i;
    for (j = 0; j < 26; j++) {
      if (dp[i] > (dp[last[j] + 1] + 1)) {
        dp[i] = dp[last[j] + 1] + 1;
        f[i] = char(j + 'a');
        nt[i] = last[j] + 1;
      }
    }
  }

  int x = 1;

  while (x <= n) {
    printf("%c", f[x]);
    x = nt[x];
  }
  printf("\n");

  return 0;
}
Problem p03629 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  int n, d[200005][26] = {}, b[200005] = {};
  string s, z;
  cin >> s;
  n = (int)s.length();
  for (int i = 0; i < 26; i++)
    d[n][i] = n + 1;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++)
      d[i][j] = d[i + 1][j];
    d[i][s[i] - 'a'] = i + 1;
    // for (int j = 0; j < 26; j++) cout << d[i][j] << ' '; cout << '\n';
  }
  for (int i = 0; i <= n; i++) {
    int c = i;
    while (c <= n) {
      int e = 0;
      for (int j = 0; j < 26; j++)
        e = max(e, d[c][j]);
      c = e;
      b[i]++;
    }
    // cout << i << ' ' << b[i] << '\n';
  }
  int c = 0;
  for (int i = b[0]; i; i--) {
    int e = 0;
    for (int j = 0; j < 26; j++)
      if (b[d[c][j]] == i - 1) {
        e = j;
        c = d[c][j];
        break;
      }
    z += (char)(e + 'a');
  }
  cout << z;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
  ios::sync_with_stdio(false);
  int n, d[200005][26] = {}, b[200005] = {};
  string s, z;
  cin >> s;
  n = (int)s.length();
  for (int i = 0; i < 26; i++)
    d[n][i] = n + 1;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = 0; j < 26; j++)
      d[i][j] = d[i + 1][j];
    d[i][s[i] - 'a'] = i + 1;
    // for (int j = 0; j < 26; j++) cout << d[i][j] << ' '; cout << '\n';
  }
  for (int i = n; i >= 0; i--) {
    b[i] = 890328;
    for (int j = 0; j < 26; j++)
      b[i] = min(b[i], b[d[i][j]] + 1);
    // cout << i << ' ' << b[i] << '\n';
  }
  int c = 0;
  for (int i = b[0]; i; i--) {
    int e = 0;
    for (int j = 0; j < 26; j++)
      if (b[d[c][j]] == i - 1) {
        e = j;
        c = d[c][j];
        break;
      }
    z += (char)(e + 'a');
  }
  cout << z;
}
Problem p03629 (C++)

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

using namespace std;
const int nmax = 100005;
string s;
int nxt[nmax][30], prc[nmax], best[nmax];
int n, i, j, cnt, poz;
char ch;
int main() {
  ios_base::sync_with_stdio(false);
  // freopen("data.in","r",stdin);
  cin >> s;
  n = s.size();
  s = " " + s;
  for (j = 0; j < 26; j++)
    nxt[n][j] = n + 1;
  for (i = n; i >= 0; i--) {
    best[i] = (1 << 30);
    if (i >= 1)
      for (j = 0; j < 26; j++)
        nxt[i - 1][j] = nxt[i][j];
    if (i >= 1)
      nxt[i - 1][s[i] - 'a'] = i;
    for (j = 0; j < 26; j++) {
      if (1 + best[nxt[i][j]] < best[i])
        best[i] = 1 + best[nxt[i][j]], prc[i] = j;
    }
  }
  cnt = best[0];
  poz = 0;
  for (i = 1; i <= cnt; i++) {
    ch = 'a' + prc[poz];
    cout << ch;
    poz = nxt[poz][prc[poz]];
  }
  return 0;
}

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

using namespace std;
const int nmax = 200005;
string s;
int nxt[nmax][30], prc[nmax], best[nmax];
int n, i, j, cnt, poz;
char ch;
int main() {
  ios_base::sync_with_stdio(false);
  // freopen("data.in","r",stdin);
  cin >> s;
  n = s.size();
  s = " " + s;
  for (j = 0; j < 26; j++)
    nxt[n][j] = n + 1;
  for (i = n; i >= 0; i--) {
    best[i] = (1 << 30);
    if (i >= 1)
      for (j = 0; j < 26; j++)
        nxt[i - 1][j] = nxt[i][j];
    if (i >= 1)
      nxt[i - 1][s[i] - 'a'] = i;
    for (j = 0; j < 26; j++) {
      if (1 + best[nxt[i][j]] < best[i])
        best[i] = 1 + best[nxt[i][j]], prc[i] = j;
    }
  }
  cnt = best[0];
  poz = 0;
  for (i = 1; i <= cnt; i++) {
    ch = 'a' + prc[poz];
    cout << ch;
    poz = nxt[poz][prc[poz]];
  }
  return 0;
}
Problem p03629 (C++)

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

int t, i;
bitset<26> bt[26][1000], m;
string s, ans;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  for (i = s.size() - 1; i >= 0; i--) {
    bt[s[i] - 'a'][t] = m;
    m.set((int)(s[i] - 'a'));
    if (m.all()) {
      t++;
      m.reset();
    }
  }
  while (t + 1) {
    for (i = 0; m[i]; i++)
      ;
    ans.push_back((char)('a' + i));
    if (t--)
      m = bt[i][t];
  }
  cout << ans << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
#define mx 5005
#define inf 100000000000005
using namespace std;

int t, i;
bitset<26> bt[26][10000], m;
string s, ans;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  for (i = s.size() - 1; i >= 0; i--) {
    bt[s[i] - 'a'][t] = m;
    m.set((int)(s[i] - 'a'));
    if (m.all()) {
      t++;
      m.reset();
    }
  }
  while (t + 1) {
    for (i = 0; m[i]; i++)
      ;
    ans.push_back((char)('a' + i));
    if (t--)
      m = bt[i][t];
  }
  cout << ans << '\n';
}
Problem p03630 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const int MX = 15;
int h, w, c[MX], ans, e, st[MX], hi[MX];
char s[MX][MX];
bool b[MX][MX];
int main() {
  scanf("%d%d", &h, &w);
  ans = max(h, w);
  rep(i, h) scanf("\n%s", s[i]);
  rep(i, h - 1) rep(j, w - 1) b[i][j] =
      !(s[i][j] ^ s[i + 1][j] ^ s[i][j + 1] ^ s[i + 1][j + 1]);
  rep(i, h - 1) {
    e = 0;
    rep(j, w) {
      while (c[j] < i || b[c[j]][j])
        c[j]++;
      if (e && hi[e - 1] > c[j]) {
        for (; e && hi[e - 1] > c[j]; e--)
          ans = max(ans, (hi[e - 1] - i + 1) * (j - st[e - 1] + 1));
      } else
        st[e] = j;
      hi[e++] = c[j];
    }
  }
  printf("%d\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const int MX = 2005;
int h, w, c[MX], ans, e, st[MX], hi[MX];
char s[MX][MX];
bool b[MX][MX];
int main() {
  scanf("%d%d", &h, &w);
  ans = max(h, w);
  rep(i, h) scanf("\n%s", s[i]);
  rep(i, h - 1) rep(j, w - 1) b[i][j] =
      !(s[i][j] ^ s[i + 1][j] ^ s[i][j + 1] ^ s[i + 1][j + 1]);
  rep(i, h - 1) {
    e = 0;
    rep(j, w) {
      while (c[j] < i || b[c[j]][j])
        c[j]++;
      if (e && hi[e - 1] > c[j]) {
        for (; e && hi[e - 1] > c[j]; e--)
          ans = max(ans, (hi[e - 1] - i + 1) * (j - st[e - 1] + 1));
      } else
        st[e] = j;
      hi[e++] = c[j];
    }
  }
  printf("%d\n", ans);
}
Problem p03630 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;

struct rect {
  ll h, w;
};

ll H, W;
char S[2000][2000];
ll f[2000][2000];

rect max_rectangle(ll *h, ll n) {
  struct item {
    ll h, p;
  };
  stack<item> stk;
  rect m = (rect){0, 0};

  REP(i, 0, n + 1) {
    item r = (item){i < n ? h[i] : 0, i};
    if (stk.empty()) {
      stk.push(r);
    } else {
      if (stk.top().h < r.h)
        stk.push(r);
      if (stk.top().h > r.h) {
        ll t = i;
        while (stk.size() && stk.top().h >= r.h) {
          item s = stk.top();
          stk.pop();
          s.h *(i - s.p);
          if (s.h * (i - s.p) > m.h * m.w)
            m = (rect){s.h, i - s.p};
          t = s.p;
        }
        r.p = t;
        stk.push(r);
      }
    }
  }

  return m;
}

int main(void) {
  cin >> H >> W;
  REP(i, 0, H) REP(j, 0, W) cin >> S[i][j];

  REP(i, 0, H - 1) REP(j, 0, W - 1) {
    f[i][j] = ((S[i][j] == '#') + (S[i][j + 1] == '#') + (S[i + 1][j] == '#') +
               (S[i + 1][j + 1] == '#')) %
                  2 ==
              0;
  }
  for (ll i = H - 3; i >= 0; i--)
    REP(j, 0, W - 1) {
      if (f[i][j] > 0)
        f[i][j] += f[i + 1][j];
    }

  REP(i, 0, H - 1) {
    REP(j, 0, W - 1) cerr << f[i][j] << " ";
    cerr << endl;
  }

  ll ans = max(H, W);
  REP(i, 0, H - 1) {
    rect m = max_rectangle(&f[i][0], W - 1);
    ans = max(ans, (m.h + 1) * (m.w + 1));
  }
  cout << ans << endl;
}


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

struct rect {
  ll h, w;
};

ll H, W;
char S[2000][2000];
ll f[2000][2000];

rect max_rectangle(ll *h, ll n) {
  struct item {
    ll h, p;
  };
  stack<item> stk;
  rect m = (rect){0, 0};

  REP(i, 0, n + 1) {
    item r = (item){i < n ? h[i] : 0, i};
    if (stk.empty()) {
      stk.push(r);
    } else {
      if (stk.top().h < r.h)
        stk.push(r);
      if (stk.top().h > r.h) {
        ll t = i;
        while (stk.size() && stk.top().h >= r.h) {
          item s = stk.top();
          stk.pop();
          s.h *(i - s.p);
          if (s.h * (i - s.p) > m.h * m.w)
            m = (rect){s.h, i - s.p};
          t = s.p;
        }
        r.p = t;
        stk.push(r);
      }
    }
  }

  return m;
}

int main(void) {
  cin >> H >> W;
  REP(i, 0, H) REP(j, 0, W) cin >> S[i][j];

  REP(i, 0, H - 1) REP(j, 0, W - 1) {
    f[i][j] = ((S[i][j] == '#') + (S[i][j + 1] == '#') + (S[i + 1][j] == '#') +
               (S[i + 1][j + 1] == '#')) %
                  2 ==
              0;
  }
  for (ll i = H - 3; i >= 0; i--)
    REP(j, 0, W - 1) {
      if (f[i][j] > 0)
        f[i][j] += f[i + 1][j];
    }

  ll ans = max(H, W);
  REP(i, 0, H - 1) {
    rect m = max_rectangle(&f[i][0], W - 1);
    ans = max(ans, (m.h + 1) * (m.w + 1));
  }
  cout << ans << endl;
}
Problem p03630 (C++)

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

int h, w;

char c[2010][2010];
int x[2010][2010];

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    cin >> c[i];

  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (c[i - 1][j - 1] == c[i - 1][j]) {
        x[i - 1][j - 1] = c[i][j - 1] == c[i][j] ? 1 : 0;
      } else {
        x[i - 1][j - 1] = c[i][j - 1] != c[i][j] ? 1 : 0;
      }
    }
  }

  int dp[1010][1010] = {};
  for (int j = 0; j < w - 1; j++) {
    if (x[0][j] == 1)
      dp[0][j] = 1;
    for (int i = 1; i < h - 1; i++) {
      if (x[i][j] == 1) {
        dp[i][j] += dp[i - 1][j] + 1;
      }
    }
  }

  int ans = max(h, w);

  for (int i = 0; i < h - 1; i++) {
    stack<pair<int, int>> st;
    for (int j = 0; j < w; j++) {
      pair<int, int> p;
      p.first = dp[i][j];
      p.second = j;
      if (st.empty()) {
        st.push(p);
      } else if (st.top().first < p.first) {
        st.push(p);
      } else {
        int target = j;
        while (!st.empty() && st.top().first >= p.first) {
          ans = max(ans, (st.top().first + 1) * (j - st.top().second + 1));
          target = st.top().second;
          st.pop();
        }
        p.second = target;
        st.push(p);
      }
    }
  }

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


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

int h, w;

char c[2010][2010];
int x[2010][2010];

int main() {
  cin >> h >> w;
  for (int i = 0; i < h; i++)
    cin >> c[i];

  for (int i = 1; i < h; i++) {
    for (int j = 1; j < w; j++) {
      if (c[i - 1][j - 1] == c[i - 1][j]) {
        x[i - 1][j - 1] = c[i][j - 1] == c[i][j] ? 1 : 0;
      } else {
        x[i - 1][j - 1] = c[i][j - 1] != c[i][j] ? 1 : 0;
      }
    }
  }

  int dp[2010][2010] = {};
  for (int j = 0; j < w - 1; j++) {
    if (x[0][j] == 1)
      dp[0][j] = 1;
    for (int i = 1; i < h - 1; i++) {
      if (x[i][j] == 1) {
        dp[i][j] += dp[i - 1][j] + 1;
      }
    }
  }

  int ans = max(h, w);

  for (int i = 0; i < h - 1; i++) {
    stack<pair<int, int>> st;
    for (int j = 0; j < w; j++) {
      pair<int, int> p;
      p.first = dp[i][j];
      p.second = j;
      if (st.empty()) {
        st.push(p);
      } else if (st.top().first < p.first) {
        st.push(p);
      } else {
        int target = j;
        while (!st.empty() && st.top().first >= p.first) {
          ans = max(ans, (st.top().first + 1) * (j - st.top().second + 1));
          target = st.top().second;
          st.pop();
        }
        p.second = target;
        st.push(p);
      }
    }
  }

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

Buggy submission (status: Memory Limit Exceeded):
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <stack>
using namespace std;

bool barrier[2000][2000];
long long hist_barrier[2000][20001];
char S[2000][2001];

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for (int h = 0; h < H - 1; h++) {
    for (int w = 0; w < W - 1; w++) {
      int cnt_black = 0;
      for (int i = 0; i < 4; i++) {
        cnt_black += (S[h + (i / 2)][w + (i % 2)] == '#') ? 1 : 0;
      }
      barrier[h][w] = (cnt_black % 2 == 1);
    }
  }
  for (int h = 0; h < H; h++) {
    hist_barrier[h][0] = h + 1;
  }
  for (int w = 0; w < W; w++) {
    hist_barrier[0][w] = 1;
  }
  for (int h = 1; h < H; h++) {
    for (int w = 1; w < W; w++) {
      if (barrier[h - 1][w - 1]) {
        hist_barrier[h][w] = 1;
      } else {
        hist_barrier[h][w] = hist_barrier[h - 1][w] + 1;
      }
    }
  }

  long long ans = 0;
  for (int h = 0; h < H; h++) {
    stack<pair<long long, int>> st;
    for (int w = 0; w < W + 1; w++) {
      if (st.empty()) {
        st.push(make_pair(h + 1, w));
      } else if (st.top().first > hist_barrier[h][w]) {
        int last_pos;
        while (!st.empty() && st.top().first >= hist_barrier[h][w]) {
          ans = max(ans, (w - st.top().second) * st.top().first);
          last_pos = st.top().second;
          st.pop();
        }
        st.push(make_pair(hist_barrier[h][w], last_pos));
      }
      if (st.top().first < h + 1) {
        st.push(make_pair(h + 1, w));
      }
    }
  }
  cout << ans << endl;
}


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

bool barrier[2000][2000];
long long hist_barrier[2000][2001];
char S[2000][2001];

int main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  for (int h = 0; h < H - 1; h++) {
    for (int w = 0; w < W - 1; w++) {
      int cnt_black = 0;
      for (int i = 0; i < 4; i++) {
        cnt_black += (S[h + (i / 2)][w + (i % 2)] == '#') ? 1 : 0;
      }
      barrier[h][w] = (cnt_black % 2 == 1);
    }
  }
  for (int h = 0; h < H; h++) {
    hist_barrier[h][0] = h + 1;
  }
  for (int w = 0; w < W; w++) {
    hist_barrier[0][w] = 1;
  }
  for (int h = 1; h < H; h++) {
    for (int w = 1; w < W; w++) {
      if (barrier[h - 1][w - 1]) {
        hist_barrier[h][w] = 1;
      } else {
        hist_barrier[h][w] = hist_barrier[h - 1][w] + 1;
      }
    }
  }

  long long ans = 0;
  for (int h = 0; h < H; h++) {
    stack<pair<long long, int>> st;
    for (int w = 0; w < W + 1; w++) {
      if (st.empty()) {
        st.push(make_pair(h + 1, w));
      } else if (st.top().first > hist_barrier[h][w]) {
        int last_pos;
        while (!st.empty() && st.top().first >= hist_barrier[h][w]) {
          ans = max(ans, (w - st.top().second) * st.top().first);
          last_pos = st.top().second;
          st.pop();
        }
        st.push(make_pair(hist_barrier[h][w], last_pos));
      }
      if (st.top().first < h + 1) {
        st.push(make_pair(h + 1, w));
      }
    }
  }
  cout << ans << endl;
}
Problem p03630 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-9;
const ll mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

int h, w;
vvi a;
vi b;

int main() {
  cin >> h >> w;
  a = vvi(h, vi(w));
  b = vi(w);
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '#')
        a[i][j]++;
    }
  int res = max(h, w);
  for (int i = 0; i < h - 1; i++) {
    stack<pip> st;
    st.push({-1, {-1, -1}});
    for (int j = 0; j <= w; j++) {
      if (j < w - 1 &&
          abs(a[i][j] - a[i][j + 1]) == abs(a[i + 1][j] - a[i + 1][j + 1]) &&
          abs(a[i][j] - a[i + 1][j]) == abs(a[i][j + 1] - a[i + 1][j + 1]))
        b[j]++;
      else
        b[j] = 0;
      while (st.top().first > b[j]) {
        pip p = st.top();
        st.pop();
        res = max(res, (j - p.second.first + 1) * (p.first + 1));
      }
      st.push({b[j], {st.top().second.second + 1, j}});
    }
  }
  cout << res << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define syosu(x) fixed << setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int, P> pip;
typedef vector<pip> vip;
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-9;
const ll mod = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};

int h, w;
vvi a;
vi b;

int main() {
  cin >> h >> w;
  a = vvi(h, vi(w));
  b = vi(w);
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      char c;
      cin >> c;
      if (c == '#')
        a[i][j]++;
    }
  int res = max(h, w);
  for (int i = 0; i < h - 1; i++) {
    stack<pip> st;
    st.push({-1, {-1, -1}});
    for (int j = 0; j < w; j++) {
      if (j < w - 1 &&
          abs(a[i][j] - a[i][j + 1]) == abs(a[i + 1][j] - a[i + 1][j + 1]) &&
          abs(a[i][j] - a[i + 1][j]) == abs(a[i][j + 1] - a[i + 1][j + 1]))
        b[j]++;
      else
        b[j] = 0;
      while (st.top().first > b[j]) {
        pip p = st.top();
        st.pop();
        res = max(res, (j - p.second.first + 1) * (p.first + 1));
      }
      st.push({b[j], {st.top().second.second + 1, j}});
    }
  }
  cout << res << endl;
}
Problem p03631 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str, str2, tmp;
  int n, c;
  str = to_string(n);
  str2 = to_string(n);
  tmp = str.substr(0, 1);
  str.replace(0, 1, str.substr(0, 1));
  str.replace(2, 1, tmp);

  if (str == str2) {
    cout << "Yes"
         << "\n";
  } else {
    cout << "No"
         << "\n";
  }
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string str, str2, tmp;
  int n;
  cin >> n;
  str = to_string(n);
  str2 = to_string(n);
  tmp = str.substr(0, 1);
  str.replace(0, 1, str.substr(0, 1));
  str.replace(2, 1, tmp);

  if (str == str2) {
    cout << "Yes"
         << "\n";
  } else {
    cout << "No"
         << "\n";
  }
}
Problem p03631 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
print("Yes" if n[0] == n[2] else "No")


Fixed submission:
n = input()
print("Yes" if n[0] == n[2] else "No")
Problem p03631 (Python)

Buggy submission (status: Runtime Error):
n = input()
if n(0) == n(2):
    print("Yes")
else:
    print("No")


Fixed submission:
n = input()
if n[0] == n[2]:
    print("Yes")
else:
    print("No")
Problem p03631 (Python)

Buggy submission (status: Runtime Error):
n = input()

if n(0) == n(-1):
    print("Yes")
else:
    print("No")


Fixed submission:
n = input()

if n[0] == n[-1]:
    print("Yes")
else:
    print("No")
Problem p03631 (C++)

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

int main() {
  string n_str = 0;
  cin >> n_str;
  if (n_str[0] == n_str[2])
    puts("Yes");
  else
    puts("No");

  return 0;
}


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

int main() {
  string n_str;
  cin >> n_str;
  if (n_str[0] == n_str[2])
    puts("Yes");
  else
    puts("No");

  return 0;
}
Problem p03631 (C++)

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

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

  if (N.at(0) == N.at(N.at(2)))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

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

  if (N.at(0) == N.at(2))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03631 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long> rec(N);
  for (int i = 0; i < N; i++) {
    cin >> rec.at(i);
  }
  sort(rec.begin(), rec.end());
  long long K;
  K = rec.at(N - 1);
  for (int i = 0; i < N; i++) {
    if (K % rec.at(i) == 0) {
      if (i == N - 1) {
        cout << K << endl;
      } else {
      }
    } else {
      K = K + K;
      continue;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  if (S.at(0) == S.at(2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03631 (C++)

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

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

  string n1;

  int s = 3;

  rep(i, s) {
    n1.at(i) = n.at(s - i - 1);
    if (n1.at(i) != n.at(i)) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}


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

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

  string n1 = n;

  int s = 3;

  rep(i, s) {
    n1.at(i) = n.at(s - i - 1);
    if (n1.at(i) != n.at(i)) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
Problem p03631 (C++)

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

int main() {
  string N;
  if (N.at(0) == N.at(2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  string N;
  cin >> N;
  if (N.at(0) == N.at(2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03631 (C++)

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

typedef long long ll;
typedef pair<int, int> pii;

long long MOD = 1000000000 + 7;

int main() {
  string x, y;
  cin >> x;
  y = x;
  reverse(x.begin(), y.begin());
  if (x == y) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

typedef long long ll;
typedef pair<int, int> pii;

long long MOD = 1000000000 + 7;

int main() {
  string x, y;
  cin >> x;
  y = x;
  reverse(x.begin(), x.end());
  if (x == y) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03631 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.at(0) == s.at(3)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.at(0) == s.at(2)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03632 (Python)

Buggy submission (status: Runtime Error):
a, b, c, d = map(int, input().split())

print(max(min(b, d) - max(a, c)), 0)


Fixed submission:
a, b, c, d = map(int, input().split())

print(max(min(b, d) - max(a, c), 0))
Problem p03632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int inf = 0x3f3f3f3f;
const int ninf = 0xcfcfcfcf;
const double pi = acos(-1.0);
static int faster_iostream = []() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  return 0;
}();

int main() {
#ifndef judge
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  // b = a + b;
  // d = c + d;
  cout << max(0, min(b, d) - max(a, c)) << endl;
  return 0;
}

Fixed submission:
#define judge
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int inf = 0x3f3f3f3f;
const int ninf = 0xcfcfcfcf;
const double pi = acos(-1.0);
static int faster_iostream = []() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  return 0;
}();

int main() {
#ifndef judge
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
#endif
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  // b = a + b;
  // d = c + d;
  cout << max(0, min(b, d) - max(a, c)) << endl;
  return 0;
}
Problem p03632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", a, b, c, d);
  if (c > b) {
    cout << 0;
  } else if (c >= a && d <= b) {
    cout << d - c;
  } else if (c >= a && d >= b) {
    cout << b - c;
  } else if (a > d) {
    cout << 0;
  } else if (a >= c && b <= d) {
    cout << b - a;
  } else if (a >= c && b >= d) {
    cout << d - a;
  } else if (a == c && b == d) {
    cout << b - a;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  int s = max(a, c);
  int g = min(b, d);
  cout << max(g - s, 0);
}
Problem p03632 (C++)

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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int res = 0;
  rep(i, c, d + 1) if (a <= i && i <= b) res++;

  return max(0, res);
}


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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int res = 0;
  rep(i, c, d + 1) if (a <= i && i <= b) res++;

  cout << max(0, res - 1) << endl;
  return 0;
}
Problem p03632 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a, n) vector<int>(a)((n))
#define Vec(a, n) vector<string>(a)((n))
using namespace std;
signed main() {
  int a, b, c, d, n = 101;
  cin >> a >> b >> c >> d;
  vec(f, n);
  REP(i, n) { f[i] = 0; }
  FOR(i, a, a + b + 1) { f[i]++; }
  FOR(i, c, c + d + 1) { f[i]++; }
  int ans = 0;
  REP(i, n) {
    if (f[i] == 2)
      ans++;
  }
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a, n) vector<int>(a)((n))
#define Vec(a, n) vector<string>(a)((n))
using namespace std;
signed main() {
  int a, b, c, d, n = 101;
  cin >> a >> b >> c >> d;
  vec(f, n);
  REP(i, n) { f[i] = 0; }
  FOR(i, a, b) { f[i]++; }
  FOR(i, c, d) { f[i]++; }
  int ans = 0;
  REP(i, n) {
    if (f[i] == 2)
      ans++;
  }
  cout << ans;
  return 0;
}
Problem p03632 (C++)

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

int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  int a, b, c, d, ans = 0;
  cin >> a >> b >> c >> d;
  vector<int> t(200);
  t[a]++;
  t[b]--;
  t[c]++;
  t[d]--;
  for (int i = 0; i < 1000; i++) {
    t[i + 1] += t[i];
  }
  for (int i = 0; i < 1000; i++) {
    if (t[i] == 2) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}

int main() {
  int a, b, c, d, ans = 0;
  cin >> a >> b >> c >> d;
  vector<int> t(10000);
  t[a]++;
  t[b]--;
  t[c]++;
  t[d]--;
  for (int i = 0; i < 1000; i++) {
    t[i + 1] += t[i];
  }
  for (int i = 0; i < 1000; i++) {
    if (t[i] == 2) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03632 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rp(i, n) for (int i = 0; i < n; i++)
#define rep(i, m, n) for (int i = m; i < n; i++)

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  rp(i, INT_MAX) {
    if (a <= i && i <= b && c <= i && i <= d) {
      ans++;
    }
  }
  cout << (ans != 0 ? ans - 1 : 0) << endl;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  rp(i, 101) {
    if (a <= i && i <= b && c <= i && i <= d) {
      ans++;
    }
  }
  cout << (ans != 0 ? ans - 1 : 0) << endl;
}
Problem p03632 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  int n, i, m, a, b, c, d, x, y;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if ((int)a != a)
    return -1;
  if ((int)b != d)
    return -1;
  if ((int)c != c)
    return -1;
  if ((int)d != d)
    return -1;
  if (a < 0 || a >= b || a > 100 || b <= 0 || b > 100)
    return -1;
  else if (c < 0 || c >= d || c > 100 || d <= 0 || d > 100)
    return -1;
  else if (b < c)
    printf("0\n");
  else if (a <= c && b >= d)
    printf("%d\n", d - c);
  else if (a >= c && b <= d)
    printf("%d\n", b - a);
  else
    printf("%d\n", b - c);
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(0, min(b, d) - max(a, c)) << endl;
}
Problem p03633 (C++)

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

using namespace std;

long long lcm(long long a, long long b) {
  long long tmp = max(a, b);

  do {
    if (tmp % a == 0 and tmp % b == 0)
      return tmp;
    else
      tmp++;
  } while (1);
}
int main() {
  int n;
  long long t[100];

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> t[i];

  long long ans;
  long long tmp = t[0];
  for (int i = 1; i < n; i++) {
    tmp = lcm(tmp, t[i]);
  }

  cout << tmp << endl;

  return 0;
}


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

using namespace std;

long long lcm(long long a, long long b) {
  long long tmp = max(a, b);

  do {
    if (tmp % a == 0 and tmp % b == 0)
      return tmp;
    else
      tmp += max(a, b);
  } while (1);
}
int main() {
  int n;
  long long t[100];

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> t[i];

  long long ans;
  long long tmp = t[0];
  for (int i = 1; i < n; i++) {
    tmp = lcm(tmp, t[i]);
  }

  cout << tmp << endl;

  return 0;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>
#include <iostream>
#define N 1000000 + 5
#define ull unsigned long long
using namespace std;
ull n, T[N];
ull gcd(ull a, ull b) {
  if (b == 1)
    return 1;
  return gcd(b, a % b);
}
int main() {
  scanf("%llu", &n);
  for (ull i = 0; i < n; i++)
    scanf("%llu", &T[i]);
  for (ull i = 1; i < n; i++)
    T[i] = T[i] / gcd(T[i], T[i - 1]) * T[i - 1];
  printf("%llu\n", T[n - 1]);
  return 0;
}

Fixed submission:
#include <cmath>
#include <cstdio>
#include <iostream>
#define N 1000000 + 5
#define ull unsigned long long
using namespace std;
ull n, T[N];
ull gcd(ull a, ull b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
int main() {
  scanf("%llu", &n);
  for (ull i = 0; i < n; i++)
    scanf("%llu", &T[i]);
  for (ull i = 1; i < n; i++)
    T[i] = T[i] / gcd(T[i], T[i - 1]) * T[i - 1];
  printf("%llu\n", T[n - 1]);
  return 0;
}
Problem p03633 (C++)

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

ll gdc(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  // cout << a << b << endl;
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  // cout << b << endl;
  return b;
}

int main() {
  int N;
  cin >> N;
  vector<ll> T(N);
  rep(i, N) cin >> T[i];
  ll ans;
  ans = T[0] * T[1] / gdc(T[0], T[1]);
  // cout << ans << endl;
  for (int i = 2; i < N; i++) {
    ans = T[i] / gdc(T[i], ans) * ans;
  }
  cout << ans << endl;
  return 0;
}

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

ll gdc(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  // cout << a << b << endl;
  ll r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  // cout << b << endl;
  return b;
}

int main() {
  int N;
  cin >> N;
  vector<ll> T(N);
  rep(i, N) cin >> T[i];
  ll ans;
  ans = 1;
  for (int i = 0; i < N; i++) {
    ans = ans / gdc(T[i], ans) * T[i];
  }
  cout << ans << endl;
  return 0;
}
Problem p03633 (C++)

Buggy submission (status: Runtime Error):
#pragma once
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd(b, a / b);
}
ll lcm(ll a, ll b) {

  if (a < b) {
    return a * (b / gcd(b, a));
  }
  return b * (a / gcd(a, b));
}
void MultipleClocks() {
  int n;
  cin >> n;
  ll lc = 1;
  for (size_t i = 0; i < n; i++) {
    ll t;
    cin >> t;
    lc = lcm(lc, t);
  }

  cout << lc << endl;
}
int main() {
  MultipleClocks();
  return 0;
}


Fixed submission:
#pragma once
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 10e9;
ll gcd(ll a, ll b) {
  if (a % b == 0)
    return b;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {

  if (a < b) {
    return a * (b / gcd(b, a));
  }
  return b * (a / gcd(a, b));
}
void MultipleClocks() {
  int n;
  cin >> n;
  ll lc = 1;
  for (size_t i = 0; i < n; i++) {
    ll t;
    cin >> t;
    lc = lcm(lc, t);
  }

  cout << lc << endl;
}
int main() {
  MultipleClocks();
  return 0;
}
Problem p03633 (C++)

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

#define ll long long

ll gcd(ll a, ll b) {
  if (a < b) { // aの方が大きくなるようにする
    swap(a, b);
  }
  ll k = a % b;
  while (k) {
    a = b;
    b = k;
    k = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  ll c = gcd(a, b);
  return a / c * b;
}

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  for (ll &x : v)
    cin >> x;

  ll a = lcm(v[0], v[1]);
  for (int i = 2; i < n; i++) {
    a = lcm(a, v[i]);
  }

  cout << a << endl;

  return 0;
}


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

#define ll long long

ll gcd(ll a, ll b) {
  if (a < b) { // aの方が大きくなるようにする
    swap(a, b);
  }
  ll k = a % b;
  while (k) {
    a = b;
    b = k;
    k = a % b;
  }
  return b;
}

ll lcm(ll a, ll b) {
  ll c = gcd(a, b);
  return a / c * b;
}

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  for (ll &x : v)
    cin >> x;

  if (n == 1) {
    cout << v[0] << endl;
    return 0;
  }

  ll a = lcm(v[0], v[1]);
  for (int i = 2; i < n; i++) {
    a = lcm(a, v[i]);
  }

  cout << a << endl;

  return 0;
}
Problem p03633 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
long long gcd(long long n, long long m) {
  if (n % m == 0)
    return m;
  if (m % n == 0)
    return n;
  return n - m > m ? gcd(n - m, m) : gcd(m, n - m);
  // while (n != m)
  //	n > m ? n -= m : m -= n;
  // return n;
}
int main() {
  int n, i;
  long long a[100], k, t;
  cin >> n;
  cin >> a[0];
  k = a[0];
  for (i = 1; i < n; i++) {
    cin >> a[i];
    t = gcd(a[i], k);
    k *= (a[i] / t);
  }
  cout << k << '\n';
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
long long gcd(long long n, long long m) { return n % m ? gcd(m, n % m) : m; }
int main() {
  int n, i;
  long long a[100], k, t;
  cin >> n;
  cin >> a[0];
  k = a[0];
  for (i = 1; i < n; i++) {
    cin >> a[i];
    t = gcd(a[i], k);
    k *= (a[i] / t);
  }
  cout << k << '\n';
  return 0;
}
Problem p03633 (C++)

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

typedef long long int ll;

ll gcd(ll n, ll m) {
  if (m == 0) {
    return n;
  }
  return (m, n % m);
}

ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

int main() {
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ans = lcm(ans, a[i]);
  }
  cout << ans << endl;
}


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

typedef long long int ll;

ll gcd(ll n, ll m) {
  if (m == 0) {
    return n;
  }
  return gcd(m, n % m);
}

ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

int main() {
  int n;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll ans = 1;
  for (int i = 0; i < n; i++) {
    ans = lcm(ans, a[i]);
  }
  cout << ans << endl;
}