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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 123456;
vector<int> ans[MAXN];

int main() {
  int n;
  scanf("%d", &n);
  int tmp = n * 2;
  int k = sqrt(tmp);
  if (k * (k + 1) != tmp)
    return puts("87");
  printf("Yes\n%d\n", k);
  int cur = 1;
  for (int i = 1; i <= k + 1; i++) {
    printf("%d ", k);
    int cnt = 0;
    for (int j = 1; j < i; j++) {
      printf("%d ", ans[j].back());
      ans[j].pop_back();
      cnt++;
    }
    for (int j = 0; j < k - cnt; j++) {
      printf("%d ", cur);
      ans[i].push_back(cur++);
    }
    puts("");
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 123456;
vector<int> ans[MAXN];

int main() {
  int n;
  scanf("%d", &n);
  int tmp = n * 2;
  int k = sqrt(tmp);
  if (k * (k + 1) != tmp)
    return !printf("No\n");
  printf("Yes\n%d\n", k + 1);
  int cur = 1;
  for (int i = 1; i <= k + 1; i++) {
    printf("%d ", k);
    int cnt = 0;
    for (int j = 1; j < i; j++) {
      printf("%d ", ans[j].back());
      ans[j].pop_back();
      cnt++;
    }
    for (int j = 0; j < k - cnt; j++) {
      printf("%d ", cur);
      ans[i].push_back(cur++);
    }
    puts("");
  }

  return 0;
}
Problem p03224 (C++)

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

template <typename Tp> inline void getint(Tp &num) {
  register int ch, neg = 0;
  while (!isdigit(ch = getchar()))
    if (ch == '-')
      neg = 1;
  num = ch & 15;
  while (isdigit(ch = getchar()))
    num = num * 10 + (ch & 15);
  if (neg)
    num = -num;
}

int N, k;
vector<int> S[320];

int main() {
  getint(N), k = (int)sqrt((N << 3) + 1.0) + 1 >> 1;
  if (k * (k - 1) != N << 1)
    return puts("No"), 0;
  for (register int i = 1, cur = 0; i <= k; i++)
    for (register int j = i + 1; j <= k; j++)
      S[i].push_back(++cur), S[j].push_back(cur);
  puts("Yes"), printf("%d\n", k);
  for (register int i = 1, siz; i <= k; i++, puts("")) {
    printf("%d ", siz = S[i].size());
    for (register int j = 0; j < siz; j++)
      printf("%d ", S[i][j]);
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

template <typename Tp> inline void getint(Tp &num) {
  register int ch, neg = 0;
  while (!isdigit(ch = getchar()))
    if (ch == '-')
      neg = 1;
  num = ch & 15;
  while (isdigit(ch = getchar()))
    num = num * 10 + (ch & 15);
  if (neg)
    num = -num;
}

int N, k;
vector<int> S[450];

int main() {
  getint(N), k = (int)sqrt((N << 3) + 1.0) + 1 >> 1;
  if (k * (k - 1) != N << 1)
    return puts("No"), 0;
  for (register int i = 1, cur = 0; i <= k; i++)
    for (register int j = i + 1; j <= k; j++)
      S[i].push_back(++cur), S[j].push_back(cur);
  puts("Yes"), printf("%d\n", k);
  for (register int i = 1, siz; i <= k; i++, puts("")) {
    printf("%d ", siz = S[i].size());
    for (register int j = 0; j < siz; j++)
      printf("%d ", S[i][j]);
  }
  return 0;
}
Problem p03224 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P2;
#define fi first
#define sese cond
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

map<int, int> st;

signed main() {
  int x = 1;
  for (int i = 2; i <= 100000; i++) {
    st[x] = i - 1;
    x += i;
  }
  int n;
  cin >> n;

  if (!st.count(n)) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  cout << st[n] + 1 << endl;

  int a = st[n];

  int ans[a][a + 1], cnt = 1;

  for (int i = a, k = 0; i >= 1; i--, k++) {
    for (int j = 0; j < i; j++) {
      ans[k][j + k] = cnt;
      ans[k + j + 1][k] = cnt;
      cnt++;
    }
  }
  r(i, a + 1) {
    cout << a;
    r(j, a) {
      cout << ' ';
      cout << ans[i][j];
    }
    cout << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P2;
#define fi first
#define sese cond
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};

map<int, int> st;

signed main() {
  int x = 1;
  for (int i = 2; i <= 100000; i++) {
    st[x] = i - 1;
    x += i;
  }
  int n;
  cin >> n;

  if (!st.count(n)) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  cout << st[n] + 1 << endl;

  int a = st[n];

  int ans[a + 1][a], cnt = 1;

  for (int i = a, k = 0; i >= 1; i--, k++) {
    for (int j = 0; j < i; j++) {
      ans[k][j + k] = cnt;
      ans[k + j + 1][k] = cnt;
      cnt++;
    }
  }
  r(i, a + 1) {
    cout << a;
    r(j, a) {
      cout << ' ';
      cout << ans[i][j];
    }
    cout << endl;
  }
}
Problem p03224 (C++)

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

int a[400][400];

int main() {
  int n;
  scanf("%d", &n);
  int id = -1;
  for (int i = 1; i * (i + 1) / 2 <= n; i++) {
    if (n == i * (i + 1) / 2) {
      id = i;
      break;
    }
  }
  if (id == -1)
    return 0 * puts("No");
  puts("Yes");
  printf("%d\n", id + 1);
  int s = 0;
  for (int i = 1; i <= id + 1; i++) {
    printf("%d ", id);
    for (int j = 1; j < i; j++) {
      a[i][j] = a[j][i - 1];
    }
    for (int j = i; j <= id; j++)
      a[i][j] = ++s;
    for (int j = 1; j <= id; j++)
      printf("%d ", a[i][j]);
    puts("");
  }
  return 0;
}

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

int a[1000][1000];

int main() {
  int n;
  scanf("%d", &n);
  int id = -1;
  for (int i = 1; i * (i + 1) / 2 <= n; i++) {
    if (n == i * (i + 1) / 2) {
      id = i;
      break;
    }
  }
  if (id == -1)
    return 0 * puts("No");
  puts("Yes");
  printf("%d\n", id + 1);
  int s = 0;
  for (int i = 1; i <= id + 1; i++) {
    printf("%d ", id);
    for (int j = 1; j < i; j++) {
      a[i][j] = a[j][i - 1];
    }
    for (int j = i; j <= id; j++)
      a[i][j] = ++s;
    for (int j = 1; j <= id; j++)
      printf("%d ", a[i][j]);
    puts("");
  }
  return 0;
}
Problem p03224 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
int n, m, i, j, x;
std::vector<int> v[999];
int main() {
  scanf("%d", &n);
  m = (1 + sqrt(1 + 8 * n)) / 2;
  if (m * (m - 1) / 2 != n)
    return puts("No");
  for (i = 1; i < m; ++i)
    for (j = i + 1; j <= m; ++j)
      ++x, v[i].push_back(x), v[j].push_back(x);
  printf("Yes\n%d\n", m);
  for (i = 1; i <= m; ++i)
    for (int x : v[printf("%d ", m - 1), i])
      printf("%d%c", x, x == v[i].back() ? '\n' : ' ');
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
int n, m, i, j, x;
std::vector<int> v[999];
int main() {
  scanf("%d", &n);
  m = (1 + sqrt(1 + 8 * n)) / 2;
  if (m * (m - 1) / 2 != n)
    return puts("No"), 0;
  for (i = 1; i < m; ++i)
    for (j = i + 1; j <= m; ++j)
      ++x, v[i].push_back(x), v[j].push_back(x);
  printf("Yes\n%d\n", m);
  for (i = 1; i <= m; ++i)
    for (int x : v[printf("%d ", m - 1), i])
      printf("%d%c", x, x == v[i].back() ? '\n' : ' ');
  return 0;
}
Problem p03224 (C++)

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

using namespace std;

int d[350][350];

void solve() {
  int n;
  cin >> n;
  int k = 1;
  auto c2 = [](int x) { return x * (x - 1) / 2; };
  while (c2(k) < n) {
    k++;
  }
  if (c2(k) != n) {
    cout << "No";
    return;
  }
  int edge_cnt = 1;
  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++) {
      d[i][j] = d[j][i] = edge_cnt++;
    }
  }

  cout << "Yes\n";
  cout << k << "\n";
  for (int i = 0; i < k; i++) {
    cout << (k - 1) << ' ';
    for (int j = 0; j < k; j++) {
      if (i != j) {
        cout << d[i][j] << ' ';
      }
    }
    cout << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  cout << endl;
}


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

using namespace std;

int d[450][450];

void solve() {
  int n;
  cin >> n;
  int k = 1;
  auto c2 = [](int x) { return x * (x - 1) / 2; };
  while (c2(k) < n) {
    k++;
  }
  if (c2(k) != n) {
    cout << "No";
    return;
  }
  int edge_cnt = 1;
  for (int i = 0; i < k; i++) {
    for (int j = i + 1; j < k; j++) {
      d[i][j] = d[j][i] = edge_cnt++;
    }
  }

  cout << "Yes\n";
  cout << k << "\n";
  for (int i = 0; i < k; i++) {
    cout << (k - 1) << ' ';
    for (int j = 0; j < k; j++) {
      if (i != j) {
        cout << d[i][j] << ' ';
      }
    }
    cout << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  cout << endl;
}
Problem p03224 (C++)

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

using namespace std;
#define int long long
/*                      */ // #undef int
#define INF 1000000009ll
#define INFL 1000000000000000018ll
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<pair<int, PA>, vector<pair<int, PA>>,
                       greater<pair<int, PA>>>
    PQG;

int N;
vector<int> V[1000];

signed main() {
  cin >> N;
  if (N == 1)
    return 1;
  bool flag = true;
  int res;
  int ans;
  for (int i = 2; i * (i + 1) / 2 <= N; i++) {
    if (i * (i + 1) / 2 == N) {
      res = i;
      ans = i;
      flag = false;
    }
  }
  if (flag) {
    printf("No\n");
    return 0;
  } else {
    printf("Yes\n");
  }
  int in1 = 0, in2 = 1;
  for (int i = 1; i <= N; i++) {
    V[in1].pb(i);
    V[in2 + in1].pb(i);
    if (in2 % res == 0) {
      res--;
      in1++;
      in2 = 1;
    } else
      in2++;
  }
  printf("%lld\n", ans + 1);
  for (int i = 0; i <= ans; i++) {
    printf("%lld ", (int)V[i].size());
    for (int j = 0; j < (int)V[i].size(); j++) {
      printf("%lld", V[i][j]);
      if (j < (int)V[i].size() - 1) {
        printf(" ");
      }
    }
    printf("\n");
  }

  return 0;
}
/*



*/


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

using namespace std;
#define int long long
/*                      */ // #undef int
#define INF 1000000009ll
#define INFL 1000000000000000018ll
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<pair<int, PA>, vector<pair<int, PA>>,
                       greater<pair<int, PA>>>
    PQG;

int N;
vector<int> V[1000];

signed main() {
  cin >> N;
  if (N == 1) {
    printf("Yes\n2\n1 1\n1 1\n");
    return 0;
  }
  bool flag = true;
  int res;
  int ans;
  for (int i = 2; i * (i + 1) / 2 <= N; i++) {
    if (i * (i + 1) / 2 == N) {
      res = i;
      ans = i;
      flag = false;
    }
  }
  if (flag) {
    printf("No\n");
    return 0;
  } else {
    printf("Yes\n");
  }
  int in1 = 0, in2 = 1;
  for (int i = 1; i <= N; i++) {
    V[in1].pb(i);
    V[in2 + in1].pb(i);
    if (in2 % res == 0) {
      res--;
      in1++;
      in2 = 1;
    } else
      in2++;
  }
  printf("%lld\n", ans + 1);
  for (int i = 0; i <= ans; i++) {
    printf("%lld ", (int)V[i].size());
    for (int j = 0; j < (int)V[i].size(); j++) {
      printf("%lld", V[i][j]);
      if (j < (int)V[i].size() - 1) {
        printf(" ");
      }
    }
    printf("\n");
  }

  return 0;
}
/*



*/
Problem p03224 (C++)

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

const int maxN = 1e5 + 10;
int a[maxN];
int b[maxN];
int c[maxN];
vector<int> w[maxN];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= 1000; i++) {
    int k = (i) * (i - 1) / 2;
    b[k] = 1;
    c[k] = i;
  }
  if (b[n] != 1) {
    puts("No");
    return 0;
  } else {
    puts("Yes");
    printf("%d\n", c[n]);
    int cnt = 0;
    for (int i = 1; i < c[n]; i++) {
      for (int j = i + 1; j <= c[n]; j++) {
        cnt++;
        w[i].push_back(cnt);
        w[j].push_back(cnt);
      }
    }
    for (int i = 1; i <= c[n]; i++) {
      int sz = w[i].size();
      printf("%d ", sz);
      for (int j = 0; j < w[i].size() - 1; j++) {
        printf("%d ", w[i][j]);
      }
      printf("%d\n", w[i][sz - 1]);
    }
  }
  return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;

const int maxN = 1e5 + 10;
int a[maxN];
int b[10 * maxN];
int c[10 * maxN];
vector<int> w[maxN];
int n;
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= 1000; i++) {
    int k = (i) * (i - 1) / 2;
    b[k] = 1;
    c[k] = i;
  }
  if (b[n] != 1) {
    puts("No");
    return 0;
  } else {
    puts("Yes");
    printf("%d\n", c[n]);
    int cnt = 0;
    for (int i = 1; i < c[n]; i++) {
      for (int j = i + 1; j <= c[n]; j++) {
        cnt++;
        w[i].push_back(cnt);
        w[j].push_back(cnt);
      }
    }
    for (int i = 1; i <= c[n]; i++) {
      int sz = w[i].size();
      printf("%d ", sz);
      for (int j = 0; j < w[i].size() - 1; j++) {
        printf("%d ", w[i][j]);
      }
      printf("%d\n", w[i][sz - 1]);
    }
  }
  return 0;
}
Problem p03224 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second

const int mx = 200010;
const ll mod = 1e9 + 7;

#define bit(n, k) ((n >> k) & 1) //*n no k bit me 1 or 0*/

int main() {
  int n;
  cin >> n;
  rep(i, 1000) {
    int res = i * (i - 1) / 2;
    if (n != res)
      continue;
    cout << "Yes" << endl;
    cout << i << endl;
    vector<int> v[n];
    int cnt = 1;
    rep(j, i) REP(k, j + 1, i) {
      v[j].emplace_back(cnt);
      v[k].emplace_back(cnt);
      cnt++;
    }
    rep(j, i) {
      cout << v[j].size() << " ";
      for (auto it : v[j])
        cout << it << " ";
      cout << endl;
    }
    return 0;
  }

  cout << "No" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second

const int mx = 200010;
const ll mod = 1e9 + 7;

#define bit(n, k) ((n >> k) & 1) //*n no k bit me 1 or 0*/

int main() {
  int n;
  cin >> n;
  rep(i, 1000) {
    int res = i * (i - 1) / 2;
    if (n != res)
      continue;
    cout << "Yes" << endl;
    cout << i << endl;
    vector<int> v[i];
    int cnt = 1;
    rep(j, i) REP(k, j + 1, i) {
      v[j].emplace_back(cnt);
      v[k].emplace_back(cnt);
      cnt++;
    }
    rep(j, i) {
      cout << v[j].size() << " ";
      for (auto it : v[j])
        cout << it << " ";
      cout << endl;
    }
    return 0;
  }

  cout << "No" << endl;
  return 0;
}
Problem p03224 (C++)

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

using namespace std;
typedef long long ll;
const int MAX_K = 1e3;

int main() {
  int N;
  scanf("%d", &N);
  int k = 0;
  for (int res = 1; res <= MAX_K; res++) {
    if ((res * (res + 1)) / 2 == N) {
      k = res;
      break;
    }
  }

  if (k == 0) {
    printf("%s\n", "No");
    return 0;
  }

  vector<int> vec[k + 1];
  int cnt = 0;

  for (int i = 2; i <= k - 1; i++) {
    // 上から何段目スタートか
    for (int h = i * (i - 1) / 2 + 1; h <= i * (i + 1) / 2; h++) {
      vec[cnt].push_back(h);
    }
    int w = i * (i + 1) / 2;
    for (int times = 0; i + times < k; times++) {
      w += i + times;
      vec[cnt].push_back(w);
    }
    cnt++;
  }

  for (int s = 0; s < k; s++) {
    vec[cnt].push_back(((s * (s + 1)) / 2) + 1);
  }

  cnt++;

  for (int t = (k * (k - 1)) / 2 + 1; t <= k * (k + 1) / 2; t++) {
    vec[cnt].push_back(t);
  }

  cnt++;

  for (int u = 1; u <= k; u++) {
    vec[cnt].push_back((u * (u + 1)) / 2);
  }

  printf("%s\n", "Yes");
  printf("%d\n", k + 1);

  for (int i = 0; i <= k; i++) {
    printf("%d ", (int)vec[i].size());
    for (auto n : vec[i]) {
      printf("%d ", n);
    }
    printf("\n");
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
const int MAX_K = 1e3;

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

  if (N == 1) {
    printf("%s\n", "Yes");
    printf("%d\n", 2);
    printf("%d %d\n", 1, 1);
    printf("%d %d\n", 1, 1);
    return 0;
  }

  int k = 0;
  for (int res = 1; res <= MAX_K; res++) {
    if ((res * (res + 1)) / 2 == N) {
      k = res;
      break;
    }
  }

  if (k == 0) {
    printf("%s\n", "No");
    return 0;
  }

  vector<int> vec[k + 1];
  int cnt = 0;

  for (int i = 2; i <= k - 1; i++) {
    // 上から何段目スタートか
    for (int h = i * (i - 1) / 2 + 1; h <= i * (i + 1) / 2; h++) {
      vec[cnt].push_back(h);
    }
    int w = i * (i + 1) / 2;
    for (int times = 0; i + times < k; times++) {
      w += i + times;
      vec[cnt].push_back(w);
    }
    cnt++;
  }

  for (int s = 0; s < k; s++) {
    vec[cnt].push_back(((s * (s + 1)) / 2) + 1);
  }

  cnt++;

  for (int t = (k * (k - 1)) / 2 + 1; t <= k * (k + 1) / 2; t++) {
    vec[cnt].push_back(t);
  }

  cnt++;

  for (int u = 1; u <= k; u++) {
    vec[cnt].push_back((u * (u + 1)) / 2);
  }

  printf("%s\n", "Yes");
  printf("%d\n", k + 1);

  for (int i = 0; i <= k; i++) {
    printf("%d ", (int)vec[i].size());
    for (auto n : vec[i]) {
      printf("%d ", n);
    }
    printf("\n");
  }

  return 0;
}
Problem p03225 (C++)

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

#include <algorithm>

using namespace std;

#define NMAX 310
#define BMAX (NMAX * 3 + 6)

typedef long long i64;

static int n, m;
static char map[NMAX + 10][NMAX + 10];
static int pre[3 * NMAX + 10][3 * NMAX + 10];

#define S(i, j) pre[NMAX + (i)][NMAX + (j)]

void show() {
  for (int i = 1; i <= n; i++)
    printf("%s\n", map[i] + 1);
  puts("");
}

void rotate() {
  static char buf[NMAX + 10][NMAX + 10];
  memcpy(buf, map, sizeof(buf));
  memset(map, 0, sizeof(map));
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      map[i][j] = buf[n - j + 1][i];
  swap(n, m);
  // show();
}

i64 eval() {
  memset(pre, 0, sizeof(pre));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      S(i, j) = map[i][j] == '#';
  for (int i = 0; i <= BMAX; i++)
    for (int j = 1; i >= j; j++)
      pre[i - j][j] += pre[i - j + 1][j - 1];

  i64 r = 0;
  for (int i = 1; i <= n + m; i++)
    for (int j = 0; i - j >= 1; j++)
      if (map[i - j][j + 1] == '#')
        for (int k = j + 1; i - k >= 1; k++)
          if (map[i - k][k + 1] == '#') {
            int d = (k - j) << 1;
            r += S(i - j - d, j + 1) - S(i - k, k - d + 1);
          }
  return r;
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%s", map[i] + 1);

  i64 ans = eval();
  rotate();
  ans += eval();
  rotate();
  ans += eval();
  rotate();
  ans += eval();
  printf("%lld\n", ans);

  return 0;
}


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

#include <algorithm>

using namespace std;

#define NMAX 600
#define BMAX (NMAX * 3 + 6)

typedef long long i64;

static int n, m;
static char map[NMAX + 10][NMAX + 10];
static int pre[3 * NMAX + 10][3 * NMAX + 10];

#define S(i, j) pre[NMAX + (i)][NMAX + (j)]

void show() {
  for (int i = 1; i <= n; i++)
    printf("%s\n", map[i] + 1);
  puts("");
}

void rotate() {
  static char buf[NMAX + 10][NMAX + 10];
  memcpy(buf, map, sizeof(buf));
  memset(map, 0, sizeof(map));
  for (int i = 1; i <= m; i++)
    for (int j = 1; j <= n; j++)
      map[i][j] = buf[n - j + 1][i];
  swap(n, m);
  // show();
}

i64 eval() {
  memset(pre, 0, sizeof(pre));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++)
      S(i, j) = map[i][j] == '#';
  for (int i = 0; i <= BMAX; i++)
    for (int j = 1; i >= j; j++)
      pre[i - j][j] += pre[i - j + 1][j - 1];

  i64 r = 0;
  for (int i = 1; i <= n + m; i++)
    for (int j = 0; i - j >= 1; j++)
      if (map[i - j][j + 1] == '#')
        for (int k = j + 1; i - k >= 1; k++)
          if (map[i - k][k + 1] == '#') {
            int d = (k - j) << 1;
            r += S(i - j - d, j + 1) - S(i - k, k - d + 1);
          }
  return r;
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++)
    scanf("%s", map[i] + 1);

  i64 ans = eval();
  rotate();
  ans += eval();
  rotate();
  ans += eval();
  rotate();
  ans += eval();
  printf("%lld\n", ans);

  return 0;
}
Problem p03227 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  if (s.size() == 2) {
    cout << s << endl;
  } else {
    cout << s.at(2) << s.at(1) << s.at(0) << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s.size() == 2) {
    cout << s << endl;
  } else {
    cout << s.at(2) << s.at(1) << s.at(0) << endl;
  }
}
Problem p03227 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
// const double PI = acos(-1);
// const double EPS = 1e-15;
// long long INF=(long long)1E17;
#define i_7 (long long)(1e9 + 7)
long mod(long a) {
  long long c = a % i_7;
  if (c >= 0)
    return c;
  return c + i_7;
}
using namespace std;

bool prime_(int n) {
  if (n == 1) {
    return false;
  } else if (n == 2) {
    return true;
  } else {
    for (int i = 2; i <= sqrt(n); i++) {
      if (n % i == 0) {
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }
  if (a % b == 0) {
    return b;
  } else {
    return gcd_(b, a % b);
  }
}

long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }

int main() {

  string s;
  cin >> s;
  string ans = "";
  int n = s.size();
  if (n == 2) {
    cout << s << endl;
  } else {
    for (int i = n - 1; i >= 0; i++) {
      ans += s[i];
    }
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
// const double PI = acos(-1);
// const double EPS = 1e-15;
// long long INF=(long long)1E17;
#define i_7 (long long)(1e9 + 7)
long mod(long a) {
  long long c = a % i_7;
  if (c >= 0)
    return c;
  return c + i_7;
}
using namespace std;

bool prime_(int n) {
  if (n == 1) {
    return false;
  } else if (n == 2) {
    return true;
  } else {
    for (int i = 2; i <= sqrt(n); i++) {
      if (n % i == 0) {
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b) {
  if (a < b) {
    swap(a, b);
  }
  if (a % b == 0) {
    return b;
  } else {
    return gcd_(b, a % b);
  }
}

long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; }

int main() {

  string s;
  cin >> s;
  string ans = "";
  int n = s.size();
  if (n == 2) {
    cout << s << endl;
  } else {
    for (int i = n - 1; i >= 0; i--) {
      ans += s[i];
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p03227 (C++)

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

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

  string s;
  cin >> s;

  if (s.size() == 3) {
    reverse(s.begin(), s.end());
  }

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


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

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

  string s;
  cin >> s;

  if (s.size() == 3) {
    reverse(s.begin(), s.end());
  }

  cout << s << "\n";
  return 0;
}
Problem p03227 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string A;
  char B, C;
  if (A.size() == 2) {
    cout << A << endl;
  } else {
    B = A.at(0);
    C = A.at(2);
    A.at(0) = C;
    A.at(2) = B;
    cout << A << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string A;
  cin >> A;
  char B, C;
  if (A.size() == 2) {
    cout << A << endl;
  } else {
    B = A.at(0);
    C = A.at(2);
    A.at(0) = C;
    A.at(2) = B;
    cout << A << endl;
  }
}
Problem p03228 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
#define mod 1000000007
#define speed                                                                  \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
int const N = 2 * 1e5 + 10;
vector<int> v;
vector<int> v1;
int a[N], t[N], answer[N];
int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  speed ll a, b, k;
  cin >> a >> b >> k;
  f(i, 0, k) {
    if (i % 2 == 0) {
      if (a % 2 == 1)
        a--;
      b += a / 2;
      a /= 2;
    } else {
      if (b % 2 == 1)
        b--;
      a += b / 2;
      b /= 2;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
#define mod 1000000007
#define speed                                                                  \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);
int const N = 2 * 1e5 + 10;
vector<int> v;
vector<int> v1;
int a[N], t[N], answer[N];
int main() {
  speed ll a, b, k;
  cin >> a >> b >> k;
  f(i, 0, k) {
    if (i % 2 == 0) {
      if (a % 2 == 1)
        a--;
      b += a / 2;
      a /= 2;
    } else {
      if (b % 2 == 1)
        b--;
      a += b / 2;
      b /= 2;
    }
  }
  cout << a << " " << b << endl;
  return 0;
}
Problem p03229 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <fstream>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; (i) < (n); ++(i))
#define int long long
using namespace std;

signed main(void) {
  int n, mone = 0, mtwo = 0;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> aligns(n);
  rep(i, n) { cin >> aligns[i]; }
  sort(aligns.begin(), aligns.end());
  if (aligns.size() == 2) {
    return aligns[1] - aligns[0];
  }
  rep(i, n) {
    mone += aligns[n - 1 - i] - aligns[i];
    mtwo += aligns[n - 1 - i] - aligns[i];
    if (n - 1 - i - i == 2) {
      mone += aligns[n - 1] - aligns[i + 1];
      mtwo += aligns[i + 1] - aligns[0];
      break;
    } else if (n - 1 - i - i == 3) {
      mone += aligns[n - 2 - i] - aligns[i];
      mtwo += aligns[n - 1 - i] - aligns[i + 1];
      mone += aligns[n - 1] - aligns[i + 1];
      mtwo += aligns[i + 2] - aligns[0];
      break;
    } else {
      mone += aligns[n - 2 - i] - aligns[i];
      mtwo += aligns[n - 1 - i] - aligns[i + 1];
    }
  }
  cout << max(mone, mtwo) << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <fstream>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; (i) < (n); ++(i))
#define int long long
using namespace std;

signed main(void) {
  int n, mone = 0, mtwo = 0;
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> aligns(n);
  rep(i, n) { cin >> aligns[i]; }
  sort(aligns.begin(), aligns.end());
  if (aligns.size() == 2) {
    cout << aligns[1] - aligns[0] << endl;
    return 0;
  }
  rep(i, n) {
    mone += aligns[n - 1 - i] - aligns[i];
    mtwo += aligns[n - 1 - i] - aligns[i];
    if (n - 1 - i - i == 2) {
      mone += aligns[n - 1] - aligns[i + 1];
      mtwo += aligns[i + 1] - aligns[0];
      break;
    } else if (n - 1 - i - i == 3) {
      mone += aligns[n - 2 - i] - aligns[i];
      mtwo += aligns[n - 1 - i] - aligns[i + 1];
      mone += aligns[n - 1] - aligns[i + 1];
      mtwo += aligns[i + 2] - aligns[0];
      break;
    } else {
      mone += aligns[n - 2 - i] - aligns[i];
      mtwo += aligns[n - 1 - i] - aligns[i + 1];
    }
  }
  cout << max(mone, mtwo) << endl;
  return 0;
}
Problem p03229 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
typedef long long ll;
const int maxn = 10003;

int n, a[maxn], b[maxn];
ll ans;

int read() {
  char ch = getchar();
  int num = 0;
  bool fl = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      fl = 1;
  for (; isdigit(ch); ch = getchar())
    num = (num << 1) + (num << 3) + ch - 48;
  if (fl)
    num = -num;
  return num;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  std::sort(a + 1, a + n + 1);
  b[1] = a[(n + 1) / 2];
  int l = 1, r = n, cnt = 1;
  for (int i = 1, f = 0; i < n; i++) {
    if (f)
      b[++cnt] = a[r--];
    else
      b[++cnt] = a[l++];
    f = 1 - f;
  }
  ans = 0;
  for (int i = 2; i <= n; i++)
    ans += abs(1ll * b[i] - b[i - 1]);
  l = 1, r = n, cnt = 1;
  for (int i = 1, f = 1; i < n; i++) {
    if (f)
      b[++cnt] = a[r--];
    else
      b[++cnt] = a[l++];
    f = 1 - f;
  }
  ll s = 0;
  for (int i = 2; i <= n; i++)
    s += abs(1ll * b[i] - b[i - 1]);
  printf("%lld\n", std::max(ans, s));
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
typedef long long ll;
const int maxn = 100003;

int n, a[maxn], b[maxn];
ll ans;

int read() {
  char ch = getchar();
  int num = 0;
  bool fl = 0;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-')
      fl = 1;
  for (; isdigit(ch); ch = getchar())
    num = (num << 1) + (num << 3) + ch - 48;
  if (fl)
    num = -num;
  return num;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++)
    a[i] = read();
  std::sort(a + 1, a + n + 1);
  b[1] = a[(n + 1) / 2];
  int l = 1, r = n, cnt = 1;
  for (int i = 1, f = 0; i < n; i++) {
    if (f)
      b[++cnt] = a[r--];
    else
      b[++cnt] = a[l++];
    f = 1 - f;
  }
  ans = 0;
  for (int i = 2; i <= n; i++)
    ans += abs(1ll * b[i] - b[i - 1]);
  l = 1, r = n, cnt = 1;
  for (int i = 1, f = 1; i < n; i++) {
    if (f)
      b[++cnt] = a[r--];
    else
      b[++cnt] = a[l++];
    f = 1 - f;
  }
  ll s = 0;
  for (int i = 2; i <= n; i++)
    s += abs(1ll * b[i] - b[i - 1]);
  printf("%lld\n", std::max(ans, s));
  return 0;
}
Problem p03229 (C++)

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

using namespace std;

int main() {
  ifstream cin("tst.in");
  int n;
  cin >> n;
  long long x;
  vector<long long> a;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  int l = a[a.size() - 1]; // left
  int r = l;               // right
  int i = 0, j = a.size() - 2;
  long long sum = 0;
  while (i < j) {
    int li = abs(l - a[i]), ri = abs(r - a[i]);
    int lj = abs(l - a[j]), rj = abs(r - a[j]);
    if (li > ri || lj > rj) { // left side
      if (li > lj) {
        sum += li;
        l = a[i++];
      } else {
        sum += lj;
        l = a[j--];
      }
    } else {
      if (ri > rj) {
        sum += ri;
        r = a[i++];
      } else {
        sum += rj;
        r = a[j--];
      }
    }
    // cout<<l<<"---"<<r<<"------"<<i<<"---"<<j<<"----------"<<sum<<endl;
  }
  sum += max(abs(l - a[i]), abs(r - a[i]));
  cout << sum << endl;
  return 0;
}

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

using namespace std;

int main() {
  // ifstream cin("tst.in");
  int n;
  cin >> n;
  long long x;
  vector<long long> a;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  int l = a[a.size() - 1]; // left
  int r = l;               // right
  int i = 0, j = a.size() - 2;
  long long sum = 0;
  while (i < j) {
    int li = abs(l - a[i]), ri = abs(r - a[i]);
    int lj = abs(l - a[j]), rj = abs(r - a[j]);
    if (li > ri || lj > rj) { // left side
      if (li > lj) {
        sum += li;
        l = a[i++];
      } else {
        sum += lj;
        l = a[j--];
      }
    } else {
      if (ri > rj) {
        sum += ri;
        r = a[i++];
      } else {
        sum += rj;
        r = a[j--];
      }
    }
    // cout<<l<<"---"<<r<<"------"<<i<<"---"<<j<<"----------"<<sum<<endl;
  }
  sum += max(abs(l - a[i]), abs(r - a[i]));
  cout << sum << endl;
  return 0;
}
Problem p03229 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P>> G;
void g_dir(G &graph, ll a, ll b, ll w = 1) { graph[a].push_back(P(b, w)); }
void g_undir(G &graph, ll a, ll b, ll w = 1) {
  g_dir(graph, a, b, w);
  g_dir(graph, b, a, w);
}
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for (ll(i) = (n)-1; (i) >= 0; (i)--)
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; (i)--)
template <class T> void chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
  }
}
const ll INF = 1145141919810893;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main() {

  ll N;
  cin >> N;
  V v(N);
  rep(i, N) cin >> v[i];
  sort(v.begin(), v.end(), greater<ll>());
  if (N % 2) {
    return 1;
  } else {
    ll ans = 0;
    for (ll i = 0; i < N / 2; i++) {
      ans += v[i];
      if (i + 1 < N / 2)
        ans += v[i];
    }
    for (ll i = N / 2; i < N; i++) {
      ans -= v[i];
      if (i > N / 2)
        ans -= v[i];
    }
    cout << ans << endl;
  }

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P>> G;
void g_dir(G &graph, ll a, ll b, ll w = 1) { graph[a].push_back(P(b, w)); }
void g_undir(G &graph, ll a, ll b, ll w = 1) {
  g_dir(graph, a, b, w);
  g_dir(graph, b, a, w);
}
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for (ll(i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for (ll(i) = (n)-1; (i) >= 0; (i)--)
#define rrep1(i, n) for (ll(i) = (n); (i) >= 1; (i)--)
template <class T> void chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
  }
}
template <class T> void chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
  }
}
const ll INF = 1145141919810893;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main() {

  ll N;
  cin >> N;
  V v(N);
  rep(i, N) cin >> v[i];
  sort(v.begin(), v.end(), greater<ll>());
  if (N % 2) {
    ll ans = 0;
    rep(i, N / 2) ans += v[i] * 2;
    for (ll i = N / 2, j = 0; i < N; i++, j++) {
      ans -= v[i];
      if (j >= 2)
        ans -= v[i];
    }
    ll ans2 = 0;
    for (ll i = N / 2, j = 0; i >= 0; i--, j++) {
      ans2 += v[i];
      if (j >= 2)
        ans2 += v[i];
    }
    for (ll i = (N + 1) / 2; i < N; i++) {
      ans2 -= v[i] * 2;
    }
    cout << max(ans, ans2) << endl;
  } else {
    ll ans = 0;
    for (ll i = 0; i < N / 2; i++) {
      ans += v[i];
      if (i + 1 < N / 2)
        ans += v[i];
    }
    for (ll i = N / 2; i < N; i++) {
      ans -= v[i];
      if (i > N / 2)
        ans -= v[i];
    }
    cout << ans << endl;
  }

  return 0;
}
Problem p03230 (Python)

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

for i in range(n**0.5 + 1):
    if 2 * n == i**2 - i:
        k = i
        break
    elif 2 * n < i**2 - i:
        print("No")
        exit()

k = int(k)
print("Yes")
print(k)
num, ans = 1, [[] for _ in range(k)]
for i in range(k):
    for j in range(i + 1, k):
        ans[i].append(num)
        ans[j].append(num)
        num += 1
    print(k - 1, *ans[i])


Fixed submission:
n = int(input())

for i in range(10**5):
    if 2 * n == i**2 - i:
        k = i
        break
    elif 2 * n < i**2 - i:
        print("No")
        exit()

k = int(k)
print("Yes")
print(k)
num, ans = 1, [[] for _ in range(k)]
for i in range(k):
    for j in range(i + 1, k):
        ans[i].append(num)
        ans[j].append(num)
        num += 1
    print(k - 1, *ans[i])
Problem p03230 (Python)

Buggy submission (status: Runtime Error):
def main():
    from collections import deque
    from decimal import Decimal, getcontext

    getcontext().prec = 1000

    N = int(input())

    # {1,...,N}*2を分割
    # k個の集合があって
    # 各集合は他のk-1個の集合に対し共通要素を1個ずつ合わせてk-1個の要素をもつ

    sq = Decimal(N * 8 + 1).sqrt()
    cond = sq % 2 == 1  # 奇数か

    if not cond:
        print("No")
        return
    k = int((1 + sq) // 2)  # Decimalのままだとrangeの引数に使えない
    print("Yes")
    print(k)

    deqs = []
    it = iter(range(1, N + 1))
    for _ in range(k):
        print(k - 1, end=" ")
        t = []
        for deq in deqs:
            x = deq.popleft()
            t.append(x)
        u = []
        for _ in range(k - 1 - len(t)):
            x = next(it)
            u.append(x)
        print(*t, *u)
        deqs.append(deque(u))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    from collections import deque
    from decimal import Decimal, getcontext

    getcontext().prec = 1000

    N = int(input())

    # {1,...,N}*2を分割
    # k個の集合があって
    # 各集合は他のk-1個の集合に対し共通要素を1個ずつ合わせてk-1個の要素をもつ

    sq = Decimal(N * 8 + 1).sqrt()
    cond = sq % 2 == 1  # 奇数か

    if not cond:
        print("No")
        return
    k = int((1 + sq) // 2)  # Decimalのままだとrangeの引数に使えない
    print("Yes")
    print(k)

    deqs = []
    it = iter(range(1, N + 1))
    for _ in range(k):
        print(k - 1, end=" ")
        t = []
        for deq in deqs:
            x = deq.popleft()
            t.append(x)
        u = []
        for _ in range(k - 1 - len(t)):
            x = next(it)
            u.append(x)
        t.extend(u)
        print(*t)  # *t,*uがRE
        deqs.append(deque(u))


if __name__ == "__main__":
    main()
Problem p03230 (Python)

Buggy submission (status: Runtime Error):
def solve(n):
    k = 1
    while k * (k + 1) < 2 * n:
        k += 1
    if k * (k + 1) != 2 * n:
        return False, []
    ans = [[] for _ in range(1000)]
    add_num = 1
    ans[1].append(add_num)
    ans[0].append(add_num)
    for i in range(2, k + 1):
        for j in range(i):
            add_num += 1
            ans[i].append(add_num)
            ans[i - j - 1].append(add_num)
    return True, ans, k


def main():
    n = int(input())
    res, ans, k = solve(n)
    if res:
        print("Yes")
        print(k + 1)
        for a in ans:
            if a:
                print(len(a), " ".join(map(str, a)))
            else:
                break
    else:
        print("No")


if __name__ == "__main__":
    main()


Fixed submission:
def solve(n):
    k = 1
    while k * (k + 1) < 2 * n:
        k += 1
    if k * (k + 1) != 2 * n:
        return False, [], -1
    ans = [[] for _ in range(1000)]
    add_num = 1
    ans[1].append(add_num)
    ans[0].append(add_num)
    for i in range(2, k + 1):
        for j in range(i):
            add_num += 1
            ans[i].append(add_num)
            ans[i - j - 1].append(add_num)
    return True, ans, k


def main():
    n = int(input())
    res, ans, k = solve(n)
    if res:
        print("Yes")
        print(k + 1)
        for a in ans:
            if a:
                print(len(a), " ".join(map(str, a)))
            else:
                break
    else:
        print("No")


if __name__ == "__main__":
    main()
Problem p03230 (C++)

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = n - 1; i >= m; --i)
#define FORE(x, xs) for (const auto &x : xs)
#define FORI(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x, y) x = min(x, y)
#define CHMAX(x, y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

int N;

void build(int k) {
  cout << k << endl;
  vvi ans(N);
  int x = 1;
  REP(i, k) FOR(j, i + 1, k) {
    ans[i].push_back(x);
    ans[j].push_back(x);
    x++;
  }

  REP(i, k) {
    cout << k - 1;
    FORE(x, ans[i]) cout << " " << x;
    cout << endl;
  }
}

void solve() {
  REP(k, N + 10) {
    if (k * (k - 1) / 2 == N) {
      cout << "Yes" << endl;
      build(k);
      return;
    } else if (k * (k - 1) / 2 > N) {
      cout << "No" << endl;
      return;
    }
  }
}

int main() {
  cin >> N;
  solve();
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define REPR(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (ll i = m; i < n; ++i)
#define FORR(i, m, n) for (ll i = n - 1; i >= m; --i)
#define FORE(x, xs) for (const auto &x : xs)
#define FORI(i, v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x, y) x = min(x, y)
#define CHMAX(x, y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl
#define DOUBLE(d) cout << fixed << setprecision(15) << (d) << endl

int N;

void build(int k) {
  cout << k << endl;
  vvi ans(k);
  int x = 1;
  REP(i, k) FOR(j, i + 1, k) {
    ans[i].push_back(x);
    ans[j].push_back(x);
    x++;
  }

  REP(i, k) {
    cout << k - 1;
    FORE(x, ans[i]) cout << " " << x;
    cout << endl;
  }
}

void solve() {
  REP(k, N + 10) {
    if (k * (k - 1) / 2 == N) {
      cout << "Yes" << endl;
      build(k);
      return;
    } else if (k * (k - 1) / 2 > N) {
      cout << "No" << endl;
      return;
    }
  }
}

int main() {
  cin >> N;
  solve();
}
Problem p03230 (C++)

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

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

  int k = 2;
  while (k * (k - 1) / 2 < n)
    k++;
  if (k * (k - 1) / 2 != n) {
    cout << "No" << endl;
    return 0;
  }

  int a[400][400];
  int b[400];
  for (int i = 1; i <= k; i++)
    b[i] = 0;
  int x = 1;
  for (int i = 1; i <= k; i++) {
    for (int j = i + 1; j <= k; j++) {
      a[i][b[i]] = x;
      b[i]++;
      a[j][b[j]] = x;
      b[j]++;
      x++;
    }
  }

  cout << "Yes" << endl;
  cout << k << endl;

  for (int i = 1; i <= k; i++) {
    cout << k - 1 << " ";
    for (int j = 0; j < k - 1; j++) {
      cout << a[i][j];
      if (j == k - 2)
        cout << endl;
      else
        cout << " ";
    }
  }
}

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

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

  int k = 2;
  while (k * (k - 1) / 2 < n)
    k++;
  if (k * (k - 1) / 2 != n) {
    cout << "No" << endl;
    return 0;
  }

  int a[500][500];
  int b[500];
  for (int i = 1; i <= k; i++)
    b[i] = 0;
  int x = 1;
  for (int i = 1; i <= k; i++) {
    for (int j = i + 1; j <= k; j++) {
      a[i][b[i]] = x;
      b[i]++;
      a[j][b[j]] = x;
      b[j]++;
      x++;
    }
  }

  cout << "Yes" << endl;
  cout << k << endl;

  for (int i = 1; i <= k; i++) {
    cout << k - 1 << " ";
    for (int j = 0; j < k - 1; j++) {
      cout << a[i][j];
      if (j == k - 2)
        cout << endl;
      else
        cout << " ";
    }
  }
}
Problem p03230 (C++)

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

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define all(a) (a).begin(), (a).end()
#define lol 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
#define SIZE 1000005
#define debug(x) cerr << #x << " = " << x << endl;
#define F first
#define S second
#define endl '\n'
#define deci(n) cout << fixed << setprecision(n);
const double pi = acos(-1.0);

using namespace std;

void MOD(ll &x) {
  if (x >= lol)
    x -= lol;
  if (x < 0)
    x += lol;
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void solve() {
  int n;
  cin >> n;
  int k;
  rep(i, 1, n + 1) {
    int num = i * (i - 1);
    num /= 2;
    if (num == n) {
      k = i;
      break;
    } else if (num > n) {
      cout << "No";
      return;
    }
  }
  vi ans[k];
  int curr = 1;
  rep(i, 1, k + 1) {
    rep(j, i + 1, k + 1) {
      ans[i - 1].pb(curr);
      ans[j - 1].pb(curr++);
    }
  }
  cout << "Yes" << endl;
  cout << k << endl;
  rep(i, 0, k) {
    cout << k - 1 << " ";
    rep(j, 0, k - 1) cout << ans[i][j] << " ";
    cout << endl;
  }
}

// Remove  debugs!!

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //    #ifndef ONLINE_JUDGE
  //        freopen("input.txt", "r", stdin);
  //        freopen("output.txt", "w", stdout);
  //    #endif
  int t = 1;
  //    cin>>t; int i=1;
  while (t--) {
    // cout<<"Case #"<<i++<<": ";
    solve();
    // cout<<endl;
  }
  return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
#define all(a) (a).begin(), (a).end()
#define lol 1000000007
#define rep(i, a, b) for (int i = a; i < b; i++)
#define SIZE 1000005
#define debug(x) cerr << #x << " = " << x << endl;
#define F first
#define S second
#define endl '\n'
#define deci(n) cout << fixed << setprecision(n);
const double pi = acos(-1.0);

using namespace std;

void MOD(ll &x) {
  if (x >= lol)
    x -= lol;
  if (x < 0)
    x += lol;
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

void solve() {
  int n;
  cin >> n;
  int k;
  rep(i, 1, n + 2) {
    int num = i * (i - 1);
    num /= 2;
    if (num == n) {
      k = i;
      break;
    } else if (num > n) {
      cout << "No";
      return;
    }
  }
  vi ans[k];
  int curr = 1;
  rep(i, 1, k + 1) {
    rep(j, i + 1, k + 1) {
      ans[i - 1].pb(curr);
      ans[j - 1].pb(curr++);
    }
  }
  cout << "Yes" << endl;
  cout << k << endl;
  rep(i, 0, k) {
    cout << k - 1 << " ";
    rep(j, 0, k - 1) cout << ans[i][j] << " ";
    cout << endl;
  }
}

// Remove  debugs!!

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  //    #ifndef ONLINE_JUDGE
  //        freopen("input.txt", "r", stdin);
  //        freopen("output.txt", "w", stdout);
  //    #endif
  int t = 1;
  //    cin>>t; int i=1;
  while (t--) {
    // cout<<"Case #"<<i++<<": ";
    solve();
    // cout<<endl;
  }
  return 0;
}