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

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int n, par[100005];
int find(int x) {
  if (par[x] != x)
    par[x] = find(par[x]);
  return par[x];
}
bool Union(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return 0;
  par[x] = y;
  return 1;
}
void add(int x, int y) {
  if (Union(x, y))
    printf("%d %d\n", x, y);
}
void one(int x, int y) {
  add(x, y);
  add(y, 1);
  add(1, x + n);
  add(x + n, y + n);
}
void bits(int x) {
  int l = -1;
  for (int i = 0; i < 18; i++) {
    if (x & (1 << i)) {
      if (l == -1)
        add(x, (1 << i));
      else
        add((1 << l), (1 << i));
      l = i;
    }
  }
  add((1 << l), x + n);
}
int main() {
  scanf("%d", &n);
  if (!(n & (n - 1))) {
    printf("No");
    return 0;
  }
  printf("Yes\n");
  for (int i = 1; i <= 2 * n; i++)
    par[i] = i;
  add(1, 2);
  add(2, 3);
  add(3, n + 1);
  add(n + 1, n + 2);
  add(n + 2, n + 3);
  if (n % 4 == 0)
    bits(n);
  if (n % 4 == 1)
    one(n - 1, n);
  if (n % 4 == 2) {
    add(n - 1, 1);
    add(n, 3);
    add(n - 2, n);
    add(2 * n - 2, n + 1);
    add(2 * n - 1, 2 * n - 2);
    add(2 * n, 2 * n - 2);
  }
  for (int i = 4; i <= n - 3; i += 4) {
    add(i, i + 1);
    add(i + 1, i + 2);
    add(i + 2, i + 3);
    add(i + 3, n + i);
    add(n + i, n + i + 1);
    add(n + i + 1, n + i + 2);
    add(n + i + 2, n + i + 3);
    add(i, i - 4 + (i == 4));
  }
}

Fixed submission:
#include <iostream>
using namespace std;
int n, par[200005];
int find(int x) {
  if (par[x] != x)
    par[x] = find(par[x]);
  return par[x];
}
bool Union(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y)
    return 0;
  par[x] = y;
  return 1;
}
void add(int x, int y) {
  if (Union(x, y))
    printf("%d %d\n", x, y);
}
void one(int x, int y) {
  add(x, y);
  add(y, 1);
  add(1, x + n);
  add(x + n, y + n);
}
void bits(int x) {
  int l = -1;
  for (int i = 0; i < 18; i++) {
    if (x & (1 << i)) {
      if (l == -1)
        add(x, (1 << i));
      else
        add((1 << l), (1 << i));
      l = i;
    }
  }
  add((1 << l), x + n);
}
int main() {
  scanf("%d", &n);
  if (!(n & (n - 1))) {
    printf("No");
    return 0;
  }
  printf("Yes\n");
  for (int i = 1; i <= 2 * n; i++)
    par[i] = i;
  add(1, 2);
  add(2, 3);
  add(3, n + 1);
  add(n + 1, n + 2);
  add(n + 2, n + 3);
  if (n % 4 == 0)
    bits(n);
  if (n % 4 == 1)
    one(n - 1, n);
  if (n % 4 == 2) {
    add(n - 1, 1);
    add(n, 3);
    add(n - 2, n);
    add(2 * n - 2, n + 1);
    add(2 * n - 1, 2 * n - 2);
    add(2 * n, 2 * n - 2);
  }
  for (int i = 4; i <= n - 3; i += 4) {
    add(i, i + 1);
    add(i + 1, i + 2);
    add(i + 2, i + 3);
    add(i + 3, n + i);
    add(n + i, n + i + 1);
    add(n + i + 1, n + i + 2);
    add(n + i + 2, n + i + 3);
    add(i, i - 4 + (i == 4));
  }
}
Problem p02977 (C++)

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

int main() {
  int N;
  scanf("%d", &N);
  if (!(N & (N - 1)))
    return 1;
  puts("No");
}

Fixed submission:
#include <cstdio>

int main() {
  int N;
  scanf("%d", &N);
  if (!(N & (N - 1)))
    return puts("No"), 0;
  puts("Yes");
  printf("%d %d\n", N + 1, 3);
  for (int i = 2; i < N; i += 2)
    printf("%d %d\n%d %d\n%d %d\n%d %d\n", i + 1, i, i, 1, 1, N + i + 1,
           N + i + 1, N + i);
  if (N % 2 == 0)
    for (int i = 2; i < N; ++i)
      if ((i ^ N ^ 1) >= 2 && (i ^ N ^ 1) < N) {
        printf("%d %d\n%d %d\n", i % 2 == 0 ? i : N + i, N,
               (i ^ N ^ 1) % 2 == 0 ? i ^ N ^ 1 : N + (i ^ N ^ 1), 2 * N);
        break;
      }
  return 0;
}
Problem p02977 (C++)

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

#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

signed main() {
  int N;
  cin >> N;
  int a = 1;
  rep(i, 20) {
    if (N == a) {
      cout << "No" << endl;
      return 0;
    }
    a *= 2;
  }
  return 1;
}


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

#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

