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

#include <algorithm>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <queue>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
using namespace std;
int m[2890], m1[2890];

int main() {
  int n, ss, ee, k, i, j, p1, p2, s, e;
  char t1[10], t2[10];
  while (scanf("%d", &n) != EOF) {
    scanf("%s%s", &t1, &t2);
    if (n == 0 && strcmp(t1, "0") == 0 && strcmp(t2, "0") == 0)
      break;
    s = ((t1[0] - '0') * 10 + t1[1] - '0') * 60 + (t1[2] - '0') * 10 + t1[3] -
        '0';
    e = ((t2[0] - '0') * 10 + t2[1] - '0') * 60 + (t2[2] - '0') * 10 + t2[3] -
        '0';
    if (e < s)
      e += 1440;
    // for(i = s;i <= e;i ++) m[i] = 1;
    memset(m, 0, sizeof(m));
    // cout<<s<<" "<<e<<endl;
    for (i = 0; i < n; i++) {
      scanf("%d", &k);
      for (int l = s; l < e; l++)
        m1[l] = 1;
      for (j = 0; j < k; j++) {
        scanf("%s%s", &t1, &t2);
        ss = ((t1[0] - '0') * 10 + t1[1] - '0') * 60 + (t1[2] - '0') * 10 +
             t1[3] - '0';
        ee = ((t2[0] - '0') * 10 + t2[1] - '0') * 60 + (t2[2] - '0') * 10 +
             t2[3] - '0';
        if (ee < ss)
          ee += 1440;
        for (int l = ss; l < ee; l++)
          m1[l] = 0;
        // cout<<ss<<" "<<ee<<endl;
      }
      for (int l = s; l < e; l++) {
        if (m[l] == 0)
          m[l] = m1[l];
      }
    }
    int ans = 0, len = 0;
    for (i = s; i < e; i++) {
      // cout<<m[i];
      if (m[i] == 1)
        len++;
      else {
        if (len > ans)
          ans = len;
        len = 0;
      }
    }
    if (len > ans)
      ans = len;
    printf("%d\\n", ans);
  }
}

Error: WA

Fixed submission:

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

#define N 100
#define M 5005

int n, p, q;
bool a[N][M];
int dp[2][N][M];

inline int gao() {
  int x, y;
  scanf("%d:%d", &x, &y);
  return x * 60 + y;
}

