alexjercan/bugnet huggingface dataset:
Problem p00427 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 11000

int N, K, M, R;
int ans[NUM];

void calc(int bunshi, int bunbo) {

  for (int i = 0; i < NUM; i++) {
    ans[i] += bunshi / bunbo;
    bunshi %= bunbo;
    bunshi *= 10;
    if (bunshi == 0)
      return;
  }
}

void func() {

  for (int i = 0; i < NUM; i++)
    ans[i] = 0;

  if (M == 0) {
    calc(1, N);
  } else { // M == 1
    calc(1, N);
    for (int a = 1; a <= N - 1; a++) {
      calc(1, N * a);
    }
  }

  for (int a = NUM - 1; a >= 1; a--) {
    if (ans[a] >= 10) {
      ans[a - 1] += ans[a] / 10;
      ans[a] %= 10;
    }
  }

  printf("%d.", ans[0]);
  for (int a = 1; a <= R; a++) {
    printf("%d", ans[a]);
  }
  printf("\\n");
}

int main() {

  while (true) {
    scanf("%d %d %d %d", &N, &K, &M, &R);
    if (N == 0 && K == 0 && M == 0 && R == 0)
      break;

    func();
  }

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

#define NUM 1100

int N, K, M, R;
int ans[NUM];

void calc(int bunshi, int bunbo) {

  for (int i = 0; i < NUM; i++) {
    ans[i] += bunshi / bunbo;
    bunshi %= bunbo;
    bunshi *= 10;
    if (bunshi == 0)
      return;
  }
}

void func() {

  for (int i = 0; i < NUM; i++)
    ans[i] = 0;

  if (M == 0) {
    calc(1, N);
  } else { // M == 1
    calc(1, N);
    for (int a = 1; a <= N - 1; a++) {
      calc(1, N * a);
    }
  }

  for (int a = NUM - 1; a >= 1; a--) {
    if (ans[a] >= 10) {
      ans[a - 1] += ans[a] / 10;
      ans[a] %= 10;
    }
  }

  printf("%d.", ans[0]);
  for (int a = 1; a <= R; a++) {
    printf("%d", ans[a]);
  }
  printf("\\n");
}

int main() {

  while (true) {
    scanf("%d %d %d %d", &N, &K, &M, &R);
    if (N == 0 && K == 0 && M == 0 && R == 0)
      break;

    func();
  }

  return 0;
}
Problem p00427 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
using namespace std;

int answer[10500];

void add_gyakusu(int x) {
  int t = 1;
  for (int i = 0; i < 10200; i++) {
    answer[i] += t / x;
    t %= x;
    t *= 10;
  }
}

void kuriagari() {
  for (int i = 10199; i >= 0; i--) {
    answer[i - 1] += answer[i] / 10;
    answer[i] %= 10;
  }
}

int main() {
  int n, k, m, r;
  while (true) {
    cin >> n >> k >> m >> r;
    fill(answer, answer + 10500, 0);
    if (n + k + m + r == 0)
      return 0;
    add_gyakusu(n);
    if (m == 1) {
      for (int i = 1; i < n; i++) {
        add_gyakusu(i * n);
      }
    }
    kuriagari();
    cout << answer[0] << '.';
    for (int i = 1; i <= r; i++) {
      cout << answer[i];
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;

int answer[10500];

void add_gyakusu(int x) {
  int t = 1;
  for (int i = 0; i < 10200; i++) {
    answer[i] += t / x;
    t %= x;
    t *= 10;
  }
}

void kuriagari() {
  for (int i = 10199; i >= 0; i--) {
    answer[i - 1] += answer[i] / 10;
    answer[i] %= 10;
  }
}

int main() {
  int n, k, m, r;
  while (true) {
    cin >> n >> k >> m >> r;
    fill(answer, answer + 10500, 0);
    if (n + k + m + r == 0)
      return 0;
    add_gyakusu(n);
    if (m == 1) {
      for (int i = 1; i < n;) {
        add_gyakusu(i * n);
      }
    }
    kuriagari();
    cout << answer[0] << '.';
    for (int i = 1; i <= r; i++) {
      cout << answer[i];
    }
    cout << endl;
  }
}
Problem p00427 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iomanip>
#include <iostream>
using namespace std;

int ans[11000];

int kansu(long long int a, long long int b) {

  for (int i = 0; i < 11000; i++) {

    ans[i] += a / b;
    a = a % b * 10;
  }

  for (int i = 11000 - 1; i > 0; i--) {

    ans[i - 1] += ans[i] / 10;
    ans[i] = ans[i] % 10;
  }

  return a;
}

int main() {

  while (true) {

    long long int n, k, m, r, a, b;

    cin >> n >> k >> m >> r;

    if (n == 0)
      break;

    for (int i = 0; i < 11000; i++) {

      ans[i] = 0;
    }

    if (m == 0) {

      kansu(1, n);

    } else {

      kansu(1, n);

      for (int i = 1; i < n; i++) {

        kansu(1, n * i);
      }
    }

    for (int i = 0; i < r + 1; i++) {

      cout << ans[i];
      if (i == 0)
        cout << ".";
    }

    cout << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iomanip>
#include <iostream>
using namespace std;

int kansu(int a, int b) {

  if (a < b)
    swap(a, b);

  while (a != b) {

    a -= b;
    if (a < b)
      swap(a, b);
  }

  return a;
}

int main() {

  while (true) {

    long long int n, k, m, r, a, b;

    cin >> n >> k >> m >> r;

    if (n == 0)
      break;

    double ans;

    if (m == 0) {

      a = 1;
      b = n;

    } else {

      a = 1;
      b = n;

      for (int i = 1; i < n; i++) {

        long long int x = kansu(b, i);
        long long int y = kansu(b / x * i, b / x + i / x);
        a = (b / x + i / x) / y;
        b = b / x * i / y;
      }
    }

    cout << fixed << setprecision(r) << 1.00 * a / b;
  }

  return 0;
}
Problem p00427 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repa(i, s, e) for (int i = s; i <= e; i++)
#define repd(i, s, e) for (int i = s; i >= e; i--)

const int R_MAX = 100011;
int n, k, m, r;
int ans[R_MAX];

void add(int d) {
  ans[0] += 1 / d;
  int res = 1 % d;
  repa(i, 1, r + 10) {
    res *= 10;
    ans[i] += res / d;
    if (res % d == 0)
      break;
    res = res % d;
  }

  repd(i, r + 10, 0) {
    if (ans[i] >= 10) {
      int u = ans[i] / 10;
      ans[i] = ans[i] % 10;
      ans[i - 1] += u;
    }
  }
}

void div(int d) {
  int res = 0;
  rep(i, r + 10) {
    res += ans[i];
    ans[i] = res / d;
    res = res % d;
    res *= 10;
  }
}

int main() {
  while (cin >> n >> k >> m >> r, n | k | m | r) {
    memset(ans, 0, sizeof(int) * R_MAX);
    if (m == 0) {
      add(n);
    } else {
      repa(i, 1, n - 1) { add(i); }
      div(n);
      add(n);
    }

    printf("%d.", ans[0]);
    repa(i, 1, r) printf("%d", ans[i]);
    printf("\\n");
  }
}

Error: TLE

Fixed submission:


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repa(i, s, e) for (int i = s; i <= e; i++)
#define repd(i, s, e) for (int i = s; i >= e; i--)

const int R_MAX = 100010;
int n, k, m, r;
int ans[R_MAX];

void add(int d) {
  ans[0] += 1 / d;
  int res = 1 % d;
  repa(i, 1, R_MAX - 1) {
    res *= 10;
    ans[i] += res / d;
    if (res % d == 0)
      break;
    res = res % d;
  }

  repd(i, R_MAX - 1, 0) {
    if (ans[i] >= 10) {
      int u = ans[i] / 10;
      ans[i] = ans[i] % 10;
      ans[i - 1] += u;
    }
  }
}

void div(int d) {
  int res = 0;
  rep(i, R_MAX) {
    res += ans[i];
    ans[i] = res / d;
    res = res % d;
    res *= 10;
  }
}

int main() {
  while (cin >> n >> k >> m >> r, n | k | m | r) {
    memset(ans, 0, sizeof(int) * R_MAX);
    if (m == 0) {
      add(n);
    } else {
      repa(i, 1, n - 1) { add(i); }
      div(n);
      add(n);
    }

    printf("%d.", ans[0]);
    repa(i, 1, r) printf("%d", ans[i]);
    printf("\\n");
  }
}
Problem p00428 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <string.h>
using namespace std;

typedef pair<int, int> pii;

int n, m, x;
const int MAX_N = 1000;
const int MAX_M = 100;

int table[MAX_M];

int main() {
  while (cin >> n >> m, n | m) {
    for (int j = 0; j < m; j++)
      table[j] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> x;
        if (x == 1)
          table[j]++;
      }
    }

    multimap<int, int, greater<int>> rank;
    for (int j = 0; j < m; j++) {
      rank.insert(pii(table[j], j + 1));
    }

    multimap<int, int>::const_iterator iter = rank.begin();
    while (iter != rank.end()) {
      int r = (*iter).second;
      if (iter == rank.begin())
        printf("%d", r);
      else
        printf(" %d", r);
      ++iter;
    }
    printf("\\n");
  }
}

Error: WA

Fixed submission:

#include <iostream>
#include <map>
#include <string.h>
using namespace std;

typedef pair<int, int> pii;

int n, m, x;
const int MAX_N = 1000;
const int MAX_M = 100;

int table[MAX_M];

int main() {
  while (cin >> n >> m, n | m) {
    memset(table, 0, sizeof(int) * n * m);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> x;
        if (x == 1)
          table[j]++;
      }
    }

    multimap<int, int, greater<int>> rank;
    for (int j = 0; j < m; j++) {
      rank.insert(pii(table[j], j + 1));
    }

    multimap<int, int>::const_iterator iter = rank.begin();
    while (iter != rank.end()) {
      int r = (*iter).second;
      printf("%d ", r);
      ++iter;
    }
    printf("\\n");
  }
}
Problem p00428 (C++) — buggy submission, verdict: Time Limit Exceeded

// Bokan ga bokka--nn!!
// Daily Lunch Special Tanoshii !!
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d", &x)
#define rep(i, x) for (int i = 0; i < x; i++)
int num[1005][105];
int main() {
  int n, m;
  while (1) {
    scanf("%d %d", &n, &m);
    if (!n)
      return 0;
    int val[105] = {};
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &num[i][j]);
        val[j] += num[i][j];
      }
    }
    bool f = false;
    for (int i = n; i >= 0; i--) {
      for (int j = 0; j < m; j++) {
        if (val[j] == i && !f) {
          cout << j + 1;
          f = true;
        } else if (val[j] == i) {
          cout << " " << j + 1;
        }
      }
    }
    puts("");
  }
}