signed main() {
  int N;
  cin >> N;
  int a = 1;
  rep(i, 20) {
    if (N == a) {
      cout << "No" << endl;
      return 0;
    }
    a *= 2;
  }
  if (N % 2 == 1) {
    cout << "Yes" << endl;
    rep(i, N / 2) {
      int a = 2 * i + 2;
      int b = 2 * i + 3;
      cout << 1 << " " << a << endl;
      cout << a << " " << b << endl;
      cout << 1 << " " << b + N << endl;
      cout << b + N << " " << a + N << endl;
    }
    cout << 3 << " " << 1 + N << endl;
  } else {
    cout << "Yes" << endl;
    rep(i, (N - 1) / 2) {
      int a = 2 * i + 2;
      int b = 2 * i + 3;
      cout << 1 << " " << a << endl;
      cout << a << " " << b << endl;
      cout << 1 << " " << b + N << endl;
      cout << b + N << " " << a + N << endl;
    }
    cout << 3 << " " << 1 + N << endl;
    // Nと2Nの配置
    int n2 = N & -N;
    int n1 = N - n2;
    cout << n1 << " " << N << endl;
    cout << n2 + 1 + N << " " << 2 * N << endl;
  }
  return 0;
}
Problem p02977 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
const int N = 1e5 + 10;
int n, Low[N];
struct node {
  int x, y;
};
vector<node> g;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return
p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read() {
  int ret = 0, f = 0;
  char c = gc();
  while (!isdigit(c)) {
    if (c == '-')
      f = 1;
    c = gc();
  }
  while (isdigit(c)) {
    ret = ret * 10 + c - 48;
    c = gc();
  }
  if (f)
    return -ret;
  return ret;
}
signed main() {
  freopen("toad.in", "r", stdin);
  freopen("toad.out", "w", stdout);
  Low[0] = -1;
  for (int i = 1; i <= 100001; i++)
    Low[i] = Low[i / 2] + 1;
  n = read();
  if (n == 1) {
    puts("No");
    return 0;
  }
  if ((1 << Low[n]) == n) {
    puts("No");
    return 0;
  }
  puts("Yes");
  int m = 2;
  for (int i = m; i < n; i += 2) {
    g.push_back((node){1, i});
    g.push_back((node){i, i + 1});
    g.push_back((node){1, n + i + 1});
    g.push_back((node){n + i + 1, n + i});
  }
  g.push_back((node){3, n + 1});
  if (n % 2 == 0) {
    g.push_back((node){n, (1 << Low[n])});
    g.push_back((node){(n + n - (1 << Low[n])) ^ 1, n + n});
  }
  for (int i = 0; i < g.size(); i++)
    printf("%d %d\n", g[i].x, g[i].y);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define next Next
#define last Last
const int N = 1e5 + 10;
int n, Low[N];
struct node {
  int x, y;
};
vector<node> g;
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return
p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
#define gc getchar
inline int read() {
  int ret = 0, f = 0;
  char c = gc();
  while (!isdigit(c)) {
    if (c == '-')
      f = 1;
    c = gc();
  }
  while (isdigit(c)) {
    ret = ret * 10 + c - 48;
    c = gc();
  }
  if (f)
    return -ret;
  return ret;
}
signed main() {
  Low[0] = -1;
  for (int i = 1; i <= 100001; i++)
    Low[i] = Low[i / 2] + 1;
  n = read();
  if (n == 1) {
    puts("No");
    return 0;
  }
  if ((1 << Low[n]) == n) {
    puts("No");
    return 0;
  }
  puts("Yes");
  int m = 2;
  for (int i = m; i < n; i += 2) {
    g.push_back((node){1, i});
    g.push_back((node){i, i + 1});
    g.push_back((node){1, n + i + 1});
    g.push_back((node){n + i + 1, n + i});
  }
  g.push_back((node){3, n + 1});
  if (n % 2 == 0) {
    g.push_back((node){n, (1 << Low[n])});
    g.push_back((node){(n + n - (1 << Low[n])) ^ 1, n + n});
  }
  for (int i = 0; i < g.size(); i++)
    printf("%d %d\n", g[i].x, g[i].y);
  return 0;
}
Problem p02977 (C++)

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

using namespace std;

int n;

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  if (__builtin_popcount(n) == 1) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  cout << 1 << ' ' << 2 << endl;
  cout << 2 << ' ' << 3 << endl;
  cout << 3 << ' ' << n + 1 << endl;
  cout << n + 1 << ' ' << n + 2 << endl;
  cout << n + 2 << ' ' << n + 3 << endl;
  for (int i = 4; i < n; i += 2) {
    cout << n + 1 << ' ' << i << endl;
    cout << n + 1 << ' ' << i + n + 1 << endl;
    cout << i << ' ' << i + 1 << endl;
    cout << i + n + 1 << ' ' << i + n << endl;
  }
  if (n % 2 == 0) {
    return 1;
    cout << 3 << ' ' << n << endl;
    int to = (n ^ 3 ^ 1);
    if (to & 1)
      to += n;
    cout << 2 * n << ' ' << to << endl;
  }
  return 0;
}


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

using namespace std;

int n;

