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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int d[1000000];
int main() {
  int n, q;
  while (cin >> n >> q && n != 0 && q != 0) {
    fill(d, d + 1000000, 0);
    int m, d2, sum[2] = {-1, 0}, maxd = -1;
    for (int i = 0; i < n; i++) {
      cin >> m;
      for (int i = 0; i < m; i++) {
        cin >> d2;
        d[d2]++;
        maxd = max(d2, maxd);
      }
    }
    for (int i = 0; i <= maxd; i++) {
      if (d[i] > sum[0]) {
        sum[0] = d[i];
        sum[1] = i;
      }
    }
    if (sum[0] >= q)
      cout << sum[1] << endl;
    else
      cout << 0 << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoi


Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int a[1000];
int main() {
  int m, q;
  while (cin >> m >> q && m != 0) {
    fill(a, a + 1000, 0);
    for (int i = 0; i < m; i++) {
      string b, h = "";
      getline(cin, b);
      b += " ";
      for (int j = 0; j < b.length(); j++) {
        if (b[j] == ' ') {
          int c = stoi(h);
          a[c]++;
          h = "";
        } else
          h += b[j];
      }
    }
    int d = 0;
    for (int i = 100; i >= 0; i--) {
      if (a[i] >= q) {
        d = i;
        break;
      }
    }
    cout << d << endl;
  }
}
Problem p00705 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int n, q;
  for (; cin >> n >> q;) {
    if (n == 0)
      break;
    int m, t;
    vector<int> k(101);
    k[0] = q - 1;
    for (; n--;) {
      cin >> m;
      for (; m--; k[t]++)
        cin >> t;
    }
    int v = 0, r = 0;
    for (int i = 0; i < 101; i++)
      if (k[i] > v)
        v = k[i], r = i;
    cout << r << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, q, m, date, ans;
  while (true) {
    cin >> n >> q;
    int N[50] = {0};
    if (n == 0 && q == 0) {
      break;
    }
    for (int i = 0; i < n; ++i) {
      cin >> m;
      for (int j = 0; j < m; ++j) {
        cin >> date;
        N[date - 1] += 1;
      }
    }
    ans = 0;
    for (int i = 49; i >= q - 1; --i) {
      if (N[i] >= q) {
        q = N[i];
        ans = i;
      }
    }
    cout << ans << endl;
  }
}
Problem p00705 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, q, m, date, ans, max;
  while (true) {
    cin >> n >> q;
    int N[100] = {0};
    if (n == 0 && q == 0) {
      break;
    }
    for (int i = 0; i < n; ++i) {
      cin >> m;
      for (int j = 0; j < m; ++j) {
        cin >> date;
        N[date - 1] += 1;
      }
    }
    max = 0;
    ans = 0;
    for (int i = 99; i >= 0; --i) {
      if (N[i] >= max && N[i] >= q) {
        max = N[i];
        ans = i + 1;
      }
    }
    cout << ans << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int n, q, m, date, ans, max;
  while (true) {
    cin >> n >> q;
    int N[50] = {0};
    if (n == 0 && q == 0) {
      break;
    }
    for (int i = 0; i < n; ++i) {
      cin >> m;
      for (int j = 0; j < m; ++j) {
        cin >> date;
        N[date - 1] += 1;
      }
    }
    max = 0;
    ans = 0;
    for (int i = n - 1; i >= 0; --i) {
      if (N[i] >= max && N[i] >= q) {
        max = N[i];
        ans = i + 1;
      }
    }
    cout << ans << endl;
  }
}
Problem p00705 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int x[1000], y[1000], a, b, c, d, m;
int main() {
  while (true) {
    m = 0;
    memset(x, 0, 4000);
    memset(y, 0, 4000);
    cin >> a >> b;
    if (a == 0) {
      break;
    }
    for (int i = 0; i < a; i++) {
      cin >> c;
      for (int j = 0; j < c; j++) {
        cin >> d;
        m = max(m, d);
        x[d]++;
        y[d]++;
      }
    }
    sort(y, y + m + 1);
    if (y[m] < b) {
      cout << '0' << endl;
    } else {
      for (int i = 0; i < 999; i++) {
        if (y[m] == x[i]) {
          cout << i << endl;
          goto F;
        }
      }
    }
  F:;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;
int x[1000], a, b, c, d;
int main() {
  while (true) {
    memset(x, 0, 4000);
    cin >> a >> b;
    for (int i = 0; i < a; i++) {
      cin >> c;
      for (int j = 0; j < c; j++) {
        cin >> d;
        x[d]++;
      }
    }
    sort(x, x + a);
    if (x[0] < b) {
      x[0] = 0;
    }
    cout << x[0] << endl;
  }
}
Problem p00705 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define loop(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, b) loop(i, 0, b)
#define all(c) (c).begin(), (c).end()

typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
  int n, q;
  while (cin >> n >> q, n + q) {
    int s[100] = {};
    rep(i, n) {
      int m;
      cin >> m;
      rep(j, m) {
        int d;
        cin >> d;
        s[d - 1]++;
      }
    }

    int cnt = -1, p;
    rep(i, 100) {
      if (cnt < s[i]) {
        cnt = s[i];
        p = i + 1;
      }
    }
    if (cnt >= q)
      cout << p << endl;
    else
      cout << 0 << endl;
  }
}

Error: TLE

Fixed submission:

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

#define loop(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, b) loop(i, 0, b)
#define all(c) (c).begin(), (c).end()

typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
  int n, q;
  while (cin >> n >> q, n + q) {
    int s[10] = {};
    rep(i, n) {
      int m;
      cin >> m;
      rep(j, m) {
        int d;
        cin >> d;
        s[d - 1]++;
      }
    }

    int cnt = -1, p;
    rep(i, 10) {
      if (cnt < s[i]) {
        cnt = s[i];
        p = i + 1;
      }
    }
    if (cnt >= q)
      cout << p << endl;
    else
      cout << 0 << endl;
  }
}
Problem p00705 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int N, Q;
    cin >> N >> Q;

    if (N == 0 && Q == 0) {
      break;
    }

    int day[120] = {0};
    int ans = 0;
    int num = 0;

    for (int i = 0; i < N; i++) {
      int M;
      cin >> M;

      for (int j = 0; j < M; j++) {
        int temp;
        cin >> temp;
        day[temp]++;
      }
    }

    for (int i = 1; i < 120; i++) {
      if (day[i] >= Q) {
        if (day[i] > num) {
          ans = i;
          num = day[i];
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int N, Q;
    cin >> N >> Q;

    if (N == 0 && Q == 0) {
      break;
    }

    int day[51] = {0};
    int ans = 0;
    int num = 0;

    for (int i = 0; i < N; i++) {
      int M;
      cin >> M;

      for (int j = 0; j < M; j++) {
        int temp;
        cin >> temp;
        day[temp]++;
      }
    }

    for (int i = 1; i < 51; i++) {
      if (day[i] >= Q) {
        if (day[i] > num) {
          ans = i;
          num = day[i];
        }
      }
    }

    cout << ans << endl;
  }

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

#include <stdio.h>
#pragma warning(disable : 4996)
int N, Q, M, D, R[100];
int main() {
  while (true) {
    scanf("%d%d", &N, &Q);
    if (N == 0 && Q == 0)
      break;
    for (int i = 0; i < 100; i++)
      R[i] = 0;
    for (int i = 0; i < N; i++) {
      scanf("%d", &M);
      for (int j = 0; j < M; j++) {
        scanf("%d", &D);
        R[--D]++;
      }
    }
    int ptr = 0;
    for (int i = 0; i < 100; i++) {
      if (R[i] >= Q) {
        if (ptr == 0) {
          ptr = i + 1;
        } else if (R[i] > R[ptr - 1]) {
          ptr = i + 1;
        }
      }
    }
    printf("%d\\n", ptr);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
#pragma warning(disable : 4996)
int N, Q, M, D, R[100];
int main() {
  while (true) {
    scanf("%d%d", &N, &Q);
    if (N == 0 && Q == 0)
      break;
    for (int i = 0; i < 100; i++)
      R[i] = 0;
    for (int i = 0; i < N; i++) {
      scanf("%d", &M);
      for (int j = 0; j < M; j++) {
        scanf("%d", &D);
        R[--D]++;
      }
    }
    int ptr = 0;
    for (int i = 0; i < 100;) {
      if (R[i] >= Q) {
        if (ptr == 0) {
          ptr = i + 1;
        } else if (R[i] > R[ptr - 1]) {
          ptr = i + 1;
        }
      }
    }
    printf("%d\\n", ptr);
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int N, Q;
    cin >> N >> Q;
    if (N == 0)
      break;
    int list[101], i, j;
    for (i = 1; i < 101; i++) {
      list[i] = Q;
    }
    for (i = 0; i < N; i++) {
      int M, date;
      cin >> M;
      for (j = 0; j < M; j++) {
        cin >> date;
        list[date]--;
      }
    }
    int ans = 0;
    for (i = 0; i < 101; i++) {
      if (list[i] <= 0) {
        if (ans == 0 || list[i] < list[ans]) {
          ans = i;
        }
      }
    }
    cout << ans << endl;
  }
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (1) {
    int N, Q;
    cin >> N >> Q;
    if (N == 0)
      break;
    int list[101], i, j;
    for (i = 1; i < 101; i++) {
      list[i] = Q;
    }
    for (i = 0; i < N; i++) {
      int M, date[M];
      cin >> M;
      for (j = 0; j < M; j++) {
        cin >> date[j];
        list[date[j]]--;
      }
    }
    int ans = 0;
    for (i = 0; i < 101; i++) {
      if (list[i] <= 0) {
        if (ans == 0 || list[i] < list[ans]) {
          ans = i;
        }
      }
    }
    cout << ans << endl;
  }
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

#include <fstream>
#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main() {
  int N, Q;
  while (cin >> N >> Q, N | Q) {
    int p_max = 0;
    vector<int> date(110);
    for (int i = 0; i < N; i++) {
      int M;
      cin >> M;
      for (int j = 0; j < M; j++) {
        int d;
        cin >> d;
        date[d]++;
        p_max = max(p_max, date[d]);
      }
    }
    if (p_max < Q) {
      cout << 0 << endl;
    } else {
      for (int i = 0; i < 110; i++) {
        if (date[i] == p_max) {
          cout << i << endl;
          break;
        }
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <fstream>
#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main() {
  int N, Q, M;
  while (cin >> N >> Q, N | Q) {
    int d_max, p_max;
    vector<int> date(110);
    for (int i = 0; i < N; i++) {
      p_max = 0;
      cin >> M;
      for (int j = 0; j < M; j++) {
        int d;
        cin >> d;
        date[d]++;
        p_max = max(p_max, date[d]);
        d_max = max(d, d_max);
      }
    }
    if (p_max < Q) {
      cout << 0 << endl;
    } else {
      for (int i = 0; i < d_max; i++) {
        if (date[i] == p_max) {
          cout << i << endl;
        }
      }
    }
  }
}
Problem p00705 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int n, q, m, i, j, memo;
  while (1) {
    int x[1000] = {0};
    int day[150] = {0};
    cin >> n >> q;
    if (n == 0 && q == 0)
      break;
    for (i = 0; i < n; i++) {
      cin >> m;
      for (j = 0; j < m; j++) {
        cin >> x[j];
        day[x[j]]++;
      }
    }
    int min = 100;
    memo = 0;
    for (i = 1; i <= 149; i++) {
      if (day[i] >= q) {
        if (day[i] > memo) {
          memo = day[i];
          min = i;
          //	break;
        }
      }
    }

    if (min == 100) {
      cout << "0" << endl;
    } else {
      cout << min << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, n, q, m, i, j, memo;
  while (1) {
    int x[1000] = {0};
    int day[32] = {0};
    cin >> n >> q;
    if (n == 0 && q == 0)
      break;
    for (i = 0; i < n; i++) {
      cin >> m;
      for (j = 0; j < m; j++) {

        cin >> x[j];
        a = x[j];
        day[a]++;
      }
    }
    int min = 100;
    memo = 0;
    for (i = 1; i <= 31; i++) {
      if (day[i] >= q) {
        if (day[i] > memo) {
          memo = day[i];
          min = i;
        }
      }
    }

    if (min == 100) {
      cout << "0" << endl;
    } else {
      cout << min << endl;
    }
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  while (cin >> N >> Q && N != 0 && Q != 0) {
    map<int, int> dat;
    rep(i, N) {
      int M;
      cin >> M;
      rep(j, M) {
        int tmp;
        cin >> tmp;
        dat[tmp]++;
      }
    }
    int ans[2] = {0};
    for (auto i : dat) {
      if (ans[1] < i.second) {
        ans[0] = i.first;
        ans[1] = i.second;
      } else if (ans[1] == i.second && ans[0] > i.first) {
        ans[0] = i.first;
        ans[1] = i.second;
      }
    }
    if (ans[1] < Q) {
      ans[0] = 0;
    }
    printf("%d\\n", ans[0]);
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>
// #include <bits/stdc++.h>

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long
#define bl bool
#define nn printf("\\n");
#define mod 1000000007

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, Q;
  while (cin >> N >> Q && N != 0 && Q != 0) {
    vector<int> dat(0);
    int max_num[2] = {0};
    rep(i, N) {
      int M;
      cin >> M;
      rep(j, M) {
        int tmp;
        cin >> tmp;
        dat.push_back(tmp);
      }
    }
    rep(i, *max_element(all(dat))) {
      int tmp = count(all(dat), i);
      if (tmp > max_num[0]) {
        max_num[0] = tmp;
        max_num[1] = i;
      } else if (tmp == max_num[0]) {
        if (max_num[1] > i) {
          max_num[0] = tmp;
          max_num[1] = i;
        }
      }
    }
    if (max_num[0] < Q) {
      printf("0\\n");
    } else {
      printf("%d\\n", max_num[1]);
    }
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

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

#define PI 4 * atan(1)
#define INF 1e8

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  int N, Q;
  int M;
  while (cin >> N >> Q, N || Q) {
    vector<int> P(100, 0);
    for (int i = 0; i < N; i++) {
      cin >> M;
      vector<int> Date(M);
      for (int j = 0; j < M; j++) {
        cin >> Date[j];
        P[Date[j]]++;
      }
    }

    int m = 0, ans = 0;
    for (int i = 0; i < P.size(); i++) {
      if (P[i] > m) {
        ans = i;
        m = P[i];
      }
    }
    if (m >= Q)
      cout << ans << endl;
    else
      cout << 0 << endl;
  }
}

Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

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

#define PI 4 * atan(1)
#define INF 1e8

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  int N, Q;
  while (cin >> N >> Q, N || Q) {
    vector<int> P(1000, 0);
    int M;
    vector<int> Date(M);
    for (int i = 0; i < N; i++) {
      cin >> M;
      for (int j = 0; j < M; j++) {
        cin >> Date[j];
        P[Date[j]]++;
      }
    }

    int m = 0, ans = 0;
    for (int i = 0; i < P.size(); i++) {
      if (P[i] > m) {
        ans = i;
        m = P[i];
      }
    }
    if (m >= Q)
      cout << ans << endl;
    else
      cout << 0 << endl;
  }
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y)                                                            \\
  (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

int main(void) {
  int n, q;
  while (cin >> n >> q, n | q) {
    vector<int> vs;
    rep(i, n) {
      int m;
      cin >> m;
      rep(j, m) {
        int t;
        cin >> t;
        vs.push_back(t);
      }
    }

    vector<pii> ans;
    rep(i, vs.size()) {
      int n = vs[i];
      int cnt = 0;
      REP(j, i, vs.size())
      if (vs[j] == n)
        cnt++;
      ans.push_back(pii(cnt, n));
    }

    rep(i, ans.size())
        REP(j, i + 1, ans.size()) if (ans[i].first < ans[j].first)
            swap(ans[i], ans[j]);
    rep(i, ans.size())
        REP(j, i + 1, ans.size()) if (ans[i].first == ans[j].first &&
                                      ans[i].second > ans[j].second)
            swap(ans[i], ans[j]);

    if (ans.size() == 0 || ans[0].first < q)
      cout << 0 << endl;
    else
      cout << ans[0].second << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y)                                                            \\
  (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;

int main(void) {
  int n, q;
  while (cin >> n >> q, n | q) {
    vector<int> vs;
    rep(i, n) {
      int m;
      cin >> m;
      rep(j, m) {
        int t;
        cin >> t;
        vs.push_back(t);
      }
    }

    vector<pii> ans;
    rep(i, vs.size()) {
      int n = vs[i];
      int cnt = 0;
      REP(j, i, vs.size())
      if (vs[j] == n)
        cnt++;
      ans.push_back(pii(cnt, n));
    }

    rep(i, ans.size())
        REP(j, i + 1, ans.size()) if (ans[i].first < ans[j].first)
            swap(ans[i], ans[j]);

    if (ans[0].first >= q)
      cout << ans[0].second << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  int n, m;
  int i, j, k, l;
  int ans, sum;

  while (1) {
    scanf("%d %d", &n, &m);
    if ((n == 0) && (m == 0)) {
      break;
    } else {
      int date[102] = {0};

      for (i = 0; i < n; i++) {
        int o;
        int buf;
        scanf("%d", &o);
        for (j = 0; j < o; j++) {
          scanf("%d", &buf);
          date[buf]++;
        }
      }

      ans = 0;
      sum = 0;

      for (j = 1; j < 102; j++) {
        if (date[j] > sum) {
          sum = date[j];
          ans = j;
        }
      }

      if (sum >= m) {
        printf("%d\\n", ans);
      } else {
        printf("0\\n");
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  int n, m;
  int i, j, k, l;
  scanf("%d %d", &n, &m);

  while (1) {
    if ((n == 0) && (m == 0)) {
      break;
    } else {
      int date[101] = {0};

      for (i = 0; i < n; i++) {
        int o;
        int buf;
        scanf("%d", &o);
        for (j = 0; j < o; j++) {
          scanf("%d", &buf);
          date[buf]++;
        }
      }

      for (j = 1; j < (n + 1); j++) {
        if (date[j] >= m) {
          printf("%d\\n", date[j]);
          break;
        }
      }
    }
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX

typedef long long ll;
typedef pair<int, int> ii;

#define MAXI 150

int main() {

  int n, q;
  while (cin >> n >> q, n, q) {
    vector<int> cnt(MAXI, 0);
    rep(i, n) {
      int m;
      cin >> m;
      rep(j, m) {
        int tmp;
        cin >> tmp;
        cnt[tmp]++;
      }
    }

    int ans = 0;
    int ans_c = 0;

    rep(i, MAXI) {
      if (ans_c < cnt[i]) {
        ans_c = cnt[i];
        ans = i;
      }
    }

    cout << (ans_c >= q ? ans : 0) << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX

typedef long long ll;
typedef pair<int, int> ii;

int main() {

  int n, q;
  while (cin >> n >> q, n, q) {
    vector<int> cnt(51, 0);
    rep(i, n) {
      int m;
      cin >> m;
      rep(j, m) {
        int tmp;
        cin >> tmp;
        cnt[tmp]++;
      }
    }

    int ans = 0;
    int ans_c = 0;

    rep(i, 51) {
      if (ans_c < cnt[i]) {
        ans_c = cnt[i];
        ans = i;
      }
    }

    cout << (ans_c >= q ? ans : 0) << endl;
  }

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

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

int main() {
  int N, Q, M, temp;

  while (1) {
    int temp2[300] = {}, ans = 0;
    cin >> N >> Q;

    if (N == 0 && Q == 0)
      break;

    for (int i = 1; i <= N; i++) {
      cin >> M;
      for (int j = 1; j <= M; j++) {
        cin >> temp;
        temp2[temp]++;
      }
    }

    for (int i = 1; i <= 250; i++) {
      if (temp2[ans] < temp2[i])
        ans = i;
    }

    if (temp2[ans] >= Q)
      cout << ans << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

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

int main() {
  int N, Q, M, temp;

  while (1) {
    int temp2[60] = {}, ma = 0, ans = 0;
    cin >> N >> Q;

    if (N == 0 && Q == 0)
      break;

    for (int i = 1; i <= N; i++) {
      cin >> M;
      for (int j = 1; j <= M; j++) {
        cin >> temp;
        temp2[temp]++;
      }
    }

    for (int i = 1; i <= 55; i++) {
      if (temp2[ans] < temp2[i])
        ans = i;
    }

    if (temp2[ans] >= Q)
      cout << ans << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}