Error: TLE

Fixed submission:

// Bokan ga bokka--nn!!
// Daily Lunch Special Tanoshii !!
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define s(x) scanf("%d", &x)
#define rep(i, x) for (int i = 0; i < x; i++)
int num[1005][105];
int main() {
  int n, m;
  while (1) {
    scanf("%d %d", &n, &m);
    int val[105] = {};
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        scanf("%d", &num[i][j]);
        val[j] += num[i][j];
      }
    }
    bool f = false;
    for (int i = n; i >= 0; i--) {
      for (int j = 0; j < m; i++) {
        if (val[j] == i && !f)
          cout << j + 1;
        else if (val[j] == i)
          cout << " " << j + 1;
      }
    }
    puts("");
  }
}
Problem p00428 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <stack>

#define rep(i, x) for (int i = 0; i < x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rep_to(a, i, x) for (int i = a; i < x; i++)

using namespace std;

int main() {
  int n, m, set;
  while (cin >> n >> m && n) {
    int count[10000] = {};
    int number[10000] = {};

    rep(i, m) number[i] = i + 1;
    rep(i, n) {
      rep(j, m) {
        cin >> set;
        count[j] += set;
      }
    }
    rep(i, m) {
      rep_to(i, j, m) {
        if (count[i] < count[j]) {
          swap(count[j], count[i]);
          swap(number[j], number[i]);
        } else if (count[i] == count[j] && number[i] > number[j])
          swap(number[j], number[i]);
      }
    }
    rep(i, m) {
      cout << number[i];
      if (i < m - 1)
        cout << " ";
      else
        cout << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <stack>

#define rep(i, x) for (int i = 0; i < x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rep_to(a, i, x) for (int i = a; i < x; i++)

using namespace std;

int main() {
  ifstream fin("input.txt");
  ofstream fout("output.txt");

  while (1) {
    int count[100000] = {}, set = 0;
    int number[100000] = {};
    int n = 1, m = 1;

    fin >> n >> m;
    if (n == 0 || m == 0)
      break;
    rep(i, n) {
      rep(j, m) {
        fin >> set;
        count[j] += set;
      }
    }
    rep(i, m) number[i] = i;
    rep(i, m) {
      rep_to(i, j, m) {
        if (count[i] < count[j]) {
          swap(count[j], count[i]);
          swap(number[j], number[i]);
        }
      }
    }
    rep(i, m) {
      if (i < m - 1)
        fout << number[i] + 1 << " ";
      else
        fout << number[i] + 1 << endl;
    }
  }
  fin.close();
  fout.close();
  return 0;
}
Problem p00428 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {

  int x, y;
  // FILE *fp, *op;

  // fp = fopen("input.txt","r");
  // op = fopen("output.txt","w");

  while (1) {

    // fscanf(fp,"%d %d",&y,&x);
    scanf("%d %d", &y, &x);
    if (y == 0 && x == 0)
      break;

    int data[y][x];

    for (int i = 0; i < y; i++) {
      for (int j = 0; j < x; j++) {
        // fscanf(fp,"%d",&data[i][j]);
        scanf("%d", &data[i][j]);
      }
    }
    int sum[x];
    int sub[x];
    for (int i = 0; i < x; i++)
      sum[i] = 0;

    for (int i = 0; i < x; i++) {
      for (int j = 0; j < y; j++) {
        sum[i] += data[j][i];
      }
    }
    for (int i = 0; i < x; i++) {
      sub[i] = sum[i];
    }

    sort(sum, sum + x);
    reverse(sum, sum + x);

    for (int i = 0; i < x; i++) {
      for (int j = 0; j < x; j++) {
        if (sum[i] == sub[j]) {
          sub[j] = -1;
          // fprintf(op,"%d",j+1);
          printf("%d", j + 1);
          break;
        }
      }
      if (i != x - 1)
        printf(" ");
    }
    // fprintf(op,"\\n");
    printf("\\n");
  }
  // fclose(fp);
  // fclose(op);

  return 0;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {

  int x, y;
  FILE *fp, *op;

  fp = fopen("input.txt", "r");
  op = fopen("output.txt", "w");

  while (1) {

    fscanf(fp, "%d %d", &y, &x);
    if (y == 0 && x == 0)
      break;

    int data[y + 100][x + 100];

    for (int i = 0; i < y; i++) {
      for (int j = 0; j < x; j++) {
        fscanf(fp, "%d", &data[i][j]);
      }
    }
    int sum[x];
    int sub[x];
    for (int i = 0; i < x; i++)
      sum[i] = 0;

    for (int i = 0; i < x; i++) {
      for (int j = 0; j < y; j++) {
        sum[i] += data[j][i];
      }
    }
    for (int i = 0; i < x; i++) {
      sub[i] = sum[i];
    }

    sort(sum, sum + x);
    reverse(sum, sum + x);

    for (int i = 0; i < x; i++) {
      for (int j = 0; j < x; j++) {
        if (sum[i] == sub[j]) {
          sub[j] = -1;
          fprintf(op, "%d", j + 1);
          break;
        }
      }
      if (i != x - 1)
        fprintf(op, " ");
    }
    fprintf(op, "\\n");
  }
  fclose(fp);
  fclose(op);

  return 0;
}
Problem p00428 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
const double PI = acos(-1);

int main() {
  int n, m;
  while (cin >> n >> m, n) {
    vector<pair<int, int>> v(m);
    for (int i = 1; i <= m; ++i) {
      v[i - 1].second = -i;
    }
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        int k;
        cin >> k;
        v[j].first += k;
      }
    }
    stable_sort(v.rbegin(), v.rend());
    for (int i = 0; i < m; ++i) {
      if (i != m - 1)
        cout << -v[i].second << " ";
      else
        cout << -v[i].second;
    }
    cout << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  int q[100] = {0};
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 100; ++j) {
      int o;
      cin >> o;
      if (o == 1) {
        q[j] += 1;
      }
    }
  }
  for (int i = 100; i >= 0; ++i) {
    for (int j = 0; j < 100; ++j) {
      if (q[j] == i) {
        cout << j + 1 << " " << endl;
      }
    }
  }
  return 0;
}
Problem p00428 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;
int main(void) {

  int n, m;
  int a;
  int b[1000] = {0};
  int c[1000] = {0};
  int v = 0;
  int i, j;
  for (;;) {

    cin >> n;
    cin >> m;
    for (i = 0; i < 1000; i++) {
      b[i] = 0;
      v = 0;
    }
    if (n == 0 && m == 0)
      break;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {

        cin >> a;
        b[j] += a;
      }
    }
    for (i = n; i >= 0; i--) {
      for (j = 0; j < m; j++) {

        if (b[j] == i) {
          c[v] = j;
          v++;
        }
      }
    }
    for (j = 0; j < m; j++) {

      cout << c[j] + 1;
      if (j == m - 1)
        cout << endl;
      else
        cout << " ";
    }
  }

  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;
int main(void) {

  int n, m;
  int a;
  int b[100] = {0};
  int c[100] = {0};
  int v = 0;
  int i, j;
  for (;;) {
    scanf("%d%d", &n, &m);
    // cin >> n;
    // cin >> m;
    if (n == 0 && m == 0)
      break;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        scanf("%d", &a);
        // cin >> a;
        b[j] += a;
      }
    }
    for (i = n; i > 0; i--) {
      for (j = 0; j < m; j++) {

        if (b[j] == i) {
          c[v] = j;
          v++;
        }
      }
    }
    for (j = 0; j < m; j++) {
      printf("%d ", c[j] + 1);
      printf("\\n");
      // cout << c[j]+1 << endl;
    }
  }

  return 0;
}
Problem p00428 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b, a, b) {
    int data[1200];

    for (int i = 0; i < b; i++)
      data[i] = 0;

    for (int i = 0; i < a; i++) {
      for (int j = 0; j < b; j++) {
        int c;
        cin >> c;
        data[j] += c;
      }
    }

    vector<int> ans;

    for (int i = a; i > -1; i--) {
      for (int j = 0; j < b; j++) {
        if (data[j] == i) {
          ans.push_back(j + 1);
        }
      }
    }

    for (int i = 0; i < b; i++) {
      cout << ans[i];
      if (i == b - 1)
        cout << endl;
      else
        cout << ' ';
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b, a, b) {
    int data[120] = {};

    for (int i = 0; i < a; i++) {
      for (int j = 0; j < b; j++) {
        int c;
        cin >> c;
        data[j] += c;
      }
    }

    vector<int> ans;

    for (int i = b; i > -1; i--) {
      for (int j = 0; j < b; j++) {
        if (data[j] == i) {
          ans.push_back(j + 1);
        }
      }
    }

    for (int i = 0; i < b; i++) {
      cout << ans[i];
      if (i == b - 1)
        cout << endl;
      else
        cout << ' ';
    }
  }
  return 0;
}
Problem p00428 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int main() {
  int a, b, i, j, n, m, *p, *pl;

  while (1) {
    cin >> n;

    if (n != 0) {
      cin >> m;
      p = new int[m];
      pl = new int[m];

      for (i = 0; i < m; i++) {
        p[i] = 0;
        pl[i] = i + 1;
      }

      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          cin >> a;
          if (a) {
            p[j]++;
          }
        }
      }

      i = 0;
      while (i < m - 1) {
        if (p[i] < p[i + 1]) {
          b = p[i + 1];
          p[i + 1] = p[i];
          p[i] = b;

          b = pl[i + 1];
          pl[i + 1] = pl[i];
          pl[i] = b;

          i = 0;
          continue;
        }

        i++;
      }

      for (i = 0; i < m; i++) {
        cout << pl[i];
        if (i == m - 1) {
          cout << endl;
        } else {
          cout << " ";
        }
      }
    } else {
      break;
    }
  }

  return 0;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <iostream>

using namespace std;

int main() {
  int a, b, i, j, n, m, *p, *pl;

  while (1) {
    cin >> n;

    if (n != 0) {
      cin >> m;
      p = new int[m];
      pl = new int[m];
      fill(p, p + m, 0);

      for (i = 0; i < n; i++) {
        for (j = 0; j < m; j++) {
          cin >> a;
          if (a) {
            p[j]++;
          }
        }
      }

      for (i = 0; i < m; i++) {
        pl[i] = i + 1;
      }

      i = 0;
      while (1) {
        if (p[i] < p[i + 1]) {
          b = p[i + 1];
          p[i + 1] = p[i];
          p[i] = b;

          b = pl[i + 1];
          pl[i + 1] = pl[i];
          pl[i] = b;

          i = 0;
          continue;
        }

        i++;
        if (i > m) {
          break;
        }
      }

      for (i = 0; i < m; i++) {
        cout << pl[i];
        if (i == m - 1) {
          cout << endl;
        } else {
          cout << " ";
        }
      }

      delete[] p;
      delete[] pl;
    } else {
      break;
    }
  }

  return 0;
}