int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  if (__builtin_popcount(n) == 1) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  cout << 1 << ' ' << 2 << endl;
  cout << 2 << ' ' << 3 << endl;
  cout << 3 << ' ' << n + 1 << endl;
  cout << n + 1 << ' ' << n + 2 << endl;
  cout << n + 2 << ' ' << n + 3 << endl;
  for (int i = 4; i < n; i += 2) {
    cout << n + 1 << ' ' << i << endl;
    cout << n + 1 << ' ' << i + n + 1 << endl;
    cout << i << ' ' << i + 1 << endl;
    cout << i + n + 1 << ' ' << i + n << endl;
  }
  if (n % 2 == 0) {
    for (int i = 2; i <= n; i++) {
      int u = (i == 2 || i % 2 == 1) ? i + n : i;
      if ((n ^ i ^ 1) < n) {
        int v = ((n ^ i ^ 1) == 2 || (n ^ i ^ 1) % 2 == 1) ? (n ^ i ^ 1) + n
                                                           : (n ^ i ^ 1);
        cout << u << ' ' << n << endl;
        cout << 2 * n << ' ' << v << endl;
        break;
      }
    }
  }
  return 0;
}
Problem p02977 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int mod = 1000000007;
typedef long long LL;
int n, m, u[N], v[N], du[N], a[N];
set<int> G[N];
set<pair<int, int>> s;
pair<int, int> ans[N];
int main() {
#ifdef TEST
  freopen("input.txt", "r", stdin);
#endif
  scanf("%d", &n);
  int fst = 1;
  while (fst < n)
    fst <<= 1;
  if (fst == n) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  printf("1 2\n2 3\n3 %d\n", n + 1);
  printf("%d 1\n%d %d\n", n + 3, n + 3, n + 2);
  if (n & 1) {
    for (int i = 4; i <= n; i += 2) {
      printf("%d %d\n", n + i, n + i + 1);
      printf("%d %d\n", n + i + 1, 3);
      printf("%d %d\n", i, 2);
      printf("%d %d\n", i + 1, i);
    }
  } else {
    int t = n;
    fst = fst >> 1;
    vector<int> q;
    while (t) {
      if (n >= fst) {
        q.push_back(fst);
        t -= fst;
      }
      fst >>= 1;
    }
    reverse(q.begin(), q.end());
    int head = q[0] == 2;
    for (int i = 4; i < n; i += 2) {
      if (head < q.size() && q[head] == i) {
        int pre = head == 0 ? 2 : q[head - 1];
        printf("%d %d\n", pre, i);
        printf("%d %d\n", i, i + 1);
        printf("%d %d\n", pre + 1, n + i + 1);
        printf("%d %d\n", n + i + 1, n + i);
        head++;
      } else {
        printf("%d %d\n", n + i, n + i + 1);
        printf("%d %d\n", n + i + 1, 3);
        printf("%d %d\n", i, 2);
        printf("%d %d\n", i + 1, i);
      }
    }
    printf("%d %d\n", q[0], n);
    printf("%d %d\n", q[head - 1], n + n);
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int mod = 1000000007;
typedef long long LL;
int n, m, u[N], v[N], du[N], a[N];
set<int> G[N];
set<pair<int, int>> s;
pair<int, int> ans[N];
int main() {
#ifdef TEST
  freopen("input.txt", "r", stdin);
#endif
  scanf("%d", &n);
  int fst = 1;
  while (fst < n)
    fst <<= 1;
  if (fst == n) {
    printf("No\n");
    return 0;
  }
  printf("Yes\n");
  printf("1 2\n2 3\n3 %d\n", n + 1);
  printf("%d 1\n%d %d\n", n + 3, n + 3, n + 2);
  if (n & 1) {
    for (int i = 4; i <= n; i += 2) {
      printf("%d %d\n", n + i, n + i + 1);
      printf("%d %d\n", n + i + 1, 3);
      printf("%d %d\n", i, 2);
      printf("%d %d\n", i + 1, i);
    }
  } else {
    int t = n;
    fst = fst >> 1;
    vector<int> q;
    while (t) {
      if (t >= fst) {
        q.push_back(fst);
        t -= fst;
      }
      fst >>= 1;
    }
    reverse(q.begin(), q.end());
    int head = q[0] == 2;
    for (int i = 4; i < n; i += 2) {
      if (head < q.size() && q[head] == i) {
        int pre = head == 0 ? 2 : q[head - 1];
        printf("%d %d\n", pre, i);
        printf("%d %d\n", i, i + 1);
        printf("%d %d\n", pre + 1, n + i + 1);
        printf("%d %d\n", n + i + 1, n + i);
        head++;
      } else {
        printf("%d %d\n", n + i, n + i + 1);
        printf("%d %d\n", n + i + 1, 3);
        printf("%d %d\n", i, 2);
        printf("%d %d\n", i + 1, i);
      }
    }
    printf("%d %d\n", q[0], n);
    printf("%d %d\n", q[head - 1], n + n);
  }
  return 0;
}
Problem p02977 (C++)

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

int main() {
  using namespace std;
  size_t N;
  cin >> N;
  if (__builtin_popcountll(N) == 1)
    return 0 & puts("No");
  puts("Yes\n1 2");
  for (unsigned long i = 2; i < N; i += 2)
    cout << i << " " << i + 1 << "\n"
         << i + 1 << " " << N + 1 << "\n"
         << N + 1 << " " << N + i << "\n"
         << N + i << " " << N + i + 1 << endl;
  if (~N & 1) {
    assert(0);
    cout << N << " " << N + 2 << "\n" << (3 ^ N) << " " << 2 * N << endl;
  }
  return 0;
}

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

int main() {
  using namespace std;
  size_t N;
  cin >> N;
  if (__builtin_popcountll(N) == 1)
    return 0 & puts("No");
  puts("Yes\n1 2");
  for (unsigned long i = 2; i < N; i += 2)
    cout << i << " " << i + 1 << "\n"
         << i + 1 << " " << N + 1 << "\n"
         << N + 1 << " " << N + i << "\n"
         << N + i << " " << N + i + 1 << endl;
  if (N % 2 == 0)
    cout << N << " " << N + (N & -N) << "\n"
         << ((N & -N) ^ 1 ^ N) << " " << 2 * N << endl;
  return 0;
}
Problem p02977 (C++)

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

#define ll long long
#define fornum(A, B, C) for (A = B; A < C; A++)
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, n;
vector<pll> vn;
ll mk[100], mk2;
pll ab[100];
pll ans[101010];
ll ans2;
ll i, j;

int main() {
  scanf("%lld", &N);
  if (N == 3) {
    printf("Yes\n1 2\n2 3\n3 4\n4 5\n5 6\n");
    return 0;
  }
  for (n = 1; n <= N; n *= 2)
    ;
  n /= 2;
  if (N == n) {
    printf("No");
    return 0;
  }
  ans2 = 0;
  fornum(i, 1, n - 1) {
    ans[ans2++] = {i, i + 1};
    ans[ans2++] = {i + N, i + N + 1};
  }
  ans[ans2++] = {n - 1, N + 1};
  if (N % 2 == 1) {
    fornum(i, n, N + 1) {
      ans[ans2++] = {i, i + 1};
      ans[ans2++] = {i + 1, 1};
      ans[ans2++] = {1, N + i};
      ans[ans2++] = {N + i, N + i + 1};
      i++;
    }
  } else {
    ll a = N & (n - 1);
    fornum(i, n, N) {
      ans[ans2++] = {i + 1, i};
      ans[ans2++] = {i, a};
      ans[ans2++] = {a + 1, N + i + 1};
      ans[ans2++] = {N + i + 1, N + i};
      i++;
    }
    ans[ans2++] = {N, n};
    ans[ans2++] = {a, N * 2};
  }
  printf("Yes\n");
  fornum(i, 0, ans2) { printf("%lld %lld\n", ans[i].first, ans[i].second); }

  return 0;
}

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

#define ll long long
#define fornum(A, B, C) for (A = B; A < C; A++)
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, n;
pll ans[202020];
ll ans2;
ll i, j;

int main() {
  scanf("%lld", &N);
  if (N == 3) {
    printf("Yes\n1 2\n2 3\n3 4\n4 5\n5 6\n");
    return 0;
  }
  for (n = 1; n <= N; n *= 2)
    ;
  n /= 2;
  if (N == n) {
    printf("No");
    return 0;
  }
  ans2 = 0;
  fornum(i, 1, n - 1) {
    ans[ans2++] = {i, i + 1};
    ans[ans2++] = {i + N, i + N + 1};
  }
  ans[ans2++] = {n - 1, N + 1};
  if (N % 2 == 1) {
    fornum(i, n, N + 1) {
      ans[ans2++] = {i, i + 1};
      ans[ans2++] = {i + 1, 1};
      ans[ans2++] = {1, N + i};
      ans[ans2++] = {N + i, N + i + 1};
      i++;
    }
  } else {
    ll a = N & (n - 1);
    fornum(i, n, N) {
      ans[ans2++] = {i + 1, i};
      ans[ans2++] = {i, a};
      ans[ans2++] = {a + 1, N + i + 1};
      ans[ans2++] = {N + i + 1, N + i};
      i++;
    }
    ans[ans2++] = {N, n};
    ans[ans2++] = {a, N * 2};
  }
  printf("Yes\n");
  fornum(i, 0, ans2) { printf("%lld %lld\n", ans[i].first, ans[i].second); }

  return 0;
}
Problem p02977 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;
// #define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int gcd(int x, int y) { return (!y ? x : gcd(y, x % y)); }
const int maxn = 1e5 + 10;
vi adj[maxn];
void ad_e(int u, int v) { adj[u].push_back(v); }
int32_t main() {
  IOS;
  int n;
  cin >> n;
  if (__builtin_popcount(n) == 1) {
    cout << "No\n";
    return 0;
  }
  int m = (n % 2 == 0 ? n - 1 : n);
  int st = 1;
  ad_e(1 + n, 2 + n), ad_e(2 + n, 3), ad_e(3, 1);
  ad_e(1, 2), ad_e(2, 3 + n);

  for (int i = 4; i <= m; i++) {
    ad_e(st, i);
    ad_e(i, (i ^ 1) + n);
  }
  if (m != n) {
    for (int u = 2; u <= m; u++) {
      int v = n ^ 1 ^ u;
      if (v != u && v <= m) {
        ad_e(v, n);
        ad_e(u, 2 * n);
        break;
      }
    }
  }
  cout << "Yes\n";
  for (int i = 1; i <= 2 * n; i++)
    for (auto j : adj[i]) {
      cout << i << " " << j << endl;
    }
}


Fixed submission:
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;
// #define int long long
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
#define X first
#define Y second
#define all(o) o.begin(), o.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0), cin.tie(0)

int gcd(int x, int y) { return (!y ? x : gcd(y, x % y)); }
const int maxn = 1e6 + 10;
vi adj[maxn];
void ad_e(int u, int v) { adj[u].push_back(v); }
int32_t main() {
  IOS;
  int n;
  cin >> n;
  if (__builtin_popcount(n) == 1) {
    cout << "No\n";
    return 0;
  }
  int m = (n % 2 == 0 ? n - 1 : n);
  int st = 1;
  ad_e(1 + n, 2 + n), ad_e(2 + n, 3), ad_e(3, 1);
  ad_e(1, 2), ad_e(2, 3 + n);

  for (int i = 4; i <= m; i++) {
    ad_e(st, i);
    ad_e(i, (i ^ 1) + n);
  }
  if (m != n) {
    for (int u = 2; u <= m; u++) {
      int v = n ^ 1 ^ u;
      if (v != u && v <= m) {
        ad_e(v, n);
        ad_e(u, 2 * n);
        break;
      }
    }
  }
  cout << "Yes\n";
  for (int i = 1; i <= 2 * n; i++)
    for (auto j : adj[i]) {
      cout << i << " " << j << endl;
    }
}
Problem p02977 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
const int MAXN = 100005;
int N, Root = 1;
vector<int> P[MAXN];
int main() {
  // freopen("tree.in","r",stdin);
  // freopen("tree.out","w",stdout);
  scanf("%d", &N);
  if (int(log2(N)) == log2(N)) {
    printf("No\n");
    return 0;
  }
  P[1].push_back(2);
  P[2].push_back(3);
  P[3].push_back(1 + N);
  P[1 + N].push_back(2 + N);
  P[2 + N].push_back(3 + N);
  for (int i = 4; i < N; i += 2) {
    P[Root].push_back(i);
    P[Root].push_back(i + N + 1);
    P[i].push_back(i + 1);
    P[i + N + 1].push_back(i + N);
  }
  if (N % 2 == 0) {
    int ed = N, f = 0, Sum = 0;
    for (int i = 25; i >= 0; i--)
      if (ed & (1 << i))
        f = (1 << i), Sum += f;
    int t1, t2;
    t1 = f, t2 = Sum - t1 + N + 1;
    P[ed].push_back(t1);
    P[ed + N].push_back(t2);
  }
  printf("Yes\n");
  for (int i = 1; i <= 2 * N; i++) {
    int size = P[i].size();
    for (int j = 0; j < size; j++)
      printf("%d %d\n", i, P[i][j]);
  }
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
const int MAXN = 200005;
int N, Root = 1;
vector<int> P[MAXN];
int main() {
  // freopen("tree.in","r",stdin);
  // freopen("tree.out","w",stdout);
  scanf("%d", &N);
  if (int(log2(N)) == log2(N)) {
    printf("No\n");
    return 0;
  }
  P[1].push_back(2);
  P[2].push_back(3);
  P[3].push_back(1 + N);
  P[1 + N].push_back(2 + N);
  P[2 + N].push_back(3 + N);
  for (int i = 4; i < N; i += 2) {
    P[Root].push_back(i);
    P[Root].push_back(i + N + 1);
    P[i].push_back(i + 1);
    P[i + N + 1].push_back(i + N);
  }
  if (N % 2 == 0) {
    int ed = N, f = 0, Sum = 0;
    for (int i = 25; i >= 0; i--)
      if (ed & (1 << i))
        f = (1 << i), Sum += f;
    int t1, t2;
    t1 = f, t2 = Sum - t1 + N + 1;
    P[ed].push_back(t1);
    P[ed + N].push_back(t2);
  }
  printf("Yes\n");
  for (int i = 1; i <= 2 * N; i++) {
    int size = P[i].size();
    for (int j = 0; j < size; j++)
      printf("%d %d\n", i, P[i][j]);
  }
}
Problem p02978 (C++)

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (auto &a : A)
    cin >> a;
  function<int64_t(vector<int64_t>)> dfs = [&](vector<int64_t> A) {
    if (A.size() == 2)
      return A[0] + A[1];
    int64_t ret = numeric_limits<int64_t>::max();
    for (int i = 1; i <= A.size() - 2; i++) {
      vector<int64_t> AA;
      for (int j = 0; j < A.size(); j++) {
        if (j != i)
          AA.push_back(A[j]);
      }
      AA[i - 1] += A[i];
      AA[i] += A[i];
      ret = min(ret, dfs(AA));
    }
    return ret;
  };
  cout << dfs(A) << endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (auto &a : A)
    cin >> a;
  function<int64_t(int64_t, int64_t, int64_t, int64_t)> rec =
      [&](int64_t l, int64_t r, int64_t lx, int64_t rx) {
        if (r - l == 1)
          return int64_t(0);
        int64_t ret = numeric_limits<int64_t>::max();
        for (int k = l + 1; k < r; k++) {
          ret = min(ret, rec(l, k, lx, lx + rx) + rec(k, r, lx + rx, rx) +
                             A[k] * (lx + rx));
        }
        return ret;
      };
  cout << rec(0, N - 1, 1, 1) + A[0] + A[N - 1] << endl;
  return 0;
}
Problem p02978 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
const int N = 25;
const long long INF = 4557430888798830399;
int n;
int a[N];
map<pair<int, int>, long long> f[N][N];
long long dfs(int l, int r, int p, int q) {
  if (l > r)
    return 0;
  if (f[l][r][{p, q}])
    return f[l][r][{p, q}];
  long long res = INF;
  for (int i = l; i <= r; i++)
    res = min(res, dfs(l, i - 1, p, p + q) + dfs(i + 1, r, p + q, q) +
                       1LL * (p + q) * a[i]);
  return f[l][r][{p, q}] = res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  printf("%lld", dfs(2, n - 1, 1, 1) + a[1] + a[n]);
  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
const int N = 25;
const long long INF = 4557430888798830399;
int n;
int a[N];
map<pair<int, int>, long long> f[N][N];
long long dfs(int l, int r, int p, int q) {
  if (l > r)
    return 0;
  if (f[l][r].count({p, q}))
    return f[l][r][{p, q}];
  long long res = INF;
  for (int i = l; i <= r; i++)
    res = min(res, dfs(l, i - 1, p, p + q) + dfs(i + 1, r, p + q, q) +
                       1LL * (p + q) * a[i]);
  return f[l][r][{p, q}] = res;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++)
    scanf("%d", &a[i]);
  printf("%lld", dfs(2, n - 1, 1, 1) + a[1] + a[n]);
  return 0;
}
Problem p02978 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
template <class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {
  return b < a ? (a = b, true) : false;
}
template <class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {
  return a < b ? (a = b, true) : false;
}
template <class Type> Type read() {
  Type a;
  bool b;
  unsigned char c;
  while (c = getchar() - 48, (c > 9) & (c != 253))
    ;
  for (a = (b = c == 253) ? 0 : c; (c = getchar() - 48) <= 9; a = a * 10 + c)
    ;
  return b ? -a : a;
}
auto rd = read<int>;

int n, a[19], l[1 << 16], r[1 << 16], u[1 << 16], v[1 << 16];
long long f[1 << 16][19][19];
int main() {
  n = rd();
  for (int i = 1; i <= n; ++i)
    a[i] = rd();
  if (n == 2) {
    printf("%d\n", a[1] + a[n]);
    return 0;
  }
  u[1] = v[1] = l[1] = 1;
  r[1] = n;
  for (int i = 1; i < 1 << (n - 3); ++i) {
    u[i << 1] = u[i];
    v[i << 1] = u[i << 1 | 1] = u[i] + v[i];
    v[i << 1 | 1] = v[i];
    l[i << 1] = l[i], r[i << 1] = r[i] - 1;
    l[i << 1 | 1] = l[i] + 1, r[i << 1 | 1] = r[i];
  }
  for (int x = 1 << (n - 2); --x;) {
    for (int i = l[x]; i <= r[x]; ++i)
      for (int j = i + 2; j <= r[x]; ++j)
        f[x][i][j] = 4e18;
    for (int i = l[x]; i < r[x]; ++i)
      for (int j = i + 1; j < r[x]; ++j)
        for (int k = j + 1; k <= r[x]; ++k)
          cmin(f[x][i][k], f[x << 1][i][j] + f[x << 1 | 1][j][k] +
                               (long long)(u[x] + v[x]) * a[j]);
  }
  printf("%lld\n", a[1] + a[n] + f[1][1][n]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
template <class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {
  return b < a ? (a = b, true) : false;
}
template <class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {
  return a < b ? (a = b, true) : false;
}
template <class Type> Type read() {
  Type a;
  bool b;
  unsigned char c;
  while (c = getchar() - 48, (c > 9) & (c != 253))
    ;
  for (a = (b = c == 253) ? 0 : c; (c = getchar() - 48) <= 9; a = a * 10 + c)
    ;
  return b ? -a : a;
}
auto rd = read<int>;

int n, a[19], l[1 << 16], r[1 << 16], u[1 << 16], v[1 << 16];
long long f[1 << 17][19][19];
int main() {
  n = rd();
  for (int i = 1; i <= n; ++i)
    a[i] = rd();
  if (n == 2) {
    printf("%d\n", a[1] + a[n]);
    return 0;
  }
  u[1] = v[1] = l[1] = 1;
  r[1] = n;
  for (int i = 1; i < 1 << (n - 3); ++i) {
    u[i << 1] = u[i];
    v[i << 1] = u[i << 1 | 1] = u[i] + v[i];
    v[i << 1 | 1] = v[i];
    l[i << 1] = l[i], r[i << 1] = r[i] - 1;
    l[i << 1 | 1] = l[i] + 1, r[i << 1 | 1] = r[i];
  }
  for (int x = 1 << (n - 2); --x;) {
    for (int i = l[x]; i <= r[x]; ++i)
      for (int j = i + 2; j <= r[x]; ++j)
        f[x][i][j] = 4e18;
    for (int i = l[x]; i < r[x]; ++i)
      for (int j = i + 1; j < r[x]; ++j)
        for (int k = j + 1; k <= r[x]; ++k)
          cmin(f[x][i][k], f[x << 1][i][j] + f[x << 1 | 1][j][k] +
                               (long long)(u[x] + v[x]) * a[j]);
  }
  printf("%lld\n", a[1] + a[n] + f[1][1][n]);
  return 0;
}
Problem p02978 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, A[18];
vector<pair<ll, ll>> DP[18][18];
ll RES;

vector<pair<ll, ll>> f(int l, int r) {
  if (DP[l][r].empty()) {
    vector<pair<ll, ll>> v;
    for (int i = l + 1; i <= r - 1; ++i) {
      vector<pair<ll, ll>> L = f(l, i);
      vector<pair<ll, ll>> R = f(i, r);
      for (int j = 0; j < L.size(); ++j) {
        for (int k = 0; k < R.size(); ++k) {
          v.push_back(mkp(L[j].first + L[j].second + R[k].first - A[i],
                          L[j].second + R[k].first - A[i] + R[k].second));
        }
      }
    }
    for (int i = 0; i < v.size(); ++i) {
      bool f = true;
      for (int j = 0; j < v.size(); ++j) {
        if (v[i].first > v[j].first && v[i].second > v[j].second) {
          f = false;
          break;
        }
      }
      if (f) {
        DP[l][r].push_back(v[i]);
      }
    }
  }
  return DP[l][r];
}

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N - 1; ++i) {
    DP[i][i + 1].push_back(mkp(A[i], A[i + 1]));
  }
  vector<pair<ll, ll>> res = f(0, N - 1);
  RES = llmax;
  for (pair<ll, ll> p : res) {
    RES = min(RES, p.first + p.second);
  }
  cout << RES << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, A[18];
vector<pair<ll, ll>> DP[18][18];
ll RES;

vector<pair<ll, ll>> f(int l, int r) {
  if (DP[l][r].empty()) {
    vector<pair<ll, ll>> v;
    for (int i = l + 1; i <= r - 1; ++i) {
      vector<pair<ll, ll>> L = f(l, i);
      vector<pair<ll, ll>> R = f(i, r);
      for (int j = 0; j < L.size(); ++j) {
        for (int k = 0; k < R.size(); ++k) {
          v.push_back(mkp(L[j].first + L[j].second + R[k].first - A[i],
                          L[j].second + R[k].first - A[i] + R[k].second));
        }
      }
    }
    for (int i = 0; i < v.size(); ++i) {
      bool f = true;
      for (int j = 0; j < v.size(); ++j) {
        if (v[i].first > v[j].first && v[i].second > v[j].second ||
            (v[i] == v[j] && i < j)) {
          f = false;
          break;
        }
      }
      if (f) {
        DP[l][r].push_back(v[i]);
      }
    }
  }
  return DP[l][r];
}

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int i = 0; i < N - 1; ++i) {
    DP[i][i + 1].push_back(mkp(A[i], A[i + 1]));
  }
  vector<pair<ll, ll>> res = f(0, N - 1);
  RES = llmax;
  for (pair<ll, ll> p : res) {
    RES = min(RES, p.first + p.second);
  }
  cout << RES << endl;
}
Problem p02979 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#define RI register int
#define CI const int &
using namespace std;
const int N = 150;
int n, k, mod;
inline void inc(int &x, CI y) {
  if ((x += y) >= mod)
    x -= mod;
}
namespace Case1 // Even number solver
{
int f[N][N];
inline int calc(CI n, CI k) {
  RI i, j;
  for (f[0][0] = i = 1; i <= n; ++i)
    for (f[i][0] = f[i - 1][0], j = 1; j <= k; ++j)
      inc(f[i][0], f[i - 1][j]), f[i][j] = f[i - 1][j - 1];
  int ret = 0;
  for (i = 0; i <= k; ++i)
    inc(ret, f[n][i]);
  return ret;
}
inline void solve(void) {
  printf("%d", 1LL * calc(n >> 1, k >> 1) * calc(n - (n >> 1), k >> 1) % mod);
}
};              // namespace Case1
namespace Case2 // Odd number solver
{
int f[N][N][N], ans;
inline void solve(void) {
  RI i, j, p;
  for (f[0][0][0] = i = 1; i <= n; ++i) {
    int r = i << 1, l = r - k, fl = 1 <= l && l <= n, fr = 1 <= r && r <= n;
    for (j = 0; j <= n; ++j)
      for (p = 0; p <= k + 1; ++p) {
        inc(f[i][0][0], f[i - 1][j][p]);
        if (fr)
          inc(f[i][j + 1][0], f[i - 1][j][p]);
        if (fl && p + 1 < k + 2)
          inc(f[i][0][p ? p + 1 : p], f[i - 1][j][p]);
        if (fl && fr && max(j + 2, p + 1) < k + 2)
          inc(f[i][j + 1][max(j + 2, p + 1)], f[i - 1][j][p]);
      }
  }
  for (i = 0; i <= n; ++i)
    for (j = 0; j <= k + 1; ++j)
      inc(ans, f[n][i][j]);
  printf("%d", ans);
}
}; // namespace Case2
int main() {
  scanf("%d%d%d", &n, &k, &mod);
  if (k & 1)
    Case2::solve();
  else
    Case1::solve();
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#define RI register int
#define CI const int &
using namespace std;
const int N = 155;
int n, k, mod;
inline void inc(int &x, CI y) {
  if ((x += y) >= mod)
    x -= mod;
}
namespace Case1 // Even number solver
{
int f[N][N];
inline int calc(CI n, CI k) {
  RI i, j;
  for (f[0][0] = i = 1; i <= n; ++i)
    for (f[i][0] = f[i - 1][0], j = 1; j <= k; ++j)
      inc(f[i][0], f[i - 1][j]), f[i][j] = f[i - 1][j - 1];
  int ret = 0;
  for (i = 0; i <= k; ++i)
    inc(ret, f[n][i]);
  return ret;
}
inline void solve(void) {
  printf("%d", 1LL * calc(n >> 1, k >> 1) * calc(n - (n >> 1), k >> 1) % mod);
}
};              // namespace Case1
namespace Case2 // Odd number solver
{
int f[N][N][N], ans;
inline void solve(void) {
  RI i, j, p;
  for (f[0][0][0] = i = 1; i <= n; ++i) {
    int r = i << 1, l = r - k, fl = 1 <= l && l <= n, fr = 1 <= r && r <= n;
    for (j = 0; j <= n; ++j)
      for (p = 0; p <= k + 1; ++p) {
        inc(f[i][0][0], f[i - 1][j][p]);
        if (fr)
          inc(f[i][j + 1][0], f[i - 1][j][p]);
        if (fl && p + 1 < k + 2)
          inc(f[i][0][p ? p + 1 : p], f[i - 1][j][p]);
        if (fl && fr && max(j + 2, p + 1) < k + 2)
          inc(f[i][j + 1][max(j + 2, p + 1)], f[i - 1][j][p]);
      }
  }
  for (i = 0; i <= n; ++i)
    for (j = 0; j <= k + 1; ++j)
      inc(ans, f[n][i][j]);
  printf("%d", ans);
}
}; // namespace Case2
int main() {
  scanf("%d%d%d", &n, &k, &mod);
  if (k & 1)
    Case2::solve();
  else
    Case1::solve();
  return 0;
}
Problem p02980 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
const int mo = 998244353, N = 1e5 + 5;
int ksm(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = ans * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return ans;
}
int fac[N], inv[N], f[N];

int C(int a, int b) { return fac[a] * inv[b] % mo * inv[a - b] % mo; }
signed main() {
  int n, m, ans = 0;
  scanf("%lld%lld", &n, &m);
  fac[0] = 1;
  for (int i = 1; i < N; ++i)
    fac[i] = (fac[i - 1] * i) % mo;
  inv[N - 1] = ksm(fac[N - 1], mo - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mo;
  if (n > m)
    std::swap(n, m);
  for (int i = 0; i <= n; ++i)
    f[i] = C(n, i) * C(m, i) % mo * fac[i] % mo * ksm(n + 1, m - i) % mo *
           ksm(m + 1, n - i) % mo;
  for (int i = 0; i <= n; ++i)
    ans = ((ans + (1 - ((i & 1) << 1)) * f[i]) % mo + mo) % mo;
  printf("%lld\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
const int mo = 998244353, N = 1e6 + 5;
int ksm(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1)
      ans = ans * a % mo;
    a = a * a % mo;
    b >>= 1;
  }
  return ans;
}
int fac[N], inv[N], f[N];

int C(int a, int b) { return fac[a] * inv[b] % mo * inv[a - b] % mo; }
signed main() {
  int n, m, ans = 0;
  scanf("%lld%lld", &n, &m);
  fac[0] = 1;
  for (int i = 1; i < N; ++i)
    fac[i] = (fac[i - 1] * i) % mo;
  inv[N - 1] = ksm(fac[N - 1], mo - 2);
  for (int i = N - 2; i >= 0; i--)
    inv[i] = (inv[i + 1] * (i + 1)) % mo;
  if (n > m)
    std::swap(n, m);
  for (int i = 0; i <= n; ++i)
    f[i] = C(n, i) * C(m, i) % mo * fac[i] % mo * ksm(n + 1, m - i) % mo *
           ksm(m + 1, n - i) % mo;
  for (int i = 0; i <= n; ++i)
    ans = ((ans + (1 - ((i & 1) << 1)) * f[i]) % mo + mo) % mo;
  printf("%lld\n", ans);
}
Problem p02981 (C++)

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

int main() {
  int n, a, b;

  scanf("%d %d %d", &n, &a, &b);

  if (n * a > b) {
    printf("%d", b);
  } else {
    printf("%d", a * n);
  }

  return b;
}


Fixed submission:
#include <stdio.h>
#include <stdlib.h>

int main() {
  int n, a, b;

  scanf("%d %d %d", &n, &a, &b);

  if (n * a > b) {
    printf("%d", b);
  } else {
    printf("%d", a * n);
  }

  return 0;
}
Problem p02981 (Python)

Buggy submission (status: Runtime Error):
N, A, B = map(int, input().split())
ans = []
for i in range(1, N):
    ans.append(A * i + B / N * (N - i))
print(min(ans))


Fixed submission:
N, A, B = map(int, input().split())
if A * N < B:
    print(A * N)
else:
    print(B)
Problem p02981 (C++)

Buggy submission (status: Runtime Error):
/*ربى اصلح لى شأنى*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define el '\n';
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long fact(long long n) { return !n ? 1 : n * fact(n - 1); }
using namespace std;
const double PI = acos(-1);
/* smile ^_^ */
using lli = long long int;
using namespace std;
void ezzo() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
int main() {
  ezzo();
  lli n, a, b;
  cin >> n >> a >> b;
  if ((a * n) > b) {
    cout << b << el;
  } else {
    cout << (a * n) << el;
  }
  // memset(a, 0, sizeof a);//تصفير الاراى
  // cout << fixed << setprecision(9) << a << el;
}

Fixed submission:
/*ربى اصلح لى شأنى*/
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define el '\n';
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long fact(long long n) { return !n ? 1 : n * fact(n - 1); }
using namespace std;
const double PI = acos(-1);
/* smile ^_^ */
using lli = long long int;
using namespace std;
void ezzo() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
int main() {
  ezzo();
  lli n, a, b;
  cin >> n >> a >> b;
  if ((a * n) > b) {
    cout << b << el;
  } else {
    cout << (a * n) << el;
  }
  // memset(a, 0, sizeof a);//تصفير الاراى
  // cout << fixed << setprecision(9) << a << el;
}
Problem p02981 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>

#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main() {

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

  return min(n * a, b);
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>

#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main() {

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

  cout << min(n * a, b) << endl;
}
Problem p02981 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  int N, A, B;
  scanf("%d %d %d", N, A, B);
  if (A * N >= B)
    printf("%d", B);
  else
    printf("%d", A * N);
  return 0;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int N, A, B;
  scanf("%d %d %d", &N, &A, &B);
  if (A * N >= B)
    printf("%d", B);
  else
    printf("%d", A * N);
  return 0;
}
Problem p02981 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int N, A, B;
  scanf("%d%d%d", N, A, B);
  if (N * A <= B)
    printf("%d\n", N * A);
  else
    printf("%d\n", B);
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int N, A, B;
  scanf("%d%d%d", &N, &A, &B);
  if (N * A <= B)
    printf("%d\n", N * A);
  else
    printf("%d\n", B);
  return 0;
}
Problem p02981 (C++)

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  return min(a * b, c);
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(a * b, c) << endl;
}
Problem p02981 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
using namespace std;
int main() {
  int N, A, B;
  int sc = scanf("%d %d %d", &N, &A, &B);
  return A * N < B ? A * N : B;
}