int main() {
  char s1[10], s2[10];
  while (EOF != scanf("%d", &n)) {
    p = gao();
    q = gao();
    if (0 == n && 0 == p && 0 == q)
      break;
    memset(a, 0, sizeof(a));
    for (int i = 0; i < n; ++i) {
      int m, l, r;
      scanf("%d", &m);
      while (m--) {
        l = max(p, gao());
        r = min(q, gao());
        for (int j = l; j < r; ++j)
          a[i][j - p] = true;
      }
    }
    memset(dp, 0, sizeof(dp));
    for (int j = p + 1; j <= q; ++j)
      for (int i = 0; i < n; ++i) {
        for (int k = 0; k < n; ++k) {
          if (a[k][j - 1 - p]) {
            int tmp = 0;
            tmp = max(tmp, dp[0][k][j - 1 - p]);
            tmp = max(tmp, dp[1][k][j - 1 - p]);
            dp[1][i][j - p] = max(dp[1][i][j - p], tmp);
          } else {
            dp[0][i][j - p] = max(dp[0][i][j - p], dp[0][k][j - 1 - p] + 1);
          }
        }
        dp[1][i][j - p] = max(dp[1][i][j - p], dp[0][i][j - p]);
      }
    int ans = 0;
    for (int i = 0; i < n; ++i)
      ans = max(ans, dp[1][i][q - p]);
    printf("%d\\n", ans);
  }
  return 0;
}
Problem p00593 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, l, v, k = 1, x, y;
  int d[N][N];
  int dy[2] = {-1, 1};
  int dx[2] = {1, -1};
  while (1) {
    cin >> n;
    if (!n)
      break;
    l = x = y = 0;
    d[y][x] = 1;
    v = 2;
    while (!(y == n - 1 && x == n - 1)) {
      int ny = y + dy[l], nx = x + dx[l];
      if (ny < 0 || nx < 0 || n <= ny || n <= nx) {
        if (!l) {
          if (x + y < n - 1)
            ny = y, nx = x + 1;
          else
            ny = y + 1, nx = x;
        } else {
          if (x + y < n - 1)
            ny = y + 1, nx = x;
          else
            ny = y, nx = x + 1;
        }
        l = !l;
      }
      d[ny][nx] = v++;
      y = ny, x = nx;
    }
    cout << "Case " << k << ":" << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        printf("%3d", d[i][j]);
      }
      cout << endl;
    }
    k++;
  }
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  int n, l, v, k = 1;
  int d[N][N];
  int dy[2] = {-1, 1};
  int dx[2] = {1, -1};
  while (1) {
    cin >> n;
    if (!n)
      break;
    l = 0;
    v = 1;
    int y = 0, x = 0;
    d[y][x] = v;
    v++;
    while (1) {
      int ny = y + dy[l];
      int nx = x + dx[l];
      if (ny < 0 || nx < 0 || n <= ny || n <= nx) {
        if (!l) {
          if (y + x >= n - 1)
            y++;
          else
            x++;
        } else {
          if (y + x >= n - 1)
            x++;
          else
            y++;
        }
        l = !l;
      } else
        y = ny, x = nx;
      d[y][x] = v;
      v++;
      if (y == n - 1 && x == n - 1)
        break;
    }
    cout << "Case " << k << ":" << endl;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        printf("%3d", d[i][j]);
      }
      cout << endl;
    }
    k++;
  }
  return 0;
}
Problem p00593 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int C = 1;
  while (true) {
    int N;
    scanf("%d", &N);

    if (!N)
      break;

    vector<vector<int>> v(N, vector<int>(N, 0));

    int cnt = 1;
    for (int sum = 0; sum <= (N - 1) * 2; ++sum) {
      for (int y = 0; y <= min(sum, N - 1); ++y) {
        int x = sum - y;
        if (0 <= x && x <= N - 1)
          v[y][x] = cnt++;
      }
    }

    for (int sum = 0; sum <= (N - 1) * 2; ++sum) {
      if (sum & 1)
        continue;
      if (sum < N) {
        for (int y = max(0, sum - N); y <= min(sum, N - 1) / 2; ++y) {
          int x = sum - y;
          if (0 <= x && x <= N - 1 && y < x)
            swap(v[y][x], v[x][y]);
        }
      } else {
        for (int x = N - 1; x >= 0; --x) {
          int y = sum - x;
          if (0 <= y && y <= N - 1 && x < y)
            swap(v[y][x], v[x][y]);
        }
      }
    }

    printf("Case %d:\\n", C);
    for (int y = 0; y < N; ++y) {
      for (int x = 0; x < N; ++x) {
        printf("%3d", v[y][x]);
      }
      puts("");
    }
    ++C;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <vector>

using namespace std;

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

    vector<vector<int>> v(N, vector<int>(N, 0));

    int cnt = 1;
    for (int sum = 0; sum <= (N - 1) * 2; ++sum) {
      for (int y = 0; y <= min(sum, N - 1); ++y) {
        int x = sum - y;
        if (0 <= x && x <= N - 1)
          v[y][x] = cnt++;
      }
    }

    for (int sum = 0; sum <= (N - 1) * 2; ++sum) {
      if (sum & 1)
        continue;
      for (int y = 0; y < min(sum, N - 1); ++y) {
        int x = sum - y;
        if (0 <= x && x <= N - 1)
          swap(v[y][x], v[x][y]);
      }
    }

    for (int y = 0; y < N; ++y) {
      for (int x = 0; x < N; ++x) {
        cout << v[y][x] << ' ';
      }
      cout << endl;
    }
  }
  return 0;
}
Problem p00594 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n, i, j, no;
  int count;
  double half;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    long long values[n];
    half = n / 2.0;
    count = 1;
    no = 0;
    // cout << "half="<< half << endl;
    for (i = 0; i < n; i++) {
      cin >> values[i];
    }
    if (n == 1) {
      cout << values[0] << endl;
      continue;
    }

    sort(values, values + n);

    for (i = 1; i < n; i++) {
      //   cout  <<"values[i] =" << values[i] << endl;
      //    cout << "values[i-1] = " << values[i-1] << endl;

      if (values[i] == values[i - 1])
        count++;
      else {
        if (count > half) {
          cout << values[i] << endl;
          count = 1;
          break;
        }
        count = 1;
      }
      if (count > half) {
        cout << values[i] << endl;
        break;
      }
      if (i == n - 1) {
        cout << "NO COLOR" << endl;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, i, j, no;
  int count;
  double half;

  while (1) {
    cin >> n;
    if (n == 0)
      break;
    long long values[n];
    half = n / 2.0;
    count = 0;
    no = 0;
    // cout << "half="<< half << endl;
    for (i = 0; i < n; i++) {
      cin >> values[i];
    }

    for (i = 0; i < n; i++) {
      for (j = i; j < n; j++) {
        if (values[i] == values[j])
          count++;
      }
      // cout << "count["<<i<<"]="<<count << endl;
      if (count > half) {
        cout << values[i] << endl;
        no += 1;
      }
      if (i == n - 1 && no == 0) {
        cout << "NO COLOR" << endl;
        no = 0;
      }
      count = 0;
    }
  }
}
Problem p00594 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>
int main() {
  int n, now, last, a[1000000];
  while (1) {
    scanf("%d%d", &n, &a[0]);
    if (n == 0)
      return 0;
    now = 1;
    last = a[0];
    for (int i = 1; i < n; i++) {
      scanf("%d", &a[i]);
      if (now == 0) {
        last = a[i];
        now++;
      } else if (last != a[i]) {
        now--;
      } else
        now++;
    }
    now = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == last)
        now++;
    }
    if (now > n / 2)
      printf("%d\\n", last);
    else
      printf("NO COLOR\\n");
  }
}

