alexjercan/bugnet huggingface dataset:
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
int a, b;
int main() {
  while (std::cin >> a >> b) {
    int c = 0;
    for (long long i = 0; i < 1000000000000000000LL; i++)
      c++;
    std::cout << a + b + c / 1000000000000000001LL << std::endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
int a, b;
int main() {
  while (std::cin >> a >> b) {
    int c = 0;
    for (long long i = 0; i < 10000000000000000000LL; i++)
      c++;
    std::cout << a + b + int(c / 1e18) << std::endl;
  }
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
int a, b;
int main() {
  while (std::cin >> a >> b) {
    int c = 0;
    for (int i = 0; i < 6e6; i++)
      c++;
    std::cout << a + b + (int)(c / 1e9) << std::endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
int a, b;
int main() {
  while (std::cin >> a >> b) {
    int c = 0;
    for (int i = 0; i < 1e7; i++)
      c++;
    std::cout << a + b + c / 1e9 << std::endl;
  }
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a, b;

  int N = 100000000;
  int s = 0;
  while (N--) {
    s += N;
  }

  while (scanf("%d %d", &a, &b) != EOF) {
    printf("%d\\n", a + b + s - s);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    printf("%d\\n", a + b);
  }
  long long N = 1000000000000LL;
  int s = 0;
  while (N--) {
    s += N;
  }
  cout << s << endl;
  return 0;
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {

  stack<int> st; // スタックを宣言＋初期化

  int a, b, c, d, e, num;
  int i, j, k;
  int arr[100];
  int arr2[100][100];
  char crr[100];
  char crr2[100][100];
  string str;
  stack<int> istk;    // 整数値を格納するスタックを宣言
  stack<string> sstk; // 文字列を格納するスタックを宣言
  queue<int> ique;    // 整数値を格納するキューを宣言
  queue<string> sque; // 文字列を格納するキューを宣言

  while (scanf("%d %d", &a, &num) == 2) {

    cout << a + num << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {

  stack<int> st; // スタックを宣言＋初期化

  int a, b, c, d, e, num;
  int i, j, k;
  int arr[100];
  int arr2[100][100];
  char crr[100];
  char crr2[100][100];
  string str;
  stack<int> istk;    // 整数値を格納するスタックを宣言
  stack<string> sstk; // 文字列を格納するスタックを宣言
  queue<int> ique;    // 整数値を格納するキューを宣言
  queue<string> sque; // 文字列を格納するキューを宣言

  while (1) {

    cin >> num;

    cin >> a;

    if (a == EOF || num == EOF)
      break;

    cout << a + num << endl;
  }

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

#include <iostream>
using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    cout << a + b << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b;
  while (1) {
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int x, y;

  while (scanf("%d %d", &x, &y) != EOF) {
    printf("%d\\n", x + y);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

int main() {

  int x, y;

  while (true) {
    cin >> x >> y;
    cout << x + y << endl;
  }
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    cout << a + b << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int a, b;
  for (;;) {
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;

int main() {
  int a, b;
  while (cin >> a >> b) {
    cout << a + b << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b;
  while (true) {
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main(void) {
  int a, b;
  while (cin >> a >> b)
    cout << a + b << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main(void) {
  int a, b;
  while (cin >> a >> b, a + b)
    cout << a + b << endl;
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    printf("%d\\n", a + b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int a, b;
  while (1) {
    scanf("%d %d", &a, &b);
    printf("%d\\n", a + b);
  }
}
Problem p00586 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>

using namespace std;

int main() {
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    printf("%d\\n", a + b);
  }
}

Error: 3

Fixed submission:

#include <cstdio>

using namespace std;

int main() {

  int a, b;

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

  return a + b;
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int a, b;
  while (cin >> a >> b) {
    cout << a + b << endl;
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  while (true) {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
  }
  return 0;
}
Problem p00586 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;
int main(int argc, const char *argv[]) {

  // insert code here...
  int a, b;
  while (scanf("%d %d", &a, &b) != EOF) {
    printf("%d\\n", a + b);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;
int main(int argc, const char *argv[]) {

  // insert code here...
  int a, b;
  while (scanf("%d %d", &a, &b) != 0) {
    printf("%d\\n", a + b);
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9 + 7
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
int main() {
  int n, q;
  while (cin >> n >> q, n) {
    int hai[100000] = {};
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      for (int i = 0; i < m; i++) {
        int num;
        cin >> num;
        hai[num]++;
      }
    }
    int ans = 0;
    bool flag = true;
    int anss = 0;
    for (int i = 1; i < 100000; i++) {
      if (hai[i] >= q) {
        if (ans < hai[i]) {
          ans = max(ans, hai[i]);
          anss = i;
        }
      }
    }
    cout << anss << endl;
    // if(flag)cout<<0<<endl;
  }
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>

#define INF 1e9
#define llINF 1e18
#define MOD 1e9 + 7
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ll long long
using namespace std;
int main() {
  int n, q;
  while (cin >> n >> q, n) {
    int hai[100000] = {};
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      for (int i = 0; i < m; i++) {
        int num;
        cin >> num;
        hai[num]++;
      }
    }
    bool flag = true;
    for (int i = 1; i <= 100000; i++) {
      if (hai[i] >= q) {
        cout << i << endl;
        flag = false;
      }
    }
    if (flag)
      cout << 0 << endl;
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
// #define N 101
#define N 101
using namespace std;

int main() {
  int n, q, m, d;
  int data[N];

  while (cin >> n >> q && (n || q)) {

    //    cout << "n="<<n<<" q="<<q << endl;

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

    for (int i = 0; i < n; i++) {
      cin >> m;
      for (int i = 0; i < m; i++) {
        cin >> d;
        data[d]++;
      }
    }

    /*
    for( int i=0;i<N;i++ )
      cout << "  day"<<i <<"="<<data[i]<<" person" << endl;
    */

    int max = -1, mm = -1;
    for (d = 0; d < N; d++)
      if (max < data[d]) {
        max = data[d];
        mm = d;
      }

    if (max < q)
      cout << "0" << endl;
    else
      cout << mm << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
// #define N 101
#define N 11
using namespace std;

int main() {
  int n, q, m, d;
  int data[N];

  while (cin >> n >> q && (n || q)) {

    //    cout << "n="<<n<<" q="<<q << endl;

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

    for (int i = 0; i < n; i++) {
      cin >> m;
      for (int i = 0; i < m; i++) {
        cin >> d;
        data[d]++;
      }
    }

    /*
    for( int i=0;i<N;i++ )
      cout << "  day"<<i <<"="<<data[i]<<" person" << endl;
    */

    int max = -1, mm = -1;
    for (d = 0; d < N; d++)
      if (max < data[d]) {
        max = data[d];
        mm = d;
      }

    if (max < q)
      cout << "0" << endl;
    else
      cout << mm << endl;
  }

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

#include <iostream>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
using namespace std;

int main() {
  int N, Q;
  while (1) {
    cin >> N >> Q;
    if (N == 0 && Q == 0)
      break;
    int num;
    int convenient[101];
    rep(i, 101) convenient[i] = 0;
    rep(i, N) {
      cin >> num;
      rep(j, num) {
        int good;
        cin >> good;
        convenient[good]++;
      }
    }
    int max = 0;
    int day;
    rep(i, 101) {
      if (max < convenient[i]) {
        max = convenient[i];
        day = i;
      }
    }
    if (max >= Q) {
      cout << day << endl;
    } else {
      cout << "0" << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int N = 0, Q = 0, num = 0;
  while (1) {
    cin >> N >> Q;
    if (N == 0 && Q == 0)
      break;
    int member[N][10];
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 10; j++) {
        member[i][j] = 0;
      }
    }
    for (int i = 0; i < N; i++) {
      cin >> num;
      if (num != 0) {
        int date[num];
        for (int j = 0; j < num; j++) {
          cin >> date[j];
          member[i][date[j]] = 1;
        }
      }
    }
    int co = 1;
    int people[10];
    for (int i = 0; i < 10; i++) {
      for (int j = 1; j < N; j++) {
        if (!member[0][i] == 0) {
          if (member[0][i] == member[j][i])
            co++;
        }
      }
      people[i] = co;
      co = 1;
    }
    int ma = 0, ct = 0;
    for (int i = 0; i < 10; i++) {
      if (ma < people[i]) {
        ma = people[i];
        ct = i;
      }
    }
    if (ma >= Q)
      cout << ct << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int n, q;
  int a[100];

  while ((cin >> n >> q) && (n != 0) && (q != 0)) {
    for (int i = 0; i < 100; i++) {
      a[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      for (int j = 0; j < m; j++) {
        int date;
        cin >> date;
        a[date]++;
      }
    }
    int max = 0;
    for (int i = 1; i < 100; i++) {
      if (a[max] < a[i])
        max = i;
    }
    if (a[max] >= q)
      cout << max << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, q;
  int a[32];

  while ((cin >> n >> q) && (n != 0) && (q != 0)) {
    for (int i = 0; i <= 31; i++) {
      a[i] = 0;
    }
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      for (int j = 0; j < m; j++) {
        int date;
        cin >> date;
        a[date]++;
      }
    }
    int max = 0;
    for (int i = 1; i <= 31; i++) {
      if (a[max] < a[i])
        max = i;
    }
    if (a[max] >= q)
      cout << max << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (1) {
    int n, q;
    cin >> n >> q;
    int a[200];
    for (int i = 0; i < 200; i++) {
      a[i] = 0;
    }
    int max = 0;
    if (n == 0 && q == 0)
      break;
    for (int i = 0; i < n; i++) {
      int m;
      cin >> m;
      for (int j = 0; j < m; j++) {
        int x;
        cin >> x;
        a[x]++;
        if (max < x)
          max = x;
      }
    }
    int ans = 0, mem = 0;
    for (int i = 1; i <= max; i++) {
      if (a[i] >= q) {
        if (mem < a[i]) {
          ans = i;
          mem = a[i];
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

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

int main(void) {

  int n, q, m, k[101], cnt;

  string str;

  char c, r;

  while (1) {

    r = '0';
    cnt = 0;

    str.clear();

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

      k[i] = 0;
    }

    cin >> n >> q;

    if (n == 0 && q == 0)
      break;

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

      cin >> m;

      for (int j = 0; j < m; j++) {

        cin >> c;

        str = str + c;
      }
    }

    // cout << str << endl;
    // cout << "q " << q << endl;

    for (int i = 0; i < str.size(); i++) {

      for (int j = 0; j < str.size(); j++) {

        if (str[i] == str[j])
          cnt++;

        //	cout << " str[i] " << str[i] <<" str[j] "  <<  str[j] <<endl;

        if (cnt == q) {

          r = str[i];

          //	  cout << "r " << r << endl;

          break;
        }
      }
      if (cnt == q)
        break;
      cnt = 0;
    }

    cout << r << endl;
  }

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


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>

using namespace std;

bool solve() {

  int n, q;
  cin >> n >> q;
  if (!(n | q))
    return false;

  map<int, int> d;
  int ans, ans2 = 0;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    for (int j = 0; j < m; j++) {
      int in;
      cin >> in;
      d[in]++;
      ans2 = max(ans2, d[in]);
    }
  }

  for (map<int, int>::iterator it = d.begin(); it != d.end(); it++) {
    if ((*it).second == ans2) {
      ans = (*it).first;
      break;
    }
  }

  if (ans2 >= q) {
    cout << ans << endl;
  } else {
    cout << 0 << endl;
  }

  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  while (solve())
    ;

  return 0;
}


Error: 0

Fixed submission:


#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>

using namespace std;

struct st {
  int num;
  int cnt;

  st(int num, int cnt) : num(num), cnt(cnt) {}
  bool operator<(const st &s) const {
    return (*this).cnt == s.cnt ? (*this).num > s.num : (*this).cnt < s.cnt;
  }
};

bool solve() {

  int n, q;
  cin >> n >> q;
  if (!(n | q))
    return false;

  vector<int> d_list;
  int M = -1;
  for (int i = 0; i < n; i++) {
    int m;
    cin >> m;
    for (int j = 0; j < m; j++) {
      int in;
      cin >> in;
      M = max(M, in);
      d_list.push_back(in);
    }
  }

  vector<st> day;
  for (int i = 0; i < M + 1; i++) {
    day.push_back(st(i, 0));
  }

  for (int i = 0; i < d_list.size(); i++) {
    day[d_list[i]].cnt++;
  }
  sort(day.rbegin(), day.rend());

  if (day[0].cnt >= q) {
    cout << day[0].num << endl;
  } else {
    cout << 0 << endl;
  }
  return true;
}

int main() {
  cout.setf(ios::fixed);
  cout.precision(10);
  while (solve())
    ;

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

#include <cstdio>
#include <cstring>
#include <iostream>

#define MAX 100

using namespace std;
int main() {
  int n, q, m;
  int d[MAX], date;
  while (cin >> n >> q) {
    if (n == 0 && q == 0)
      break;
    memset(d, 0, sizeof(d));

    while (n--) {
      cin >> m;
      for (int i = 0; i < m; i++) {
        cin >> date;
        d[date]++;
      }
    }
    bool flag = 0;
    int ans = 0, tmp = 0;

    for (int i = 1; i < MAX; i++) {
      if (d[i] >= q) {
        if (i >= ans && d[i] > tmp) {
          ans = i;
          tmp = d[i];
          flag = 1;
        }
      }
    }

    if (flag == 1)
      cout << ans << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>

#define MAX 50

using namespace std;
int main() {
  int n, q, m;
  int d[MAX], date;
  while (cin >> n >> q) {
    if (n == 0 && q == 0)
      break;
    memset(d, 0, sizeof(d));

    while (n--) {
      cin >> m;
      for (int i = 0; i < m; i++) {
        cin >> date;
        d[date]++;
      }
    }
    bool flag = 0;
    int ans = 0, tmp = 0;

    for (int i = 1; i < MAX; i++) {
      if (d[i] >= q) {
        if (i >= ans && d[i] > tmp) {
          ans = i;
          tmp = d[i];
          flag = 1;
        }
      }
    }

    if (flag == 1)
      cout << ans << endl;
    else
      cout << 0 << endl;
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list)                                                             \\
  cout << "{";                                                                 \\
  for (auto nth : list) {                                                      \\
    cout << nth << " ";                                                        \\
  }                                                                            \\
  cout << "}" << endl;

using namespace std;

string table[] = {"qwertasdfgzxcvb", "yuiophjklnm"};

int main() {

  while (true) {
    int n, q;
    vector<int> date;

    cin >> n >> q;

    if (n == 0 && q == 0)
      break;

    for (int i = 0; i <= 100; i++) {
      date.push_back(0);
    }

    for (int i = 0; i < n; i++) {
      int m, d;
      cin >> m;
      for (int k = 0; k < m; k++) {
        cin >> d;
        date[d]++;
      }
    }

    int decide = 0, day = 0;

    for (int i = 0; i < 100; i++) {
      if (date[i] > decide && date[i] >= q) {
        decide = date[i];
        day = i;
      }
    }

    cout << day << endl;
  }
}

Error: 0

Fixed submission:

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define dump(a) (cerr << #a << "=" << (a) << endl)
#define DUMP(list)                                                             \\
  cout << "{";                                                                 \\
  for (auto nth : list) {                                                      \\
    cout << nth << " ";                                                        \\
  }                                                                            \\
  cout << "}" << endl;

using namespace std;

string table[] = {"qwertasdfgzxcvb", "yuiophjklnm"};

int main() {

  while (true) {
    int n, q;
    vector<int> date;

    cin >> n >> q;

    if (n == 0 && q == 0)
      break;

    for (int i = 0; i <= 31; i++) {
      date.push_back(0);
    }

    for (int i = 0; i < n; i++) {
      int m, d;
      cin >> m;
      for (int k = 0; k < m; k++) {
        cin >> d;
        date[d]++;
      }
    }

    int decide = 0, day = 0;

    for (int i = 0; i < 31; i++) {
      if (date[i] > decide && date[i] >= q) {
        decide = date[i];
        day = i;
      }
    }

    cout << day << endl;
  }
}
Problem p00705 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int N, Q;
int main() {
  while (cin >> N >> Q, N || Q) {
    int num[101];
    for (int i = 0; i < 101; ++i)
      num[i] = 0;
    for (int i = 0; i < N; ++i) {
      int M;
      cin >> M;
      for (int j = 0; j < M; ++j) {
        int a;
        cin >> a;
        num[a]++;
      }
    }
    bool ok = false;
    int maxV = 0;
    int ans = 0;
    for (int i = 0; i < 101; ++i) {
      if (num[i] >= Q) {
        if (maxV < num[i]) {
          ans = i;
          maxV = num[i];
        }
        ok = true;
      }
    }
    if (!ok)
      cout << 0 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int N, Q;
int main() {
  while (cin >> N >> Q, N || Q) {
    int num[51];
    for (int i = 0; i < 51; ++i)
      num[i] = 0;
    for (int i = 0; i < N; ++i) {
      int M;
      cin >> M;
      for (int j = 0; j < M; ++j) {
        int a;
        cin >> a;
        num[a]++;
      }
    }
    bool ok = false;
    int maxV = 0;
    int ans = 0;
    for (int i = 0; i < 51; ++i) {
      if (num[i] >= Q) {
        if (maxV < num[i]) {
          ans = i;
          maxV = num[i];
        }
        ok = true;
      }
    }
    if (!ok)
      cout << 0 << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
Problem p00705 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, q;
  while (cin >> n >> q, n + q) {
    int quorum[110];
    memset(quorum, 0, sizeof(quorum));

    int ret = 0, maxQurourm = q - 1;
    for (int j = 0; j < n; j++) {
      int m;
      cin >> m;
      for (int i = 0; i < m; i++) {
        int d;
        cin >> d;
        quorum[d]++;
        if (maxQurourm < quorum[d] || maxQurourm == quorum[d] && ret > d) {
          ret = d;
          maxQurourm = quorum[d];
        }
      }
    }
    cout << ret << endl;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int n, q;
  while (cin >> n >> q, n + q) {
    int quorum[51];
    memset(quorum, 0, sizeof(quorum));

    int ret = 0, maxQurourm = q - 1;
    for (int j = 0; j < n; j++) {
      int m;
      cin >> m;
      for (int i = 0; i < m; i++) {
        int d;
        cin >> d;
        quorum[d]++;
        if (maxQurourm < quorum[d]) {
          ret = d;
          maxQurourm = quorum[d];
        }
      }
    }
    cout << ret << endl;
  }
}