Fixed submission:
#include <stdio.h>
using namespace std;
int main() {
  int N, A, B;
  int sc = scanf("%d %d %d", &N, &A, &B);
  printf("%d\n", A * N < B ? A * N : B);
}
Problem p02981 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main(void) {
  int n, a, b, c, d;
  scanf("%d", &n);
  scanf("%d", &a);
  scanf("%d", &b);
  d = n * a;
  if (d > b) {
    c = b;
  } else {
    c = d;
  }
  printf("%d\n", c);
  return 9;
}

Fixed submission:
#include <stdio.h>
int main(void) {
  int n, a, b, c, d;
  scanf("%d", &n);
  scanf("%d", &a);
  scanf("%d", &b);
  d = n * a;
  if (d > b) {
    c = b;
  } else {
    c = d;
  }
  printf("%d\n", c);
  return 0;
}
Problem p02981 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

using namespace std;

#define PI 3.14159265
#define OO 1e9
#define SS second
#define FF first
#define Trace(n) cout << #n << " = " << n << endl;
#define ll long long
#define endl "\n"

//@formatter:off
int dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[] = {-1, 1, 0, 0, 1, -1, 1, -1};

void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}
//@formatter:on

int main() {
  fast();
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(a * b, c);
}


Fixed submission:
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

