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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using lint = long long int;
#define FOR(i, from, to) for (i = (from); i < (to); i++)

const int NMAX = 10005;

int cluc_dist(int x, int xx) {
  int dx = xx - x;
  if (dx < 0)
    dx *= -1;
  return dx;
}

int main() {
  int i, j, k, l;
  int N;
  cin >> N;
  int t[NMAX], x[NMAX], y[NMAX];
  t[0] = x[0] = y[0] = 0;

  int tt, d, dx, dy;
  FOR(i, 1, N + 1) {
    cin >> t[i] >> x[i] >> y[i];
    tt = t[i] - t[i - 1];
    dx = cluc_dist(x[i - 1], x[i]);
    dy = cluc_dist(y[i - 1], y[i]);
    d = dx + dy;

    if (tt < d) {
      cout << "No" << endl;
      return 0;
    }
    if (tt % 2 != d % 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using lint = long long int;
#define FOR(i, from, to) for (i = (from); i < (to); i++)

const int NMAX = 100005;

int cluc_dist(int x, int xx) {
  int dx = xx - x;
  if (dx < 0)
    dx *= -1;
  return dx;
}

int main() {
  int i, j, k, l;
  int N;
  cin >> N;
  int t[NMAX], x[NMAX], y[NMAX];
  t[0] = x[0] = y[0] = 0;

  int tt, d, dx, dy;
  FOR(i, 1, N + 1) {
    cin >> t[i] >> x[i] >> y[i];
    tt = t[i] - t[i - 1];
    dx = cluc_dist(x[i - 1], x[i]);
    dy = cluc_dist(y[i - 1], y[i]);
    d = dx + dy;

    if (tt < d) {
      cout << "No" << endl;
      return 0;
    }
    if (tt % 2 != d % 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}
Problem p03459 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) ((v).begin()), ((v).end())
#define clr(v, val) memset(v, val, sizeof v)
void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout);
#endif
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
const int N = 510 + 20;
int dist(pair<int, int> a, pair<int, int> b) {
  int x = abs(a.first - b.first);
  int y = abs(a.second - b.second);
  return x + y;
}
/***You***Can***Do***It***/
int main() {
  file();
  fast();
  int n;
  while (cin >> n) {
    vector<pair<int, int>> p(n);
    vector<int> t1(n);
    map<pair<int, int>, int> mp;
    bool ok = 1;
    for (int i = 0; i < n; i++) {
      cin >> t1[i] >> p[i].first >> p[i].second;
    }
    int t = 0;
    pair<int, int> nw(0, 0);
    nw.first = 0;
    nw.second = 0;
    for (int i = 0; i < n; i++) {
      int di = dist(nw, p[i]);
      if (nw == p[i]) {
        ok = 0;
        break;
      }
      if ((di > (t1[i] - t)) || (di % 2 == 0 && di != (t1[i] - t))) {
        ok = 0;
        break;
      }
      nw = p[i];
      t = t1[i];
    }
    if (ok)
      cout << "Yes" << endl;
    else {
      cout << "No" << endl;
    }
  }
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) ((v).begin()), ((v).end())
#define clr(v, val) memset(v, val, sizeof v)
void file() {
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout);
#endif
}
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
}
const int N = 510 + 20;
int dist(pair<int, int> a, pair<int, int> b) {
  int x = abs(a.first - b.first);
  int y = abs(a.second - b.second);
  return x + y;
}
/***You***Can***Do***It***/
int main() {
  fast();
  int n;
  while (cin >> n) {
    vector<pair<int, int>> p(n);
    vector<int> t1(n);
    map<pair<int, int>, int> mp;
    bool ok = 1;
    for (int i = 0; i < n; i++) {
      cin >> t1[i] >> p[i].first >> p[i].second;
    }
    int t = 0;
    pair<int, int> nw(0, 0);
    nw.first = 0;
    nw.second = 0;
    for (int i = 0; i < n; i++) {
      int di = dist(nw, p[i]);
      if (nw == p[i]) {
        ok = 0;
        break;
      }
      if ((di > (t1[i] - t)) || (di % 2 == 0 && di != (t1[i] - t))) {
        ok = 0;
        break;
      }
      nw = p[i];
      t = t1[i];
    }
    if (ok)
      cout << "Yes" << endl;
    else {
      cout << "No" << endl;
    }
  }
}
Problem p03459 (C++)

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

signed main() {
  int N;
  cin >> N;
  int out = 0;
  std::vector<int> t(N), x(N), y(N);
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  for (int i = 1; i < N + 1; i++)
    cin >> t[i] >> x[i] >> y[i];
  for (int i = 1; i < N + 1; i++) {
    if (t[i] - t[i - 1] < abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]))
      out++;
    else if ((t[i] - t[i - 1]) % 2 !=
             (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) % 2)
      out++;
  }
  if (out)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}


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

signed main() {
  int N;
  cin >> N;
  int out = 0;
  std::vector<int> t(N + 1), x(N + 1), y(N + 1);
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  for (int i = 1; i < N + 1; i++)
    cin >> t[i] >> x[i] >> y[i];
  for (int i = 1; i < N + 1; i++) {
    if (t[i] - t[i - 1] < abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]))
      out++;
    else if ((t[i] - t[i - 1]) % 2 !=
             (abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) % 2)
      out++;
  }
  if (out)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}
Problem p03459 (C++)

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

using namespace std;

const int maxn = 100100;

int t[maxn], x[maxn], y[maxn], n;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> t[i] >> x[i] >> y[i];
  x[0] = 0;
  y[0] = 0;
  for (int i = 1; i <= n; i++) {
    int l = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
    int ti = t[i] - t[i - 1];
    if ((l % 2 != ti % 2) || (l > ti)) {
      cout << "No";
      return 1;
    }
  }
  cout << "Yes";
}


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

using namespace std;

const int maxn = 100100;