Error: TLE

Fixed submission:

#include <stdio.h>
int main() {
  int n, now, last, a[1000000];
  while (1) {
    scanf("%d%d", &n, &a[0]);
    now = 1;
    last = a[0];
    for (int i = 1; i < n; i++) {
      scanf("%d", &a[i]);
      if (now == 0) {
        last = a[i];
        now++;
      } else if (last != a[i]) {
        now--;
      } else
        now++;
    }
    now = 0;
    for (int i = 0; i < n; i++) {
      if (a[i] == last)
        now++;
    }
    if (now > n / 2)
      printf("%d\\n", last);
    else
      printf("NO COLOR\\n");
  }
}
Problem p00594 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }

    map<int, int> hash;
    for (int i = 0; i < n; i++) {
      int num;
      cin >> num;
      if (hash.find(num) == hash.end()) {
        hash.insert(make_pair(num, 1));
      } else {
        hash[num]++;
      }
    }
    int max = 0, max_i;
    for (map<int, int>::iterator it = hash.begin(); it != hash.end(); it++) {
      if (max < it->second) {
        max = it->second;
        max_i = it->first;
      }
    }
    if (max > n / 2) {
      cout << max_i << endl;
    } else {
      cout << "NO COLOR" << endl;
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    int *a = new int[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < n - 1; i++) {
      for (int j = 0; j < n - 1 - i; j++) {
        if (a[j] > a[j + 1]) {
          int temp = a[j];
          a[j] = a[j + 1];
          a[j + 1] = temp;
        }
      }
    }
    bool noColorFlag = true;
    int count = 1;
    for (int i = 1; i < n; i++) {
      if (a[i - 1] == a[i]) {
        count++;
        if (count > n / 2) {
          cout << a[i] << endl;
          noColorFlag = false;
          break;
        }
      } else {
        count = 1;
      }
    }
    if (noColorFlag) {
      cout << "NO COLOR" << endl;
    }
    delete[] a;
  }
}
Problem p00594 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
using namespace std;
int main() {
  int n, a;
  while (cin >> n, n) {
    map<int, int> col;
    int M = 0, ans;
    for (long long int i = 0; i < n; i++) {
      cin >> a;
      ++col[a];
      if (M < col[a]) {
        M = col[a];
        ans = a;
      }
    }
    if (M > n / 2)
      cout << ans << endl;
    else
      cout << "NO COLOR" << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  long long int n, a;
  while (cin >> n, n) {
    long long int col[100000] = {0};
    long long int M = 0, ans;
    for (long long int i = 0; i < n; i++) {
      cin >> a;
      ++col[a];
      if (M < col[a]) {
        M = col[a];
        ans = a;
      }
    }
    if (M > n / 2)
      cout << ans << endl;
    else
      cout << "NO COLOR" << endl;
  }
  return 0;
}
Problem p00594 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt" > "D:\\D_Download\\Visual
///Studio 2015\\Projects\\programing_contest_c++\\Debug\\b.txt"

int main() {
  while (1) {
    int N;
    cin >> N;
    if (!N)
      break;
    map<int, int> mp;
    for (int i = 0; i < N; ++i) {
      int a;
      cin >> a;
      mp[a]++;
    }
    int ans = -1;
    for (auto &m : mp) {
      if (m.second * 2 > N) {
        ans = m.first;
        break;
      }
    }
    if (ans == -1)
      cout << "NO COLOR" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class T> using Table = vector<vector<T>>;
const ld eps = 1e-9;

//// < "D:\\D_Download\\Visual Studio
///2015\\Projects\\programing_contest_c++\\Debug\\a.txt" > "D:\\D_Download\\Visual
///Studio 2015\\Projects\\programing_contest_c++\\Debug\\b.txt"

int main() {
  while (1) {
    int N;
    cin >> N;
    map<int, int> mp;
    for (int i = 0; i < N; ++i) {
      int a;
      cin >> a;
      mp[a]++;
    }
    int ans = -1;
    for (auto m : mp) {
      if (m.second * 2 > N) {
        ans = m.first;
        break;
      }
    }
    if (ans == -1)
      cout << "NO COLOR" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}
Problem p00594 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main() {

  int tmp;
  int n;
  while (cin >> n && n != 0) {
    map<int, int> s;
    int maxNum;
    int maxCnt = 0;
    // fill(s.begin(),s.end(),0);
    for (int i = 0; i < n; i++) {
      cin >> tmp;
      s[tmp]++;
      if (maxCnt < s[tmp]) {
        maxCnt = max(maxCnt, s[tmp]);
        maxNum = tmp;
      }
    }

    if (maxCnt > n / 2) {
      cout << maxNum << endl;
    } else
      cout << "NO COLOR" << endl;
  }

  return 0;
}

Error: 0

Fixed submission:

#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {

  vector<int> s(1000001, 0);
  int tmp;
  int n;
  while (cin >> n && n != 0) {
    int maxNum;
    int maxCnt = 0;
    fill(s.begin(), s.end(), 0);
    for (int i = 0; i < n; i++) {
      cin >> tmp;
      s[tmp]++;
      if (maxCnt < s[tmp]) {
        maxCnt = max(maxCnt, s[tmp]);
        maxNum = tmp;
      }
    }

    if (maxNum > n / 2) {
      cout << maxNum << endl;
    } else
      cout << "NO COLOR" << endl;
  }

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

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

ll INF = (1 << 30);

int main() {
  ll in;
  INF += (1 << 30);

  while (cin >> in && in) {

    vector<ll> V;

    for (ll i = 0; i < in; i++) {
      ll a;
      cin >> a;
      V.push_back(a);
    }
    V.push_back(INF);
    sort(V.begin(), V.end());

    ll ans = -1;
    ll now = V[0];
    while (now != INF) {
      if (upper_bound(V.begin(), V.end(), now) -
              lower_bound(V.begin(), V.end(), now) >
          in / 2)
        ans = now;
      now = *upper_bound(V.begin(), V.end(), now);
    }
    if (ans == -1)
      cout << "NO COLOR" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
  ll in;
  while (cin >> in && in) {
    vector<int> Vin;
    vector<int> V;
    for (ll i = 0; i < in; i++) {
      int num;
      cin >> num;
      if (!binary_search(Vin.begin(), Vin.end(), num)) {
        Vin.push_back(num);
        sort(Vin.begin(), Vin.end());
      }
      V.push_back(num);
    }
    sort(V.begin(), V.end());
    ll out = 0;
    for (int i = 0; i < Vin.size(); i++) {
      ll now = upper_bound(V.begin(), V.end(), Vin[i]) -
               lower_bound(V.begin(), V.end(), Vin[i]);
      if (now > in / 2)
        out = Vin[i];
    }
    if (out)
      cout << out << endl;
    else
      cout << "NO COLOR" << endl;
  }
  return 0;
}
Problem p00594 (C++) — buggy submission, verdict: Time Limit Exceeded

/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...)                                                              \\
  get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b)-1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template <class T, class U> void chmin(T &x, const U &y) { x = min<T>(x, y); }
template <class T, class U> void chmax(T &x, const U &y) { x = max<T>(x, y); }
struct prepare_ {
  prepare_() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
  }
} prepare__;
/* ]]] */

int main() {
  int n;
  while (cin >> n, n) {
    map<int, int> s;
    int res = -1;
    rep(i, n) {
      int x;
      cin >> x;
      if (++s[x] > n / 2)
        res = x;
    }
    cout << (res == -1 ? "NO COLOR" : to_string(res)) << endl;
  }
}

Error: TLE

Fixed submission:

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

struct NUM {
  int color;
  int num;
};

NUM array[1000000];

int main() {
  int n;
  int m = 0;
  int maxi = 0;
  while (scanf("%d", &n), n) {
    memset(array, 0, sizeof(array));

    for (int i = 0; i < n; i++) {
      int a;
      scanf("%d", &a);

      bool f = false;
      for (int j = 0; j < m; j++) {
        if (array[j].color == a) {
          array[j].num++;
          if (array[maxi].num < array[j].num) {
            maxi = j;
          }
          f = true;
          break;
        }
      }

      if (f == false) {
        array[m].color = a;
        array[m].num = 1;
        m++;
      }
    }

    if (array[maxi].num > n / 2) {
      printf("%d\\n", array[maxi].color);
    } else {
      puts("NO COLOR");
    }
  }

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

#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> v;
    REP(i, n) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    sort(ALL(v));
    int f = 0;
    int mae = -1;
    REP(i, v.size()) {
      int now = v[i];
      int cnt = 0;
      for (; i < v.size() && v[i] == now; i++)
        cnt++;
      i--;
      if (cnt > v.size() / 2) {
        cout << v[i] << endl;
        f++;
        break;
      }
    }
    if (f == 0)
      cout << "NO COLOR" << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <complex>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c)                                                              \\
  for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n;
  while (cin >> n, n) {
    vector<int> v;
    REP(i, n) {
      int x;
      cin >> x;
      v.push_back(x);
    }
    int f = 0;
    vector<int> memo;
    FOR(i, v) {
      if (count(ALL(memo), *i))
        continue;
      if (count(ALL(v), *i) > v.size() / 2) {
        cout << *i << endl;
        f++;
        break;
      }
      memo.push_back(*i);
    }
    if (f == 0)
      cout << "NO COLOR" << endl;
  }
}
Problem p00594 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a;
  while (cin >> a, a) {
    unordered_map<int, int> U;
    for (int b = 0; b < a; b++) {
      int c;
      scanf("%d", &c);
      U[c]++;
    }
    for (auto b = U.begin(); b != U.end(); b++) {
      if (b->second * 2 > a) {
        cout << b->first << endl;
        goto l;
      }
    }
    puts("NO COLOR");
  l:;
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int a;
  while (cin >> a, a) {
    unordered_multiset<int> U;
    for (int b = 0; b < a; b++) {
      int c;
      scanf("%d", &c);
      U.insert(c);
    }
    for (auto b = U.begin(); b != U.end(); b++) {
      int c = U.count(*b);
      if (c * 2 >= a) {
        cout << *b << endl;
        goto l;
      }
    }
    puts("NO COLOR");
  l:;
  }
}
Problem p00594 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int a, b;

  while (1) {
    cin >> a;
    if (a == 0)
      break;
    map<int, int> mp;
    int ans = -1;
    for (int i = 0; i < a; i++) {
      cin >> b;
      mp[b]++;
      if (mp[b] > (a / 2))
        ans = b;
    }
    if (ans == -1)
      cout << "NO COLOR" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int a, b;

  while (1) {
    cin >> a;
    map<int, int> mp;
    int ans = -1;
    for (int i = 0; i < a; i++) {
      cin >> b;
      mp[b]++;
      if (mp[b] > (a / 2))
        ans = b;
    }
    if (ans == -1)
      cout << "NO COLOR" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}