using namespace std;

#define PI 3.14159265
#define OO 1e9
#define SS second
#define FF first
#define Trace(n) cout << #n << " = " << n << endl;
#define ll long long
#define endl "\n"

//@formatter:off
int dx[] = {0, 0, -1, 1, 1, 1, -1, -1};
int dy[] = {-1, 1, 0, 0, 1, -1, 1, -1};

void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
//@formatter:on

int main() {
  fast();
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(a * b, c);
}
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <assert.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char const *argv[]) {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(4));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> x.at(i).at(j);
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      double result = 0;
      for (int k = 0; k < d; k++) {
        if (x.at(i).at(k) - x.at(j).at(k) != 0) {
          result += pow(x.at(i).at(k) - x.at(j).at(k), 2.0);
        }
      }
      result = sqrt(result);
      if (ceil(result) == result)
        count++;
    }
  }
  cout << count;

  return 0;
}

Fixed submission:
#include <assert.h>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(int argc, char const *argv[]) {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> x.at(i).at(j);
    }
  }
  int count = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      double result = 0;
      for (int k = 0; k < d; k++) {
        if (x.at(i).at(k) - x.at(j).at(k) != 0) {
          result += pow(x.at(i).at(k) - x.at(j).at(k), 2.0);
        }
      }
      result = sqrt(result);
      if (ceil(result) == result)
        count++;
    }
  }
  cout << count;

  return 0;
}
Problem p02982 (C++)

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