int t[maxn], x[maxn], y[maxn], n;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> t[i] >> x[i] >> y[i];
  x[0] = 0;
  y[0] = 0;
  for (int i = 1; i <= n; i++) {
    int l = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
    int ti = t[i] - t[i - 1];
    if ((l % 2 != ti % 2) || (l > ti)) {
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
Problem p03459 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define LL long long
using namespace std;
/*int ans_now;
int n,m;
bool flag[51][51];
void dfs(int u, int distance)
{
    if(distance>ans_now)
        return;
    if(u==n)
    {
        ans_now=distance;
        return ;
    }
    for(int i=1;i<=n;i++)
    {
        if(flag[u][i])
            dfs(i,distance+1);
    }
}
int fun()
{
    ans_now=0x3f3f3f3f;
    dfs(1,0);
    return ans_now;
}*/
int t[11000], x[11000], y[11000];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  /*while(cin>>n>>m)
  {
      memset(flag,0,sizeof(flag));
      for(int i=0;i<m;i++)
      {
          int a,b;
          cin>>a>>b;
          flag[a][b]=1;
      }
      cout<<fun()<<endl;
  }*/
  int n;
  while (cin >> n) {
    t[0] = 0, x[0] = 0, y[0] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> t[i] >> x[i] >> y[i];
    }
    bool flag = 1;
    for (int i = 1; i <= n; i++) {
      int dis = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
      int time = t[i] - t[i - 1];
      if (time >= dis && (time - dis) % 2 == 0) {

      } else {
        flag = 0;
        break;
      }
    }
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define LL long long
using namespace std;
/*int ans_now;
int n,m;
bool flag[51][51];
void dfs(int u, int distance)
{
    if(distance>ans_now)
        return;
    if(u==n)
    {
        ans_now=distance;
        return ;
    }
    for(int i=1;i<=n;i++)
    {
        if(flag[u][i])
            dfs(i,distance+1);
    }
}
int fun()
{
    ans_now=0x3f3f3f3f;
    dfs(1,0);
    return ans_now;
}*/
int t[110000], x[110000], y[110000];
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  /*while(cin>>n>>m)
  {
      memset(flag,0,sizeof(flag));
      for(int i=0;i<m;i++)
      {
          int a,b;
          cin>>a>>b;
          flag[a][b]=1;
      }
      cout<<fun()<<endl;
  }*/
  int n;
  while (cin >> n) {
    t[0] = 0, x[0] = 0, y[0] = 0;
    for (int i = 1; i <= n; i++) {
      cin >> t[i] >> x[i] >> y[i];
    }
    bool flag = 1;
    for (int i = 1; i <= n; i++) {
      int dis = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
      int time = t[i] - t[i - 1];
      if (time >= dis && (time - dis) % 2 == 0) {

      } else {
        flag = 0;
        break;
      }
    }
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
Problem p03459 (C++)

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

using namespace std;
typedef long long ll;

int N;
int T[10001];
int X[10001];
int Y[10001];

bool ok() {
  for (int i = 0; i < N; i++) {
    int t = T[i + 1] - T[i];
    int dx = X[i + 1] - X[i];
    int dy = Y[i + 1] - Y[i];
    int dist = abs(dx) + abs(dy);
    int diff = t - dist;
    if (!(diff >= 0 && diff % 2 == 0)) {
      return false;
    }
  }
  return true;
}

signed main() {
  cin >> N;
  T[0] = 0;
  X[0] = 0;
  Y[0] = 0;
  for (int i = 0; i < N; i++) {
    cin >> T[i + 1] >> X[i + 1] >> Y[i + 1];
  }
  cout << (ok() ? "Yes" : "No") << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

int N;
int T[100001];
int X[100001];
int Y[100001];

bool ok() {
  for (int i = 0; i < N; i++) {
    int t = T[i + 1] - T[i];
    int dx = X[i + 1] - X[i];
    int dy = Y[i + 1] - Y[i];
    int dist = abs(dx) + abs(dy);
    int diff = t - dist;
    if (!(diff >= 0 && diff % 2 == 0)) {
      return false;
    }
  }
  return true;
}

signed main() {
  cin >> N;
  T[0] = 0;
  X[0] = 0;
  Y[0] = 0;
  for (int i = 0; i < N; i++) {
    cin >> T[i + 1] >> X[i + 1] >> Y[i + 1];
  }
  cout << (ok() ? "Yes" : "No") << endl;
  return 0;
}
Problem p03459 (C++)

Buggy submission (status: Runtime Error):
// C++14 (Clang 3.8.0)

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#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<long long, long long> P;

const int max_n = 10000 + 10;
int a[max_n];
int b[max_n];
int t[max_n];

int main() {
  int n;
  cin >> n;
  bool flag = true;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> a[i] >> b[i];
    int tmp;
    tmp = abs(a[i] - a[i - 1]) + abs(b[i] - b[i - 1]);
    if (tmp <= t[i] - t[i - 1] and tmp % 2 == (t[i] - t[i - 1]) % 2) {
      continue;
    } else {
      flag = false;
    }
  }
  if (flag)
    cout << "Yes\n" << endl;
  else
    cout << "No\n" << endl;
  return 0;
}


Fixed submission:
// C++14 (Clang 3.8.0)

#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#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<long long, long long> P;

const int max_n = 100000 + 10;
int a[max_n];
int b[max_n];
int t[max_n];

int main() {
  int n;
  cin >> n;
  bool flag = true;
  for (int i = 1; i <= n; i++) {
    cin >> t[i] >> a[i] >> b[i];
    int tmp;
    tmp = abs(a[i] - a[i - 1]) + abs(b[i] - b[i - 1]);
    if (tmp <= t[i] - t[i - 1] and tmp % 2 == (t[i] - t[i - 1]) % 2) {
      continue;
    } else {
      flag = false;
    }
  }
  if (flag)
    cout << "Yes\n" << endl;
  else
    cout << "No\n" << endl;
  return 0;
}
Problem p03460 (C++)

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

using namespace std;

vector<pair<int, int>> v[1010];
int cntx[1010], cnty[1010], n, k, ans, vx[1010], vy[1010], t[1010];

void solve(int tip) {
  int sol = 0;
  for (int i = 1; i <= k; i++) {
    v[i].clear();
    cntx[i] = 0;
    cnty[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    int a = vx[i] / k, b = vy[i] / k, p = 0;
    int d1 = (a + 1) * k - vx[i], d2 = (b + 1) * k - vy[i];
    if (a % 2 == 0 && b % 2 == 0) {
      if (t[i] == tip) {
        sol++;
        p = 1;
      }
    } else if (a % 2 == 1 && b % 2 == 1) {
      if (t[i] == tip) {
        sol++;
        p = 1;
      }
    } else if (t[i] == 1 - tip) {
      sol++;
      p = 1;
    }
    if (p == 1) {
      cntx[d1]--;
      cnty[d2]--;
      v[d1].push_back({d2, 2});
    } else {
      cntx[d1]++;
      cnty[d2]++;
      v[d1].push_back({d2, -2});
    }
  }
  for (int i = 0; i < k; i++) {
    sol += cntx[i];
    for (int j = 0; j < v[i].size(); j++)
      cnty[v[i][j].first] += v[i][j].second;
    for (int j = 0; j < k; j++) {
      sol += cnty[j];
      ans = max(ans, sol);
    }
    for (int j = 0; j < k; j++)
      sol -= cnty[j];
  }
}

int main() {
  // freopen("file.in","r",stdin);
  // freopen("file.out","w",stdout);
  char c;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d %c\n", &vx[i], &vy[i], &c);
    if (c == 'W')
      t[i] = 0;
    else
      t[i] = 1;
  }
  solve(0);
  solve(1);
  printf("%d", ans);
  return 0;
}


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

using namespace std;

vector<pair<int, int>> v[1010];
int cntx[1010], cnty[1010], n, k, ans, vx[100010], vy[100010], t[100010];

void solve(int tip) {
  int sol = 0;
  for (int i = 1; i <= k; i++) {
    v[i].clear();
    cntx[i] = 0;
    cnty[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    int a = vx[i] / k, b = vy[i] / k, p = 0;
    int d1 = (a + 1) * k - vx[i], d2 = (b + 1) * k - vy[i];
    if (a % 2 == 0 && b % 2 == 0) {
      if (t[i] == tip) {
        sol++;
        p = 1;
      }
    } else if (a % 2 == 1 && b % 2 == 1) {
      if (t[i] == tip) {
        sol++;
        p = 1;
      }
    } else if (t[i] == 1 - tip) {
      sol++;
      p = 1;
    }
    if (p == 1) {
      cntx[d1]--;
      cnty[d2]--;
      v[d1].push_back({d2, 2});
    } else {
      cntx[d1]++;
      cnty[d2]++;
      v[d1].push_back({d2, -2});
    }
  }
  for (int i = 0; i < k; i++) {
    sol += cntx[i];
    for (int j = 0; j < v[i].size(); j++)
      cnty[v[i][j].first] += v[i][j].second;
    for (int j = 0; j < k; j++) {
      sol += cnty[j];
      ans = max(ans, sol);
    }
    for (int j = 0; j < k; j++)
      sol -= cnty[j];
  }
}

int main() {
  // freopen("file.in","r",stdin);
  // freopen("file.out","w",stdout);
  char c;
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d %c\n", &vx[i], &vy[i], &c);
    if (c == 'W')
      t[i] = 0;
    else
      t[i] = 1;
  }
  solve(0);
  solve(1);
  printf("%d", ans);
  return 0;
}
Problem p03460 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#define debug(x) cout << #x << " = " << x << endl;
#define lowbit(x) x & (-x)
#define PA pair<int, int>
#define MK make_pair
using namespace std;
typedef long long LL;
inline int read() {
  int l = 0, f = 1;
  char a = getchar();
  for (; a < '0' || a > '9'; a = getchar())
    if (a == '-')
      f = -1;
  for (; a >= '0' && a <= '9'; a = getchar())
    l = l * 10 + a - 48;
  return l * f;
}
const int N = 1000005;
int n, k, num, ans, w[1005][1005];
int sum(int x1, int y1, int x2, int y2) {
  return w[x2][y2] - w[x1 - 1][y2] - w[x2][y1 - 1] + w[x1 - 1][y1 - 1];
}
int calc(int x, int y) {
  return sum(1, 1, x, y) + sum(x + 1, y + 1, x + k, y + k) +
         sum(x + k + 1, 1, 2 * k, y) + sum(1, y + k + 1, x, 2 * k) +
         sum(x + k + 1, y + k + 1, 2 * k, 2 * k);
}
int main(int argc, char const *argv[]) {
  n = read(), k = read();
  for (int i = 1; i <= n; ++i) {
    int x = read(), y = read();
    char a = getchar();
    while (a != 'W' && a != 'B')
      a = getchar();
    if (a == 'B')
      y += k;
    w[x % (2 * k) + 1][y % (2 * k) + 1]++;
  }
  for (int i = 1; i <= 2 * k; ++i) {
    for (int j = 1; j <= 2 * k; ++j)
      w[i][j] += w[i - 1][j] + w[i][j - 1] - w[i - 1][j - 1];
  }
  for (int i = 0; i < k; ++i)
    for (int j = 0; j < k; ++j)
      ans = max(ans, max(calc(i, j), n - calc(i, j)));
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#define debug(x) cout << #x << " = " << x << endl;
#define lowbit(x) x & (-x)
#define PA pair<int, int>
#define MK make_pair
using namespace std;
typedef long long LL;
inline int read() {
  int l = 0, f = 1;
  char a = getchar();
  for (; a < '0' || a > '9'; a = getchar())
    if (a == '-')
      f = -1;
  for (; a >= '0' && a <= '9'; a = getchar())
    l = l * 10 + a - 48;
  return l * f;
}
const int N = 1000005;
int n, k, num, ans, w[2005][2005];
int sum(int x1, int y1, int x2, int y2) {
  return w[x2][y2] - w[x1 - 1][y2] - w[x2][y1 - 1] + w[x1 - 1][y1 - 1];
}
int calc(int x, int y) {
  return sum(1, 1, x, y) + sum(x + 1, y + 1, x + k, y + k) +
         sum(x + k + 1, 1, 2 * k, y) + sum(1, y + k + 1, x, 2 * k) +
         sum(x + k + 1, y + k + 1, 2 * k, 2 * k);
}
int main(int argc, char const *argv[]) {
  n = read(), k = read();
  for (int i = 1; i <= n; ++i) {
    int x = read(), y = read();
    char a = getchar();
    while (a != 'W' && a != 'B')
      a = getchar();
    if (a == 'B')
      y += k;
    w[x % (2 * k) + 1][y % (2 * k) + 1]++;
  }
  for (int i = 1; i <= 2 * k; ++i) {
    for (int j = 1; j <= 2 * k; ++j)
      w[i][j] += w[i - 1][j] + w[i][j - 1] - w[i - 1][j - 1];
  }
  for (int i = 0; i < k; ++i)
    for (int j = 0; j < k; ++j)
      ans = max(ans, max(calc(i, j), n - calc(i, j)));
  printf("%d\n", ans);
  return 0;
}
Problem p03460 (C++)

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

typedef long long ll;

int n;
int k;
ll x[100010];
ll y[100010];

ll MOD = 1e9 + 7;

ll mod(ll num) { return (MOD + num) % MOD; }

ll sum[4010][4010];

int main() {
  cin >> n >> k;
  MOD = 2 * k;

  for (int i = 0; i < n; i++) {
    int a, b;
    char c;

    cin >> a >> b >> c;

    if (c == 'W')
      a += k;

    a++;
    b++;
    a = mod(a);
    b = mod(b);

    // 左下の黒のマスの位置だけ分かればよい
    sum[a][b]++;
    sum[a + 2 * k][b]++;
    sum[a + 2 * k][b + 2 * k]++;
    sum[a][b + 2 * k]++;
  }

  for (int i = 1; i < 4010; i++) {
    for (int j = 0; j < 4010; j++) {
      sum[i][j] += sum[i - 1][j];
    }
  }
  for (int i = 1; i < 4010; i++) {
    for (int j = 0; j < 4010; j++) {
      sum[j][i] += sum[j][i - 1];
    }
  }

  int ans = 0;

  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= 4000; j++) {
      // 斜めの黒いところを足す
      int value = sum[i + k][j + k] + sum[i][j] - sum[i][j + k] - sum[i + k][j];
      int value2 = sum[i + 2 * k][j + 2 * k] + sum[i + k][j + k] -
                   sum[i + k][j + 2 * k] - sum[i + 2 * k][j + k];
      ans = max(value + value2, ans);
    }
  }

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


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

typedef long long ll;

int n;
int k;
ll x[100010];
ll y[100010];

ll MOD = 1e9 + 7;

ll mod(ll num) { return (MOD + num) % MOD; }

ll sum[4010][4010];

int main() {
  cin >> n >> k;
  MOD = 2 * k;

  for (int i = 0; i < n; i++) {
    int a, b;
    char c;

    cin >> a >> b >> c;

    if (c == 'W')
      a += k;

    a++;
    b++;
    a = mod(a);
    b = mod(b);

    // 左下の黒のマスの位置だけ分かればよい
    sum[a][b]++;
    sum[a + 2 * k][b]++;
    sum[a + 2 * k][b + 2 * k]++;
    sum[a][b + 2 * k]++;
  }

  for (int i = 1; i < 4010; i++) {
    for (int j = 0; j < 4010; j++) {
      sum[i][j] += sum[i - 1][j];
    }
  }
  for (int i = 1; i < 4010; i++) {
    for (int j = 0; j < 4010; j++) {
      sum[j][i] += sum[j][i - 1];
    }
  }

  int ans = 0;

  for (int i = 0; i <= 2 * k; i++) {
    for (int j = 0; j <= 2 * k; j++) {
      // 斜めの黒いところを足す
      int value = sum[i + k][j + k] + sum[i][j] - sum[i][j + k] - sum[i + k][j];
      int value2 = sum[i + 2 * k][j + 2 * k] + sum[i + k][j + k] -
                   sum[i + k][j + 2 * k] - sum[i + 2 * k][j + k];
      ans = max(value + value2, ans);
    }
  }

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

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

using namespace std;

typedef long long int ll;

const ll INF = (ll)1e18;

int s[6000][6000];
int b[2000][2000];

int main() {
  int N, K;

  cin >> N >> K;

  REP(i, 6000) REP(j, 6000) s[i][j] = 0;
  REP(i, 2000) REP(j, 2000) b[i][j] = 0;

  REP(i, N) {
    ll x, y;
    char c;
    cin >> x >> y >> c;

    if (c == 'W')
      y += K;
    b[x % (2 * K)][y % (2 * K)] += 1;
  }
  REP(i, 2 * K) REP(j, 2 * K) {
    if (b[i][j] == 0)
      continue;

    REP(k, 2) REP(l, 2) {
      s[i + 1 + 2 * K * k][j + 1 + 2 * K * l] += b[i][j];
      s[i + K + 1 + 2 * K * k][j + K + 1 + 2 * K * l] += b[i][j];
      s[i + K + 1 + 2 * K * k][j + 1 + 2 * K * l] -= b[i][j];
      s[i + 1 + 2 * K * k][j + K + 1 + 2 * K * l] -= b[i][j];
    }
  }

  REP(i, 6000) FOR(j, 1, 6000) s[i][j] += s[i][j - 1];
  REP(i, 6000) FOR(j, 1, 6000) s[j][i] += s[j - 1][i];

  ll ans = 0;
  FOR(i, 1, 6000) FOR(j, 1, 6000) {
    ll tmp = 0;
    tmp += s[i][j];
    tmp += s[i + K][j + K];
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define MOD 1000000007

using namespace std;

typedef long long int ll;

const ll INF = (ll)1e18;

int s[6000][6000];
int b[2000][2000];

int main() {
  int N, K;

  cin >> N >> K;

  REP(i, 6000) REP(j, 6000) s[i][j] = 0;
  REP(i, 2000) REP(j, 2000) b[i][j] = 0;

  REP(i, N) {
    ll x, y;
    char c;
    cin >> x >> y >> c;

    if (c == 'W')
      y += K;
    b[x % (2 * K)][y % (2 * K)] += 1;
  }
  REP(i, 2 * K) REP(j, 2 * K) {
    if (b[i][j] == 0)
      continue;

    REP(k, 2) REP(l, 2) {
      s[i + 1 + 2 * K * k][j + 1 + 2 * K * l] += b[i][j];
      s[i + K + 1 + 2 * K * k][j + K + 1 + 2 * K * l] += b[i][j];
      s[i + K + 1 + 2 * K * k][j + 1 + 2 * K * l] -= b[i][j];
      s[i + 1 + 2 * K * k][j + K + 1 + 2 * K * l] -= b[i][j];
    }
  }

  REP(i, 6000) FOR(j, 1, 6000) s[i][j] += s[i][j - 1];
  REP(i, 6000) FOR(j, 1, 6000) s[j][i] += s[j - 1][i];

  ll ans = 0;
  FOR(i, 1, 5000) FOR(j, 1, 5000) {
    ll tmp = 0;
    tmp += s[i][j];
    tmp += s[i + K][j + K];
    ans = max(ans, tmp);
  }

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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a, b) memset(a, b, sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int, int>
#define PLL pair<LL, LL>
using namespace std;
const int N = 1e5 + 5;
const int M = 1e9 + 7;
const double eps = 1e-6;
// void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
// int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
// int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
// LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M,
// b>>1,M) : 1; }
int n, k;
int x[N], y[N];
char c[N];
int cnt[1005 * 2], ans;
int main() {
  Accel cin >> n >> k;
  int K = k * 2;
  REP(i, n) {
    int a, b;
    cin >> a >> b >> c[i];
    x[i] = a % K;
    y[i] = b % K;
  }
  REP(i, K) {
    Re(cnt, 0);
    int r = 0;
    REP(j, n) {
      int a = (x[j] - i + K) % K;
      a = (a < k);
      if (a ^ (y[j] < k))
        r += c[j] == 'B';
      else
        r += c[j] == 'W';
      cnt[y[j]] += (a ^ (c[j] == 'W')) ? 1 : -1;
    }
    REP(j, K) {
      ans = max(ans, r);
      r += cnt[j] - cnt[(j + k) % K];
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a, b) memset(a, b, sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int, int>
#define PLL pair<LL, LL>
using namespace std;
const int N = 1e5 + 5;
const int M = 1e9 + 7;
const double eps = 1e-6;
// void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
// int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
// int find(int x){return x==p[x]?x:p[x]=find(p[x]);}
// LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M,
// b>>1,M) : 1; }
int n, k;
int x[N], y[N];
char c[N];
int cnt[1005 * 2], ans;
int main() {
  Accel cin >> n >> k;
  int K = k * 2;
  REP(i, n) {
    int a, b;
    cin >> a >> b >> c[i];
    x[i] = a % K;
    y[i] = b % K;
  }
  REP(i, K) {
    Re(cnt, 0);
    int r = 0;
    REP(j, n) {
      // int a=(x[j]-i+K)%K;
      // a=(a<k);
      int a = ((x[j] - i < 0 ? x[j] - i + K : x[j] - i) < k);
      if (a ^ (y[j] < k))
        r += c[j] == 'B';
      else
        r += c[j] == 'W';
      cnt[y[j]] += (a ^ (c[j] == 'W')) ? 1 : -1;
    }
    REP(j, K) {
      ans = max(ans, r);
      r += cnt[j] - cnt[(j + k) % K];
    }
  }
  cout << ans << endl;
}
Problem p03460 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int x[100000], y[100000], x_mod_k[100000], x_div_k[100000];
char s[100000][2];
int cnt[100000];
int n, k;

void add(int x, int t) { //(x+??)/k%2=t
  if ((x_div_k[x] & 1) == 0) {
    if (t == 0) { // たさない
      cnt[0]++;
      cnt[k - x_mod_k[x]]--;
    } else { // たす
      cnt[k - x_mod_k[x]]++;
    }
  } else {
    if (t == 0) {
      cnt[k - x_mod_k[x]]++;
    } else {
      cnt[0]++;
      cnt[k - x_mod_k[x]]--;
    }
  }
}
signed main() {
  scanf("%d%d", &n, &k);
  rep(i, n) {
    scanf("%d%d%s", &x[i], &y[i], s[i]);
    x_mod_k[i] = y[i] % k;
    x_div_k[i] = y[i] / k;
  }
  int Max = 0;
  rep(i, k) {
    memset(cnt, 0, sizeof(cnt));
    rep(j, n) {
      if (s[j][0] == 'B') {
        if (((x[j] + i) / k) % 2 == 0) { //(y[j]+t)/K%2=0
          add(j, 0);
        } else {
          add(j, 1);
        }
      } else {
        if (((x[j] + i) / k) % 2 == 0) { //(y[j]+t)/K%2=1
          add(j, 1);
        } else {
          add(j, 0);
        }
      }
    }
    rep(j, k) {
      if (j)
        cnt[j] += cnt[j - 1];
      Max = max({Max, cnt[j], n - cnt[j]});
    }
  }
  cout << Max << endl;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4,avx")
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int x[100000], y[100000], x_mod_k[100000], x_div_k[100000];
char s[100000][2];
int cnt[100000];
int n, k;

void add(int x, int t) { //(x+??)/k%2=t
  if ((x_div_k[x] & 1) == 0) {
    if (t == 0) { // たさない
      cnt[0]++;
      cnt[k - x_mod_k[x]]--;
    } else { // たす
      cnt[k - x_mod_k[x]]++;
    }
  } else {
    if (t == 0) {
      cnt[k - x_mod_k[x]]++;
    } else {
      cnt[0]++;
      cnt[k - x_mod_k[x]]--;
    }
  }
}
signed main() {
  scanf("%d%d", &n, &k);
  rep(i, n) {
    scanf("%d%d%s", &x[i], &y[i], s[i]);
    x_mod_k[i] = y[i] % k;
    x_div_k[i] = y[i] / k;
  }
  int Max = 0;
  rep(i, k) {
    memset(cnt, 0, sizeof(cnt));
    rep(j, n) {
      if (s[j][0] == 'B') {
        if (((x[j] + i) / k) % 2 == 0) { //(y[j]+t)/K%2=0
          add(j, 0);
        } else {
          add(j, 1);
        }
      } else {
        if (((x[j] + i) / k) % 2 == 0) { //(y[j]+t)/K%2=1
          add(j, 1);
        } else {
          add(j, 0);
        }
      }
    }
    rep(j, k) {
      if (j)
        cnt[j] += cnt[j - 1];
      Max = max({Max, cnt[j], n - cnt[j]});
    }
  }
  cout << Max << endl;
}
Problem p03463 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define MAX 2000005
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "r", stdin);
#endif
  ll a, b, c;
  cin >> a >> b >> c;
  if ((b + c) % 2 == 0)
    cout << "Alice\n";
  else
    cout << "Borys\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define MAX 2000005
using namespace std;
int main() {

  ll a, b, c;
  cin >> a >> b >> c;
  if ((b + c) % 2 == 0)
    cout << "Alice\n";
  else
    cout << "Borys\n";

  return 0;
}
Problem p03463 (C++)

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define rrep(i, n) RFOR(i, n, 0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

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

  int p[1];
  p[0] = a;
  p[1] = b;

  int t = 0;

  // simulation
  while (!((abs(p[t] - p[t ^ 1]) == 1) && (p[t] == 1 || p[t] == n))) {
    if (abs(p[t] - p[t ^ 1]) == 1) {
      if (p[t] == p[t ^ 1] - 1) {
        // player is on the left cell of another
        // escape from another
        p[t]--;
        t ^= 1;
      } else {
        p[t]++;
        t ^= 1;
      }
    } else {

      if (p[t] < p[t ^ 1]) {
        // player is on the left cell of another
        // move close to another
        p[t]++;
        t ^= 1;
      } else {
        p[t]--;
        t ^= 1;
      }
    }
  }

  // player is on the edge
  cout << (t == 0 ? "Borys" : "Alice") << endl;
  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(i, 0, n)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define rrep(i, n) RFOR(i, n, 0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

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

  cout << ((a + b) % 2 == 0 ? "Alice" : "Borys") << endl;
}
Problem p03463 (C++)

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

int main() {
  int N, A, B;
  scanf("%d%d%d", &N, &A, &B);
  while (true) {
    if (A == 1 && B == 2) {
      puts("Borys");
      return 0;
    }
    if (A + 1 == B)
      --A;
    else
      ++A;
    if (A == N - 2 && B == N - 1) {
      puts("Alice");
      return 0;
    }
    if (A + 1 == B)
      ++B;
    else
      --B;
  }
  return 0;
}

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

int main() {
  int N, A, B;
  scanf("%d%d%d", &N, &A, &B);
  while (true) {
    if (A == 1 && B == 2) {
      puts("Borys");
      return 0;
    }
    if (A + 1 == B)
      --A;
    else
      ++A;
    if (A == N - 1 && B == N) {
      puts("Alice");
      return 0;
    }
    if (A + 1 == B)
      ++B;
    else
      --B;
  }
  return 0;
}
Problem p03464 (C++)

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

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

using namespace std;

int main() {
  ll k;
  cin >> k;
  vector<ll> a(k);
  rep(i, k) cin >> a[i];

  ll minn = 2;
  ll maxx = 2;

  for (ll i = k - 1; 0 <= i; i--) {
    ll x = minn;
    ll y = maxx;
    while (x % a[i] != 0)
      x++;
    while (y % a[i] != 0)
      y--;
    if (maxx < x || y < minn) {
      maxx = -1;
      break;
    }
    minn = x;
    maxx = y + (a[i] - 1);
  }

  if (maxx < minn)
    cout << "-1" << endl;
  else
    cout << minn << " " << maxx << endl;

  return 0;
}


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

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

using namespace std;

int main() {
  ll k;
  cin >> k;
  vector<ll> a(k);
  rep(i, k) cin >> a[i];

  ll minn = 2;
  ll maxx = 2;

  for (ll i = k - 1; 0 <= i; i--) {
    ll x = minn;
    ll y = maxx;
    if (x % a[i] != 0)
      x = (x / a[i]) * a[i] + a[i];
    if (y % a[i] != 0)
      y = (y / a[i]) * a[i];

    if (maxx < x || y < minn) {
      maxx = -1;
      break;
    }
    minn = x;
    maxx = y + (a[i] - 1);
  }

  if (maxx < minn)
    cout << "-1" << endl;
  else
    cout << minn << " " << maxx << endl;

  return 0;
}
Problem p03464 (C++)

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int K;
  cin >> K;
  ll A[K];
  rep(i, K) cin >> A[i];
  if (A[K - 1] == 2) {
    ll u, d, b1, b2;
    u = d = b1 = b2 = 2;
    for (int i = K - 1; i >= 0; i--) {
      u = b1 + A[i] - 1;
      d = b2;
      if (i == 0)
        break;
      bool ok = false;
      for (ll j = d; j <= u; j++) {
        if (j % A[i - 1] == 0)
          ok = true;
      }
      if (!ok) {
        cout << -1 << endl;
        return 0;
      }
      b1 = u - (u % A[i - 1]);
      if (d % A[i - 1] > 0)
        b2 = d + (A[i - 1] - (d % A[i - 1]));
      else
        b2 = d;
    }
    cout << d << " " << u << endl;
  } else
    cout << -1 << endl;
  return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int K;
  cin >> K;
  ll A[K];
  rep(i, K) cin >> A[i];
  if (A[K - 1] == 2) {
    ll u, d, b1, b2;
    u = d = b1 = b2 = 2;
    for (int i = K - 1; i >= 0; i--) {
      u = b1 + A[i] - 1;
      d = b2;
      if (i == 0)
        break;
      if (u - (u % A[i - 1]) < d) {
        cout << -1 << endl;
        return 0;
      }
      b1 = u - (u % A[i - 1]);
      if (d % A[i - 1] > 0)
        b2 = d + (A[i - 1] - (d % A[i - 1]));
      else
        b2 = d;
    }
    cout << d << " " << u << endl;
  } else
    cout << -1 << endl;
  return 0;
}
Problem p03464 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define maxk 100000
using namespace std;
int a[maxk + 10];
typedef long long LL;
int main() {
#ifndef ONLINE_JUDGE
  freopen("B.in", "r", stdin);
#endif
  int k;
  cin >> k;
  for (int i = 1; i <= k; i++)
    scanf("%d", a + i);
  LL k1 = 1, k2 = 2 / a[k];
  for (int i = k; i > 1; i--) {
    if (k1 > k2)
      break;
    k1 = k1 * a[i];
    k1 = k1 / a[i - 1] + 1 - (k1 % a[i - 1] == 0);
    k2 = (k2 + 1) * a[i];
    k2 = k2 / a[i - 1] - (k2 % a[i - 1] == 0);
  }
  if (k1 > k2)
    puts("-1");
  else
    printf("%lld %lld", k1 * a[1], (k2 + 1) * a[1] - 1);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define maxk 100000
using namespace std;
int a[maxk + 10];
typedef long long LL;
int main() {
  int k;
  cin >> k;
  for (int i = 1; i <= k; i++)
    scanf("%d", a + i);
  LL k1 = 1, k2 = 2 / a[k];
  for (int i = k; i > 1; i--) {
    if (k1 > k2)
      break;
    k1 = k1 * a[i];
    k1 = k1 / a[i - 1] + 1 - (k1 % a[i - 1] == 0);
    k2 = (k2 + 1) * a[i];
    k2 = k2 / a[i - 1] - (k2 % a[i - 1] == 0);
  }
  if (k1 > k2)
    puts("-1");
  else
    printf("%lld %lld", k1 * a[1], (k2 + 1) * a[1] - 1);
  return 0;
}
Problem p03464 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define SIZE 100005
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const int MAX = 2000000;
char maze[20][25];
int ans = 0, sx, sy, H, W;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int k;
ll A[10005];

int main() {
  ll L = 2ll, R = 2ll;
  cin >> k;
  for (int i = 0; i < k; i++)
    cin >> A[i];
  for (int i = k - 1; i >= 0; i--) {
    L = (L + A[i] - 1) / A[i] * A[i];
    R = R / A[i] * A[i] + A[i] - 1;
  }
  if (L > R)
    cout << "-1" << endl;
  else
    cout << L << " " << R << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define SIZE 100005
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const int MAX = 2000000;
char maze[20][25];
int ans = 0, sx, sy, H, W;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int k;
ll A[100005];

int main() {
  ll L = 2ll, R = 2ll;
  cin >> k;
  for (int i = 0; i < k; i++)
    cin >> A[i];
  for (int i = k - 1; i >= 0; i--) {
    L = (L + A[i] - 1) / A[i] * A[i];
    R = R / A[i] * A[i] + A[i] - 1;
  }
  if (L > R)
    cout << "-1" << endl;
  else
    cout << L << " " << R << endl;
  return 0;
}
Problem p03464 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define y1 cgbngfgn
#define pb push_back
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define fir first
#define m_p make_pair
#define sec second
#define files(name)                                                            \
  freopen(name ".in", "r", stdin);                                             \
  freopen(name ".out", "w", stdout);
#define time pdojegoritg
#define left eorgjrptgj
#define right rtyjtokh
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int arr = 3e5 + 100;

int a[arr];

signed main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  reverse(a + 1, a + 1 + n);

  int mn = 2;
  int mx = 2;
  for (int i = 1; i <= n; i++) {
    if (mx < a[i]) {
      cout << -1;
      return (0);
    }
    mx = (mx / a[i]) * a[i] + a[i] - 1;
    mn = mn / a[i] * a[i] + a[i] * (mn % a[i] != 0);
  }

  if (mn > mx) {
    exit(1);
  }

  cout << mn << ' ' << mx << '\n';
}
/*
 */


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define y1 cgbngfgn
#define pb push_back
#define fast                                                                   \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define fir first
#define m_p make_pair
#define sec second
#define files(name)                                                            \
  freopen(name ".in", "r", stdin);                                             \
  freopen(name ".out", "w", stdout);
#define time pdojegoritg
#define left eorgjrptgj
#define right rtyjtokh
#define int ll
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int arr = 3e5 + 100;

int a[arr];

signed main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> a[i];
  reverse(a + 1, a + 1 + n);

  int mn = 2;
  int mx = 2;
  for (int i = 1; i <= n; i++) {
    if (mx < a[i]) {
      cout << -1;
      return (0);
    }
    mx = (mx / a[i]) * a[i] + a[i] - 1;
    mn = mn / a[i] * a[i] + a[i] * (mn % a[i] != 0);
  }

  if (mn > mx) {
    cout << -1;
    return (0);
  }

  cout << mn << ' ' << mx << '\n';
}
/*
 */
Problem p03464 (C++)

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

const int MAXN = 2001;

ll a[MAXN];

int main() {
#ifdef PAUNSVOKNO
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(20);
  cout.tie(nullptr);
  cin.tie(nullptr);
  int n;
  cin >> n;

  ll cur = 2;

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  if (a[n - 1] != 2) {
    cout << -1 << "\n";
    return 0;
  }

  ll l = 2, r = 3;

  for (int i = n - 2; i >= 0; --i) {
    if (r / a[i] == (l - 1) / a[i]) {
      cout << -1 << "\n";
      return 0;
    }

    r = r / a[i] * a[i];
    l = ((l - 1) / a[i] + 1) * a[i];
    r += a[i] - 1;
  }

  cout << l << " " << r << "\n";
}

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

const int MAXN = 200001;

ll a[MAXN];

int main() {
#ifdef PAUNSVOKNO
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(20);
  cout.tie(nullptr);
  cin.tie(nullptr);
  int n;
  cin >> n;

  ll cur = 2;

  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  if (a[n - 1] != 2) {
    cout << -1 << "\n";
    return 0;
  }

  ll l = 2, r = 3;

  for (int i = n - 2; i >= 0; --i) {
    if (r / a[i] == (l - 1) / a[i]) {
      cout << -1 << "\n";
      return 0;
    }

    r = r / a[i] * a[i];
    l = ((l - 1) / a[i] + 1) * a[i];
    r += a[i] - 1;
  }

  cout << l << " " << r << "\n";
}
Problem p03464 (C++)

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

using namespace std;

long long k, a[100005], n1[100005], n2[100005];

int main() {
  cin >> k;
  for (int i = 1; i <= k; i++)
    cin >> a[i];
  n1[k + 1] = 2, n2[k + 1] = 2;
  for (int i = k; i >= 1; i--) {
    while (n1[i + 1] % a[i] != 0)
      n1[i + 1]++;
    while (n2[i + 1] % a[i] != 0)
      n2[i + 1]--;
    if (n1[i + 1] <= n2[i + 1])
      n1[i] = n1[i + 1], n2[i] = n2[i + 1] + a[i] - 1;
    else {
      cout << -1;
      return 0;
    }
  }
  cout << n1[1] << ' ' << n2[1];
}


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

using namespace std;

long long k, a[100005], n1[100005], n2[100005];

int main() {
  cin >> k;
  for (int i = 1; i <= k; i++)
    cin >> a[i];
  n1[k + 1] = 2, n2[k + 1] = 2;
  for (int i = k; i >= 1; i--) {
    if (n1[i + 1] % a[i] != 0)
      n1[i + 1] += a[i] - n1[i + 1] % a[i];
    n2[i + 1] -= n2[i + 1] % a[i];
    if (n1[i + 1] <= n2[i + 1])
      n1[i] = n1[i + 1], n2[i] = n2[i + 1] + a[i] - 1;
    else {
      cout << -1;
      return 0;
    }
  }
  cout << n1[1] << ' ' << n2[1];
}
Problem p03464 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int mx = 100005;
int k;
long long a[mx], maxn = 2, minn = 2;

int main() {
  scanf("%d", &k);
  for (int i = k - 1; i >= 0; i--)
    scanf("%lld", a + i);
  for (int i = 0; i < k; i++) {
    minn = (minn - 1) / a[i] * a[i] + a[i];
    maxn = maxn / a[i] * a[i] + a[i] - 1;
    if (minn > maxn)
      return puts("-1");
  }
  printf("%lld %lld\n", minn, maxn);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int mx = 100005;
int k;
long long a[mx], maxn = 2, minn = 2;

int main() {
  scanf("%d", &k);
  for (int i = k - 1; i >= 0; i--)
    scanf("%lld", a + i);
  for (int i = 0; i < k; i++) {
    minn = (minn - 1) / a[i] * a[i] + a[i];
    maxn = maxn / a[i] * a[i] + a[i] - 1;
    if (minn > maxn)
      return puts("-1") * 0;
  }
  printf("%lld %lld\n", minn, maxn);
}
Problem p03464 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize "O3"

#define F first
#define S second
#define ALL(x) x.begin(), x.end()

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

constexpr int N = 100000;

int k;
LL a[N];

int main() {
  scanf("%d", &k);
  for (int i = 0; i < k; ++i)
    scanf("%lld", a + i);
  LL lb = 2, rb = 2;
  for (int i = k - 1; i >= 1; --i) {
    assert(lb % a[i] == 0);
    assert(rb % a[i] == 0);
    lb = (lb / a[i]) * a[i] - 1;
    rb = (rb / a[i]) * a[i] + a[i] - 1;
    lb += (a[i - 1] - (lb % a[i - 1]));
    rb -= (rb % a[i - 1]);
    // cerr << lb << " " << rb << endl;
    // assert(lb <= rb);
    if (lb > rb) {
      puts("-1");
      return 0;
    }
  }
  printf("%lld %lld\n", lb, rb + a[0] - 1);
}


Fixed submission:
#pragma GCC optimize "O3"

#define F first
#define S second
#define ALL(x) x.begin(), x.end()

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

constexpr int N = 100000;

int k;
LL a[N];

int main() {
  scanf("%d", &k);
  for (int i = 0; i < k; ++i)
    scanf("%lld", a + i);
  if (a[k - 1] != 2) {
    puts("-1");
    return 0;
  }
  LL lb = 2, rb = 2;
  for (int i = k - 1; i >= 1; --i) {
    assert(lb % a[i] == 0);
    assert(rb % a[i] == 0);
    lb = (lb / a[i]) * a[i] - 1;
    rb = (rb / a[i]) * a[i] + a[i] - 1;
    lb += (a[i - 1] - (lb % a[i - 1]));
    rb -= (rb % a[i - 1]);
    // cerr << lb << " " << rb << endl;
    // assert(lb <= rb);
    if (lb > rb) {
      puts("-1");
      return 0;
    }
  }
  printf("%lld %lld\n", lb, rb + a[0] - 1);
}