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

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repi(i, a, b) for (int i = a; i <= (b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using ll = long long;
using namespace std;
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N, K;
int main() {
  cin >> N >> K;
  long ans = 0;
  repi(i, K, N - 1) repi(j, i + 1, N) {
    if (!i)
      ans += (N - i) / j;
    else
      ans += ((N - i) / j + 1);
  }
  cout << ans << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
#define repi(i, a, b) for (int i = a; i <= (b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using ll = long long;
using namespace std;
struct aaa {
  aaa() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int N, K;
int main() {
  cin >> N >> K;
  long ans = 0;
  rep1(b, N) ans += (N / b) * max(0, (b - K)) + max(0, (N % b - K + 1));
  if (K == 0)
    ans -= N;
  cout << ans << endl;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
int n, k;
int main() {
  cin >> n >> k;
  ll ans = 0;
  for (int b = max(1, k + 1); b <= n; b++) {
    for (int a = 1; a <= n;) {
      if (a % b >= k) {
        ans++;
        a++;
      } else {
        a += (k - (a % b));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <cmath>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < n; i++)
#define Rreps(i, n, e) for (int i = n - 1; i >= e; --i)
int n, k;
int main() {
  cin >> n >> k;
  ll ans = 0;
  for (int b = max(1, k + 1); b <= n; b++) {
    for (int a = 1; a <= n;) {
      if (a % b >= k) {
        ans += b - (a % b);
        a += b - (a % b);
        if (a > n) {
          ans -= (a - n - 1);
        }
      } else {
        a += (k - (a % b));
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03420 (C++)

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  ll ans = 0;

  for (int i = 1; i <= N; ++i) {
    for (int k = 1; k <= N; ++k) {
      if (i % k >= K)
        ans++;
    }
  }
  cout << ans << endl;
}

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

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
using ll = long long;
string char_to_string(char val) { return string(1, val); }
int char_to_int(char val) { return val - '0'; }
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  ll ans = 0;
  for (int k = 1; k <= N; ++k) {
    if (k - K <= 0)
      continue;
    ans += (k - K) * (N / k);
    ll A;
    if (K != 0)
      A = N % k - K + 1;
    else if (K == 0)
      A = N % k;
    if (A >= 0)
      ans += A;
  }
  cout << ans << endl;
}
Problem p03420 (C++)

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

using namespace std;

using ll = long long;
using llu = long long unsigned;
using ld = long double;

const int inf = 0x3c3c3c3c;
const ll infl = 0x3c3c3c3c3c3c3c3c;

int main() {
  cin.tie(NULL);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  freopen("input.txt", "r", stdin);
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  if (K == 0)
    return !printf("%lld", N * N);
  for (int i = K + 1; i <= N; i++) {
    ans += (N / i) * (i - K) + max(N % i - K + 1, 0LL);
  }
  printf("%lld", ans);
  return 0;
}

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

using namespace std;

using ll = long long;
using llu = long long unsigned;
using ld = long double;

const int inf = 0x3c3c3c3c;
const ll infl = 0x3c3c3c3c3c3c3c3c;

int main() {
  cin.tie(NULL);
  cin.sync_with_stdio(false);
  cout.sync_with_stdio(false);
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  if (K == 0)
    return !printf("%lld", N * N);
  for (int i = K + 1; i <= N; i++) {
    ans += (N / i) * (i - K) + max(N % i - K + 1, 0LL);
  }
  printf("%lld", ans);
  return 0;
}
Problem p03420 (C++)

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

int main() {
  int n, k;
  int64_t cnt = 0;
  cin >> n >> k;
  for (int a = max(1, k); a < n + 1; a++) {
    for (int b = k + 1; b < n + 1; b++) {
      if (a % b >= k) {
        cnt++;
      }
    }
  }
  cout << cnt << endl;
}

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

int main() {
  int n, k;
  int64_t cnt = 0;
  cin >> n >> k;
  if (k != 0) {
    for (int b = max(1, k); b < n + 1; b++) {
      if (n % b < k) {
        cnt += (n / b) * (b - k);
      } else if (n % b >= k) {
        cnt += (n / b) * (b - k) + (n % b - k + 1);
      }
    }
  } else if (k == 0) {
    for (int b = max(1, k); b < n + 1; b++) {
      if (n % b < k) {
        cnt += (n / b) * (b - k);
      } else if (n % b >= k) {
        cnt += (n / b) * (b - k) + (n % b - k);
      }
    }
  }
  cout << cnt << endl;
}
Problem p03420 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define exrep(i, a, b) for (long long i = a; i <= b; i++)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

  ll n, k;
  cin >> n >> k;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  ll cnt = 0;
  exrep(a, k, n) {
    cnt += n - a;
    exrep(b, k + 1, a - 1) {
      if (a % b >= k)
        cnt++;
    }
  }
  cout << cnt << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#define exrep(i, a, b) for (long long i = a; i <= b; i++)
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const int MAX = 510000;
const double pi = acos(-1);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

  ll n, k;
  cin >> n >> k;
  if (k == 0) {
    cout << n * n << endl;
    return 0;
  }
  ll cnt = 0;
  exrep(b, k + 1, n) {
    cnt += (n / b) * max((b - k), 0ll) + max(n % b - k + 1, 0ll);
  }
  cout << cnt << endl;
}
Problem p03420 (C++)

Buggy submission (status: Runtime Error):

#include <bits/stdc++.h>
using namespace std;
int main() {
  long N, K;
  cin >> N >> K;
  assert(K > 0);
  long ans = 0;
  for (long b = K + 1; b <= N; b++) {
    long Q = N / b;
    long x = Q * (b - K);
    long y = max(0L, N - (b * Q + K) + 1);
    ans += x + y;
  }
  cout << ans;
}

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long N, K;
  cin >> N >> K;
  if (K == 0) {
    cout << N * N;
    return 0;
  }
  long ans = 0;
  for (long b = K + 1; b <= N; b++) {
    long Q = N / b;
    long x = Q * (b - K);
    long y = max(0L, N - (b * Q + K) + 1);
    ans += x + y;
  }
  cout << ans;
}
Problem p03421 (C++)

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

vector<int> ans;
signed main() {
  int n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  if (n < a + b - 1 || n > a * b) {
    printf("-1\n");
    return 0;
  }

  int x = n - a, cnt = n - a + 1;
  for (int i = cnt; i <= n; i++)
    ans.push_back(i);
  for (int i = 0; i < b - 1; i++) {
    int d = x / (b - 1);
    if (x % (b - a) > i)
      d++;
    cnt -= d;
    for (int j = cnt; j < cnt + d; j++)
      ans.push_back(j);
  }

  printf("%lld", ans[0]);
  for (int i = 1; i < ans.size(); i++)
    printf(" %lld", ans[i]);
  printf("\n");
  return 0;
}

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

vector<int> ans;
signed main() {
  int n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  if (n < a + b - 1 || n > a * b) {
    printf("-1\n");
    return 0;
  }

  int x = n - a, cnt = n - a + 1;
  for (int i = cnt; i <= n; i++)
    ans.push_back(i);
  for (int i = 0; i < b - 1; i++) {
    int d = x / (b - 1);
    if (x % (b - 1) > i)
      d++;
    cnt -= d;
    for (int j = cnt; j < cnt + d; j++)
      ans.push_back(j);
  }

  printf("%lld", ans[0]);
  for (int i = 1; i < ans.size(); i++)
    printf(" %lld", ans[i]);
  printf("\n");
  return 0;
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define N 4005
using namespace std;
int n, a, b, tot;
int ans[300005];
int main() {
  scanf("%d%d%d", &n, &a, &b);
  if (a + b > n + 1 || a * b < n)
    return puts("-1");
  int r = n;
  for (int i = 1; i <= b; i++) {
    int j, R = r - 1;
    for (j = 1; j < a && R > b - i; j++, R--)
      ;
    for (int k = j; k; k--)
      ans[++tot] = r + 1 - k;
    r -= j;
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", ans[i]);
}

Fixed submission:
#include <bits/stdc++.h>
#define N 4005
using namespace std;
int n, a, b, tot;
int ans[300005];
int main() {
  scanf("%d%d%d", &n, &a, &b);
  if (a + b > n + 1 || 1ll * a * b < n)
    return puts("-1"), 0;
  int r = n;
  for (int i = 1; i <= b; i++) {
    int j, R = r - 1;
    for (j = 1; j < a && R > b - i; j++, R--)
      ;
    for (int k = j; k; k--)
      ans[++tot] = r + 1 - k;
    r -= j;
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", ans[i]);
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back

using namespace std;

int main() {
  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);
  if (a + b > n + 1) {
    printf("-1");
    return 0;
  }
  if (a * b >= n) {
    for (int i = b; i > 0; --i) {
      printf("%d ", i);
    }
    b = (n - b) / (a - 1) + ((n - b) % (a - 1) > 0);
    for (int i = 1; i <= a; ++i) {
      for (int j = min(b * (i) + b, n); j >= b * (i) + 1; --j) {
        printf("%d ", j);
      }
    }
  } else {
    printf("-1");
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back

using namespace std;

int main() {
  int n, a, b;
  scanf("%d %d %d", &n, &a, &b);
  if (a + b > n + 1) {
    printf("-1");
    return 0;
  }
  int k = b, d = 0;
  if (1ll * a * b >= n) {
    while (d < n) {
      for (int i = k; i > 0; --i) {
        printf("%d ", i + d);
      }
      --a;
      d += k;
      if (a > 0) {
        k = (n - d) / a;
      }
    }
  } else {
    printf("-1");
  }
  return 0;
}
Problem p03421 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll N, A, B;

int main() {
  cin >> N >> A >> B;

  if (A + B - 1 > N || A * B < N) {
    cout << -1 << endl;
    return 0;
  }

  int now = min(N - A, B - 1);
  vector<int> ans;
  vector<int> used(N + 1, 0);
  for (int i = N - A + 1; i <= N; i++) {
    ans.push_back(i);
    used[i] = 1;
    for (int j = 0; j < B - 1; j++) {
      if (now - j >= 1 && used[now - j] == 0) {
        used[now - j] = 1;
        ans.push_back(now - j);
      }
    }
    now = min(N - A, now + B - 1);
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i] << " ";
  cout << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

ll N, A, B;

int main() {
  cin >> N >> A >> B;

  if (A + B - 1 > N || A * B < N) {
    cout << -1 << endl;
    return 0;
  }

  int now = min(N - A, B - 1);
  vector<int> ans;
  vector<int> used(N + 1, 0);
  for (int i = N - A + 1; i <= N; i++) {
    ans.push_back(i);
    used[i] = 1;
    for (int j = 0; j < B - 1; j++) {
      if (now - j >= 1 && used[now - j] == 0) {
        used[now - j] = 1;
        ans.push_back(now - j);
      } else
        break;
    }
    now = min(N - A, now + B - 1);
  }
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i] << " ";
  cout << endl;

  return 0;
}
Problem p03421 (C++)

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

const int maxn = 100002;

int n, A, B, p[maxn];

int main() {
  // freopen("lisdl.inp", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> A >> B;
  if (n < A + B - 1 || 1LL * A * B < n) {
    cout << -1;
    return 0;
  }
  p[1] = B;
  int tmp = n - B - A + 1;
  for (int i = 2; i <= A; ++i) {
    p[i] = 1;
  }
  for (int i = 2; i <= A; ++i) {
    p[i] += min(tmp, B - 1);
    tmp -= min(tmp, B - 1);
  }
  int cur = 1;
  for (int i = 1; i <= A; ++i) {
    for (int j = p[i] - 1; j >= 0; --j)
      cout << cur + j << ' ';
    cur += p[i];
  }
}


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

const int maxn = 300002;

int n, A, B, p[maxn];

int main() {
  // freopen("lisdl.inp", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> A >> B;
  if (n < A + B - 1 || 1LL * A * B < n) {
    cout << -1;
    return 0;
  }
  p[1] = B;
  int tmp = n - B - A + 1;
  for (int i = 2; i <= A; ++i) {
    p[i] = 1;
  }
  for (int i = 2; i <= A; ++i) {
    p[i] += min(tmp, B - 1);
    tmp -= min(tmp, B - 1);
  }
  int cur = 1;
  for (int i = 1; i <= A; ++i) {
    for (int j = p[i] - 1; j >= 0; --j)
      cout << cur + j << ' ';
    cur += p[i];
  }
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  if (a + b > n + 1 || 1LL * a * (b - 1) > n) {
    cout << -1 << '\n';
    return 0;
  }
  int cur = n;
  vector<vector<int>> seq;
  while (cur >= 1 && a > 0) {
    seq.push_back({cur--});
    a--;
  }
  int it = 0;
  while (cur >= 1) {
    while (cur >= 1 && (int)seq[it].size() < b)
      seq[it].push_back(cur--);
    it++;
  }
  vector<int> ans;
  for (int i = (int)seq.size() - 1; i >= 0; i--)
    for (int j : seq[i])
      ans.push_back(j);
  for (int i = 0; i < n; i++) {
    if (i > 0)
      cout << " ";
    cout << ans[i];
  }
  cout << '\n';
  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b;
  cin >> n >> a >> b;
  if (a + b > n + 1 || 1LL * a * b < n) {
    cout << -1 << '\n';
    return 0;
  }
  int cur = n;
  vector<vector<int>> seq;
  while (cur >= 1 && a > 0) {
    seq.push_back({cur--});
    a--;
  }
  int it = 0;
  while (cur >= 1) {
    while (cur >= 1 && (int)seq[it].size() < b)
      seq[it].push_back(cur--);
    it++;
  }
  vector<int> ans;
  for (int i = (int)seq.size() - 1; i >= 0; i--)
    for (int j : seq[i])
      ans.push_back(j);
  for (int i = 0; i < n; i++) {
    if (i > 0)
      cout << " ";
    cout << ans[i];
  }
  cout << '\n';
  return 0;
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  if (a * b < n)
    printf("-1\n");
  else if (a + b - 1 > n)
    printf("-1\n");
  else {
    int x = (n - b) / (a - 1);
    int y = (n - b) % (a - 1);
    int pos = b;
    for (int i = pos; i >= 1; i--) {
      if (i != pos)
        printf(" ");
      printf("%d", i);
    }
    for (int j = 1; j <= y; j++) {
      pos += x + 1;
      for (int i = pos; i >= pos - x; i--) {
        printf(" %d", i);
      }
    }
    for (int j = 1; j <= a - 1 - y; j++) {
      pos += x;
      for (int i = pos; i > pos - x; i--) {
        printf(" %d", i);
      }
    }
    printf("\n");
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  if (a * b < n)
    printf("-1\n");
  else if (a + b - 1 > n)
    printf("-1\n");
  else if (a == 1) {
    for (int i = n; i >= 1; i--) {
      printf("%d%c", i, i == 1 ? '\n' : ' ');
    }
  } else {
    int x = (n - b) / (a - 1);
    int y = (n - b) % (a - 1);
    int pos = b;
    for (int i = pos; i >= 1; i--) {
      if (i != pos)
        printf(" ");
      printf("%d", i);
    }
    for (int j = 1; j <= y; j++) {
      pos += x + 1;
      for (int i = pos; i >= pos - x; i--) {
        printf(" %d", i);
      }
    }
    for (int j = 1; j <= a - 1 - y; j++) {
      pos += x;
      for (int i = pos; i > pos - x; i--) {
        printf(" %d", i);
      }
    }
    printf("\n");
  }
  return 0;
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define F first
#define S second
int n, a, b;
vector<int> ans;
int main(void) {
  cin >> n >> a >> b;
  if (n + 1 < a + b || ((n + a - 1) / a > b && (n + b - 1) / b > a)) {
    cout << -1 << endl;
    return 0;
  }
  if ((n + a - 1) / a <= b) {
    int o = 1;
    for (int i = o + b - 1; i >= o; i--)
      ans.push_back(i);
    o += b;
    int s = (n - o + 1);
    a--;
    b = s / a;
    for (int i = 0; i < s % a; i++) {
      for (int j = o + b; j >= o; j--)
        ans.push_back(j);
      o += b + 1;
    }
    for (int i = 0; i < a - s % a; i++) {
      for (int j = o + b - 1; j >= o; j--)
        ans.push_back(j);
      o += b;
    }
  } else {
    int o = n;
    for (int i = o - b + 1; i <= o; i++)
      ans.push_back(i);
    o -= b;
    int s = (n - o + 1);
    a--;
    b = s / a;
    for (int i = 0; i < s % a; i++) {
      for (int j = o - b; j <= o; j++)
        ans.push_back(j);
      o -= (b + 1);
    }
    for (int i = 0; i < a - s % a; i++) {
      for (int j = o - b + 1; j <= o; j++)
        ans.push_back(j);
      o -= b;
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    if (i != 0)
      cout << ' ';
    cout << ans[i];
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define F first
#define S second
int n, a, b;
vector<int> ans;
int main(void) {
  cin >> n >> a >> b;
  if (n + 1 < a + b || ((n + a - 1) / a > b && (n + b - 1) / b > a)) {
    cout << -1 << endl;
    return 0;
  }
  if (a == 1) {
    for (int i = n; i >= 1; i--)
      ans.push_back(i);
  } else if (b == 1)
    for (int i = 1; i <= n; i++)
      ans.push_back(i);
  else if ((n + a - 1) / a <= b) {
    int o = 1;
    for (int i = o + b - 1; i >= o; i--)
      ans.push_back(i);
    o += b;
    int s = (n - o + 1);
    a--;
    b = s / a;
    for (int i = 0; i < s % a; i++) {
      for (int j = o + b; j >= o; j--)
        ans.push_back(j);
      o += b + 1;
    }
    for (int i = 0; i < a - s % a; i++) {
      for (int j = o + b - 1; j >= o; j--)
        ans.push_back(j);
      o += b;
    }
  } else {
    int o = n;
    for (int i = o - b + 1; i <= o; i++)
      ans.push_back(i);
    o -= b;
    int s = (n - o + 1);
    a--;
    b = s / a;
    for (int i = 0; i < s % a; i++) {
      for (int j = o - b; j <= o; j++)
        ans.push_back(j);
      o -= (b + 1);
    }
    for (int i = 0; i < a - s % a; i++) {
      for (int j = o - b + 1; j <= o; j++)
        ans.push_back(j);
      o -= b;
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    if (i != 0)
      cout << ' ';
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
Problem p03421 (C++)

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

using namespace std;

const int maxn = 3e5 + 1e2;

int s[maxn], vis[maxn];
int n, a, b, x, y;

int main() {
  scanf("%d%d%d", &n, &a, &b);
  if ((long long)a * b < (long long)n) {
    cout << -1;
    return 0;
  }
  if (a + b > n + 1) {
    cout << -1;
    return 0;
  }
  int tmp = 0;
  for (int i = n - a + 1; i <= n; i++)
    s[++tmp] = i, vis[i] = 1;
  if (tmp != n) {
    for (int i = b - 1; i >= 1; i--) {
      s[++tmp] = i;
      vis[i] = 1;
      if (tmp == n)
        break;
    }
  }
  for (int i = b; i <= n - a + 1; i += (b - 1)) {
    for (int j = i + b - 2; j >= i; j--) {
      if (!vis[j] && j <= n)
        s[++tmp] = j;
      if (tmp == n)
        break;
    }
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", s[i]);
  return 0;
}


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

using namespace std;

const int maxn = 3e5 + 1e2;

int s[maxn], vis[maxn];
int n, a, b, x, y;

int main() {
  scanf("%d%d%d", &n, &a, &b);
  if ((long long)a * b < (long long)n) {
    cout << -1;
    return 0;
  }
  if (a + b > n + 1) {
    cout << -1;
    return 0;
  }
  int tmp = 0;
  for (int i = n - a + 1; i <= n; i++)
    s[++tmp] = i, vis[i] = 1;
  if (tmp != n) {
    for (int i = b - 1; i >= 1; i--) {
      s[++tmp] = i;
      vis[i] = 1;
      if (tmp == n)
        break;
    }
    for (int i = b; i <= n - a + 1; i += (b - 1)) {
      for (int j = i + b - 2; j >= i; j--) {
        if (!vis[j] && j <= n)
          s[++tmp] = j, vis[j] = 1;
        if (tmp == n)
          break;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    printf("%d ", s[i]);
  return 0;
}
Problem p03421 (C++)

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

using namespace std;
typedef long long ll;
ll n, a, b, c[maxn], k, p;
bool f[maxn];

int main() {
  scanf("%d%d%d", &n, &a, &b);
  if (a + b > n + 1 || a * b < n) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; i++)
    c[i] = n - i;
  reverse(c, c + a);
  k = n - a + 1;
  b = k - b;
  for (int i = 1; i < k; i++) {
    p = min(a - 1, b);
    reverse(c + a * i, c + a * i + p + 1);
    b -= p;
  }
  for (int i = 0; i < n; i++)
    printf("%d ", c[i]);
  printf("\n");
}


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

using namespace std;
typedef long long ll;
ll n, a, b, c[maxn], k, p;
bool f[maxn];

int main() {
  scanf("%d%d%d", &n, &a, &b);
  if (a + b > n + 1 || a * b < n) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < n; i++)
    c[i] = n - i;
  reverse(c, c + a);
  k = n - a + 1;
  b = k - b;
  for (int i = 1; i < k; i++) {
    p = min(a - 1, b);
    reverse(c + a * i, c + a * i + p + 1);
    b -= p;
  }
  for (int i = 0; i < n; i++)
    printf("%d ", c[i]);
  printf("\n");
}
Problem p03421 (C++)

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

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  if (A * B < N || A + B > N + 1)
    cout << -1 << endl;
  else {
    ll num;
    ll hoge = 0;
    rep(i, A) cout << N - A + 1 + i << " ";
    num = A;
    rep(j, (N - A) / (B - 1)) {
      hoge++;
      rep(i, B - 1) {
        if (num == N)
          break;
        cout << hoge * (B - 1) - i << " ";
        num++;
      }
    }
    hoge = 0;
    while (num < N) {
      cout << N - A - hoge << " ";
      hoge++;
      num++;
    }
  }
  return 0;
}

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

using namespace std;

typedef long long ll;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  if (A * B < N || A + B > N + 1)
    cout << -1 << endl;
  else {
    if (B == 1) {
      rep(i, N) cout << i + 1 << " ";
      return 0;
    }
    ll num;
    ll hoge = 0;
    rep(i, A) cout << N - A + 1 + i << " ";
    num = A;
    rep(j, (N - A) / (B - 1)) {
      hoge++;
      rep(i, B - 1) {
        if (num == N)
          break;
        cout << hoge * (B - 1) - i << " ";
        num++;
      }
    }
    hoge = 0;
    while (num < N) {
      cout << N - A - hoge << " ";
      hoge++;
      num++;
    }
  }
  return 0;
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define _repargs(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _repargs(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T> inline void output(T a, int p = 0) {
  if (p)
    cout << fixed << setprecision(p) << a << "\n";
  else
    cout << a << "\n";
}
// end of template

template <typename T> inline void voutput(T &v) {
  rep(i, v.size()) {
    if (i)
      cout << " " << v[i];
    else
      cout << v[i];
  }
  cout << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  // source code
  ll N, A, B;
  cin >> N >> A >> B;
  if (A * B >= N && A + B - 1 <= N) {
    vector<ll> AA(A, 1);
    AA[0] = B;
    ll r = N - (A + B - 1);
    ll p = r / (A - 1);
    ll q = r % (A - 1);
    rep(i, 1, A) AA[i] += p;
    rep(i, 1, q + 1) AA[i]++;
    //        voutput(AA);
    vector<ll> ret;
    ll now = 0;
    for (auto a : AA) {
      now += a;
      for (ll i = now; i > now - a; i--)
        ret.pb(i);
    }
    voutput(ret);
  } else {
    output(-1);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define _repargs(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define rep(...) _repargs(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T> inline void output(T a, int p = 0) {
  if (p)
    cout << fixed << setprecision(p) << a << "\n";
  else
    cout << a << "\n";
}
// end of template

template <typename T> inline void voutput(T &v) {
  rep(i, v.size()) {
    if (i)
      cout << " " << v[i];
    else
      cout << v[i];
  }
  cout << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  // source code
  ll N, A, B;
  cin >> N >> A >> B;
  if (A * B >= N && A + B - 1 <= N) {
    if (A == 1) {
      vector<ll> ret(N);
      rep(i, N) ret[i] = N - i;
      voutput(ret);
      return 0;
    }
    vector<ll> AA(A, 1);
    AA[0] = B;
    ll r = N - (A + B - 1);
    ll p = r / (A - 1);
    ll q = r % (A - 1);
    rep(i, 1, A) AA[i] += p;
    rep(i, 1, q + 1) AA[i]++;
    //        voutput(AA);
    vector<ll> ret;
    ll now = 0;
    for (auto a : AA) {
      now += a;
      for (ll i = now; i > now - a; i--)
        ret.pb(i);
    }
    voutput(ret);
  } else {
    output(-1);
  }

  return 0;
}
Problem p03421 (C++)

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

typedef long long ll;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> all;
  for (ll i = 0; i < N; i++) {
    all.push_back(i + 1);
  }
  ll sz = N;
  if (A + B > N + 1)
    cout << -1 << endl;
  else if (A * B < N)
    cout << -1 << endl;
  else {
    while (sz >= A + B - 1) {
      for (ll i = sz - A; i < sz; i++) {
        cout << all[i] << " ";
      }
      for (ll i = 0; i < A; i++)
        all.pop_back();
      sz -= A;
      B--;
    }
    if (B > 0) {
      for (ll i = B - 1; i < sz; i++) {
        cout << all[i] << " ";
      }
      for (ll i = 0; i < B - 1; i++) {
        cout << all[B - 2 - i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}


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

typedef long long ll;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  vector<ll> all;
  for (ll i = 0; i < N; i++) {
    all.push_back(i + 1);
  }
  ll sz = N;
  if (A + B > N + 1)
    cout << -1 << endl;
  else if (A * B < N)
    cout << -1 << endl;
  else {
    while (sz >= A + B - 1 && sz > 0) {
      for (ll i = sz - A; i < sz; i++) {
        cout << all[i] << " ";
      }
      for (ll i = 0; i < A; i++)
        all.pop_back();
      sz -= A;
      B--;
    }
    if (B > 0) {
      for (ll i = B - 1; i < sz; i++) {
        cout << all[i] << " ";
      }
      for (ll i = 0; i < B - 1; i++) {
        cout << all[B - 2 - i] << " ";
      }
    }
    cout << endl;
  }
  return 0;
}
Problem p03421 (C++)

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

signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> seq;
  int cnt = 0, cur = 0, tmp = 0;
  if (a + b > n + 1 || a * b < n) {
    cout << -1 << endl, exit(0);
  }
  if (a == 1) {
    for (int i = 0; i < n; i++)
      seq[i] = n - i;
    for (auto &&w : seq)
      cout << w << ((&w == &seq.back()) ? "\n" : " ");
    return 0;
  }
  vector<int> v;
  v.push_back(b);
  int m = (n - b) / (a - 1), r = (n - b) % (a - 1);
  for (int i = 0; i < a - 1; i++)
    v.push_back(m + (i < r));
  int acm = 0;
  for (auto &&w : v) {
    for (int i = 0; i < w; i++) {
      seq.push_back(acm + w - i);
    }
    acm += w;
  }
  for (auto &&w : seq)
    cout << w << ((&w == &seq.back()) ? "\n" : " ");
}


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

signed main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> seq;
  int cnt = 0, cur = 0, tmp = 0;
  if (a + b > n + 1 || a * b < n) {
    cout << -1 << endl, exit(0);
  }
  if (a == 1) {
    for (int i = 0; i < n; i++)
      seq.push_back(n - i);
    for (auto &&w : seq)
      cout << w << ((&w == &seq.back()) ? "\n" : " ");
    return 0;
  }
  vector<int> v;
  v.push_back(b);
  int m = (n - b) / (a - 1), r = (n - b) % (a - 1);
  for (int i = 0; i < a - 1; i++)
    v.push_back(m + (i < r));
  int acm = 0;
  for (auto &&w : v) {
    for (int i = 0; i < w; i++) {
      seq.push_back(acm + w - i);
    }
    acm += w;
  }
  for (auto &&w : seq)
    cout << w << ((&w == &seq.back()) ? "\n" : " ");
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define INFLL (1ll << 60)
typedef pair<int, int> P;
#define MOD (1000000007ll)
#define l_ength size

bool flag = true;

int main(void) {
  ll n, a, b, x, y, m, p, q, r, i, j;
  vector<ll> v;
  cin >> n >> a >> b;
  x = a * b;
  y = a + b - 1ll;
  if (x < n || y > n) {
    cout << "-1" << endl;
    return 0;
  }
  x = n - b;
  y = a - 1ll;
  p = x / y;
  q = x % y;
  r = y - q;
  x = 0ll;
  for (i = 1ll; i <= r; ++i) {
    for (j = 0; j < p; ++j) {
      v.push_back(p * i - j);
      x = max(x, p * i - j);
    }
  }
  ++p;
  for (i = 1ll; i <= q; ++i) {
    for (j = 0; j < p; ++j) {
      v.push_back(x + p * i - j);
    }
  }
  for (i = 0ll; i < b; ++i) {
    v.push_back(n - i);
  }
  for (i = 0; i < n; ++i) {
    cout << ((i) ? " " : "") << v[i];
  }
  cout << endl;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1 << 30)
#define INFLL (1ll << 60)
typedef pair<int, int> P;
#define MOD (1000000007ll)
#define l_ength size

bool flag = true;

int main(void) {
  ll n, a, b, x, y, m, p, q, r, i, j;
  vector<ll> v;
  cin >> n >> a >> b;
  if (a == 1ll) {
    if (b == n) {
      for (i = n; i > 0ll; --i) {
        cout << i << ((i) ? " " : "");
      }
      cout << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  x = a * b;
  y = a + b - 1ll;
  if (x < n || y > n) {
    cout << "-1" << endl;
    return 0;
  }
  x = n - b;
  y = a - 1ll;
  p = x / y;
  q = x % y;
  r = y - q;
  x = 0ll;
  for (i = 1ll; i <= r; ++i) {
    for (j = 0; j < p; ++j) {
      v.push_back(p * i - j);
      x = max(x, p * i - j);
    }
  }
  ++p;
  for (i = 1ll; i <= q; ++i) {
    for (j = 0; j < p; ++j) {
      v.push_back(x + p * i - j);
    }
  }
  for (i = 0ll; i < b; ++i) {
    v.push_back(n - i);
  }
  for (i = 0; i < n; ++i) {
    cout << ((i) ? " " : "") << v[i];
  }
  cout << endl;
  return 0;
}
Problem p03421 (C++)

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

int main() {
  int id, k, temp2, t, j, n, a, b, c[100010], i, temp;
  scanf("%d%d%d", &n, &a, &b);
  if ((b > (n - a + 1)) || (b < ((n + a - 1) / a)))
    cout << "-1\n";
  else {
    for (i = 1; i <= n; i++)
      c[i] = n - i + 1;
    for (i = 1; i <= n; i++)
      if (i + (n - i * a) < b)
        break;
    i--;
    id = i;
    for (j = 1; j <= id; j++)
      for (i = 1 + (j - 1) * a, k = 0; i <= (j * a + 1 + (j - 1) * a) / 2;
           i++, k++) {
        temp = c[j * a - k];
        c[j * a - k] = c[i];
        c[i] = temp;
      }
    b -= id;
    temp = n - id * a;
    temp -= (b - 1);
    for (j = id * a + 1, k = 1; k <= temp / 2; k++, j++) {
      temp2 = c[id * a + temp - k + 1];
      c[id * a + temp - k + 1] = c[j];
      c[j] = temp2;
    }
    for (i = 1; i <= n; i++)
      printf("%d ", c[i]);
    cout << endl;
  }
  return 0;
}

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

int main() {
  int id, k, temp2, t, j, n, a, b, c[600010], i, temp;
  scanf("%d%d%d", &n, &a, &b);
  if ((b > (n - a + 1)) || (b < ((n + a - 1) / a)))
    cout << "-1\n";
  else {
    for (i = 1; i <= n; i++)
      c[i] = n - i + 1;
    for (i = 1; i <= n; i++)
      if (i + (n - i * a) < b)
        break;
    i--;
    id = i;
    for (j = 1; j <= id; j++)
      for (i = 1 + (j - 1) * a, k = 0; i <= (j * a + 1 + (j - 1) * a) / 2;
           i++, k++) {
        temp = c[j * a - k];
        c[j * a - k] = c[i];
        c[i] = temp;
      }
    b -= id;
    temp = n - id * a;
    temp -= (b - 1);
    for (j = id * a + 1, k = 1; k <= temp / 2; k++, j++) {
      temp2 = c[id * a + temp - k + 1];
      c[id * a + temp - k + 1] = c[j];
      c[j] = temp2;
    }
    for (i = 1; i <= n; i++)
      printf("%d ", c[i]);
    cout << endl;
  }
  return 0;
}
Problem p03421 (C++)

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

using namespace std;

vector<int> v;
long long n, a, b;

int main() {
  scanf("%lld %lld %lld", &n, &a, &b);
  if (a > n || b > n) {
    puts("-1");
    return 0;
  }
  if (a + b - 1 > n || (n + b - 1) / b > a) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    v.push_back(i);
  reverse(v.begin(), v.begin() + b);
  if (a == 1) {
    for (int i = 0; i < v.size(); i++)
      printf("%d ", v[i]);
    puts("");
    return 0;
  }
  int need = (n - b) % (a - 1);
  for (int i = b; i < v.size();) {
    if (need) {
      reverse(v.begin() + i, v.begin() + i + (n - b) / (a - 1) + 1);
      need--;
      i += (n - b) / (a - 1) + 1;
    } else {
      reverse(v.begin() + i, v.begin() + i + (n - b) / (a - 1));
      i += a - 1;
    }
  }
  for (int i = 0; i < v.size(); i++)
    printf("%d ", v[i]);
  puts("");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <stdio.h>
#include <vector>

using namespace std;

vector<int> v;
long long n, a, b;

int main() {
  scanf("%lld %lld %lld", &n, &a, &b);
  if (a > n || b > n) {
    puts("-1");
    return 0;
  }
  if (a + b - 1 > n || (n + b - 1) / b > a) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    v.push_back(i);
  reverse(v.begin(), v.begin() + b);
  if (a == 1) {
    for (int i = 0; i < v.size(); i++)
      printf("%d ", v[i]);
    puts("");
    return 0;
  }
  int need = (n - b) % (a - 1);
  for (int i = b; i < v.size();) {
    if (need) {
      reverse(v.begin() + i, v.begin() + i + (n - b) / (a - 1) + 1);
      need--;
      i += (n - b) / (a - 1) + 1;
    } else {
      reverse(v.begin() + i, v.begin() + i + (n - b) / (a - 1));
      i += (n - b) / (a - 1);
    }
  }
  for (int i = 0; i < v.size(); i++)
    printf("%d ", v[i]);
  puts("");
  return 0;
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define Rep(i, a, b) for (register int i = (a), i##end = (b); i <= i##end; ++i)
#define Repe(i, a, b) for (register int i = (a), i##end = (b); i >= i##end; --i)
#define For(i, a, b) for (i = (a), i <= (b); ++i)
#define Forward(i, a, b) for (i = (a), i >= (b); --i)
#define Chkmax(a, b) a = a > b ? a : b
#define Chkmin(a, b) a = a < b ? a : b
template <typename T> inline void read(T &x) {
  T f = 1;
  x = 0;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + (c ^ 48);
  x *= f;
}
using namespace std;
const int MAXN = 1010;
static int n, a, b;
inline void init() {
  read(n);
  read(a);
  read(b);
}
static int p[MAXN];
inline void solve() {
  if (a + b > n + 1 || 1ll * a * b < n) {
    cout << -1 << endl;
    exit(0);
  } else {
    static int ps, cnt = n;
    while (cnt > a) {
      // cout<<cnt<<' '<<a<<endl;
      ps = cnt;
      if (cnt - a + 1 >= b) {
        Rep(i, cnt - b + 1, cnt) p[i] = ps--;
        cnt -= b;
      } else
        Rep(i, a, cnt) {
          p[i] = ps--;
          cnt = ps;
        }
      --a;
      // cout<<cnt<<' '<<a<<endl;
    }
    Rep(i, 1, cnt) p[i] = i;
    Rep(i, 1, n) cout << p[i] << ' ';
    cout << endl;
    ;
  }
}
int main() {
  init();
  solve();
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define Rep(i, a, b) for (register int i = (a), i##end = (b); i <= i##end; ++i)
#define Repe(i, a, b) for (register int i = (a), i##end = (b); i >= i##end; --i)
#define For(i, a, b) for (i = (a), i <= (b); ++i)
#define Forward(i, a, b) for (i = (a), i >= (b); --i)
#define Chkmax(a, b) a = a > b ? a : b
#define Chkmin(a, b) a = a < b ? a : b
template <typename T> inline void read(T &x) {
  T f = 1;
  x = 0;
  char c;
  for (c = getchar(); !isdigit(c); c = getchar())
    if (c == '-')
      f = -1;
  for (; isdigit(c); c = getchar())
    x = x * 10 + (c ^ 48);
  x *= f;
}
using namespace std;
const int MAXN = 301010;
static int n, a, b;
inline void init() {
  read(n);
  read(a);
  read(b);
}
static int p[MAXN];
inline void solve() {
  if (a + b > n + 1 || 1ll * a * b < n) {
    cout << -1 << endl;
    exit(0);
  } else {
    static int ps, cnt = n;
    while (cnt > a) {
      // cout<<cnt<<' '<<a<<endl;
      ps = cnt;
      if (cnt - a + 1 >= b) {
        Rep(i, cnt - b + 1, cnt) p[i] = ps--;
        cnt -= b;
      } else
        Rep(i, a, cnt) {
          p[i] = ps--;
          cnt = ps;
        }
      --a;
      // cout<<cnt<<' '<<a<<endl;
    }
    Rep(i, 1, cnt) p[i] = i;
    Rep(i, 1, n) cout << p[i] << ' ';
    cout << endl;
    ;
  }
}
int main() {
  init();
  solve();
  return 0;
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
const int INF = 0x3f3f3f3f;
// const ll INF=1000000000000000000;

// priority_queue<int, vector<int>, greater<int> >p;
int s[500005];
int main() {
  ll n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  ll sum = n - a;
  if (a + b - 1 > n || a * b < n) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    s[i] = i;
  for (int i = n; i > 0; i -= b) {
    int t = b - 1;
    if (sum <= t) {
      t = sum;
      for (int j = i; j > i - b; j--) {
        s[j] = i - t;
        t--;
      }
      break;
    }
    sum -= t;
    for (int j = i; j > i - b; j--) {
      s[j] = i - t;
      t--;
    }
  }
  printf("%d", s[1]);
  for (int i = 2; i <= n; i++)
    printf(" %d", s[i]);
  printf("\n");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
using namespace std;
#define mod 1000000007
#define PI acos(-1.0)
typedef long long ll;
const int INF = 0x3f3f3f3f;
// const ll INF=1000000000000000000;

// priority_queue<int, vector<int>, greater<int> >p;
int s[500005];
int main() {
  ll n, a, b;
  scanf("%lld%lld%lld", &n, &a, &b);
  ll sum = n - a;
  if (a + b - 1 > n || a * b < n) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; i++)
    s[i] = i;
  for (int i = n; i > 0; i -= b) {
    int t = b - 1;
    if (sum <= t) {
      t = sum;
      for (int j = i; j > i - sum - 1; j--) {
        s[j] = i - t;
        t--;
      }
      break;
    }
    sum -= t;
    for (int j = i; j > i - b; j--) {
      s[j] = i - t;
      t--;
    }
  }
  printf("%d", s[1]);
  for (int i = 2; i <= n; i++)
    printf(" %d", s[i]);
  printf("\n");
  return 0;
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):

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

int N, A, B;
int num;

vector<int> ans;

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

  if (A + B - 1 > N) {
    printf("-1\n");
    return 0;
  }

  num = N + 1;
  for (int i = 0; i < (N - B) / (A - 1); i++) {
    num -= A;
    for (int j = 0; j < A; j++) {
      ans.push_back(num + j);
    }
  }
  if (num < 0) {
    printf("-1\n");
    return 0;
  }
  if ((N - B) % (A - 1)) {
    num -= (N - B) % (A - 1) + 1;
    for (int i = 0; i < (N - B) % (A - 1) + 1; i++) {
      ans.push_back(num + i);
    }
  }
  num--;
  while (num >= 1) {
    ans.push_back(num);
    num--;
  }
  if (ans.size() > N) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < ans.size(); i++) {
    printf("%d", ans[i]);
    if (i != ans.size() - 1)
      printf(" ");
  }
  printf("\n");
  return 0;
}


Fixed submission:

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

int N, A, B;
int num;

vector<int> ans;

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

  if (A + B - 1 > N) {
    printf("-1\n");
    return 0;
  }

  if (A == 1) {
    if (B != N)
      printf("-1\n");
    else {
      for (int i = 0; i < B; i++) {
        printf("%d", N - i);
        if (i != B - 1)
          printf(" ");
      }
      printf("\n");
    }
    return 0;
  }

  num = N + 1;
  for (int i = 0; i < (N - B) / (A - 1); i++) {
    num -= A;
    for (int j = 0; j < A; j++) {
      ans.push_back(num + j);
    }
  }
  if (num < 0) {
    printf("-1\n");
    return 0;
  }
  if ((N - B) % (A - 1)) {
    num -= (N - B) % (A - 1) + 1;
    for (int i = 0; i < (N - B) % (A - 1) + 1; i++) {
      ans.push_back(num + i);
    }
  }
  num--;
  while (num >= 1) {
    ans.push_back(num);
    num--;
  }
  if (ans.size() > N) {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < ans.size(); i++) {
    printf("%d", ans[i]);
    if (i != ans.size() - 1)
      printf(" ");
  }
  printf("\n");
  return 0;
}
Problem p03421 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  if (!(N <= A * B && A + B - 1 <= N)) {
    cout << -1 << endl;
    return 0;
  }
  vector<ll> v[B];
  ll low = 1, up = N;
  for (ll i = B - 1; 0 <= i; i--) {
    v[i].push_back(B - i);
    low = B - i;
  }
  for (ll i = N; v[0].size() < A; i--) {
    v[0].push_back(i);
    up = i;
  }
  sort(v[0].begin(), v[0].end());
  ll index = B - 1;
  for (ll i = low + 1; i < up; i++) {
    v[index].push_back(i);
    index--;
    if (!index)
      index = B - i;
  }
  for (ll i = 0; i < B; i++)
    for (ll u : v[i])
      cout << u << " ";
  cout << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  if (!(N <= A * B && A + B - 1 <= N)) {
    cout << -1 << endl;
    return 0;
  }
  vector<ll> v[B];
  ll low = 1, up = N;
  for (ll i = B - 1; 0 <= i; i--) {
    v[i].push_back(B - i);
    low = B - i;
  }
  for (ll i = N; v[0].size() < A; i--) {
    v[0].push_back(i);
    up = i;
  }
  sort(v[0].begin(), v[0].end());
  ll index = B - 1;
  for (ll i = low + 1; i < up; i++) {
    v[index].push_back(i);
    index--;
    if (!index)
      index = B - 1;
  }
  for (ll i = 0; i < B; i++)
    for (ll u : v[i])
      cout << u << " ";
  cout << endl;
  return 0;
}