int main() {

  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> X[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int norm = 0;
      for (int k = 0; k < D; k++) {
        int diff = abs(X[i][k] - X[j][k]);
        norm += diff * diff;
      }

      bool flag = false;
      for (int k = 0; k <= norm; k++) {
        if (k * k == norm)
          flag = true;
      }
      if (flag)
        ans++;
    }
  }
  cout << ans << endl;
}

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

int main() {

  int N, D;
  cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> X[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      int norm = 0;
      for (int k = 0; k < D; k++) {
        int diff = abs(X[i][k] - X[j][k]);
        norm += diff * diff;
      }

      bool flag = false;
      for (int k = 0; k <= norm; k++) {
        if (k * k == norm)
          flag = true;
      }
      if (flag)
        ans++;
    }
  }
  cout << ans << endl;
}
Problem p02982 (C++)

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<double>> Vec(N, vector<double>(4));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> Vec.at(i).at(j);
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      double DisDbl = 0;
      for (int k = 0; k < D; k++) {
        DisDbl += pow(Vec.at(i).at(k) - Vec.at(j).at(k), 2.0);
      }
      int DisDblDwn = pow(DisDbl, 0.5);
      if (DisDbl == DisDblDwn * DisDblDwn) {
        count++;
      }
    }
  }
  cout << count << endl;
}

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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<double>> Vec(N, vector<double>(D));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < D; j++) {
      cin >> Vec.at(i).at(j);
    }
  }
  int count = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      double DisDbl = 0;
      for (int k = 0; k < D; k++) {
        DisDbl += pow(Vec.at(i).at(k) - Vec.at(j).at(k), 2.0);
      }
      int DisDblDwn = pow(DisDbl, 0.5);
      if (DisDbl == DisDblDwn * DisDblDwn) {
        count++;
      }
    }
  }
  cout << count << endl;
}
Problem p02982 (Python)

Buggy submission (status: Runtime Error):
N, D = map(int, input().split())
X = list(map(int, input().split()))
count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        r = 0
        for k in range(D):
            r += (X[i][k] - X[j][k]) ** 2
        if r**0.5 % 1 == 0:
            count += 1
print(count)


Fixed submission:
N, D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]
count = 0
for i in range(N - 1):
    for j in range(i + 1, N):
        r = 0
        for k in range(D):
            r += (X[i][k] - X[j][k]) ** 2
        if r**0.5 % 1 == 0:
            count += 1
print(count)
Problem p02982 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9 + 7;
const ll INF = 0x3f3f3f3f;

int a[11][11];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
  freopen("A.txt", "r", stdin);
#endif
  int n, r, ans = 0;
  cin >> n >> r;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= r; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int x = 1; i + x <= n; x++) {
      double d = 0;
      for (int j = 1; j <= r; j++) {
        d += (a[i + x][j] - a[i][j]) * (a[i + x][j] - a[i][j]);
      }
      if (sqrt(d) == floor(sqrt(d)))
        ans++;
    }
  }
  cout << ans;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)1e9 + 7;
const ll INF = 0x3f3f3f3f;

int a[11][11];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
#ifndef ONLINE_JUDGE
// freopen("A.txt", "r", stdin);
#endif
  int n, r, ans = 0;
  cin >> n >> r;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= r; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int x = 1; i + x <= n; x++) {
      double d = 0;
      for (int j = 1; j <= r; j++) {
        d += (a[i + x][j] - a[i][j]) * (a[i + x][j] - a[i][j]);
      }
      if (sqrt(d) == floor(sqrt(d)))
        ans++;
    }
  }
  cout << ans;
}