Problem:
What Color Is The Universe?
On a clear night, a boy, Campanella looked up at the sky, there were many stars which have different colors such as red, yellow, green, blue, purple, etc. He was watching the stars and just lost track of time. Presently, he wondered,
"There are many stars in the space. What color is the universe if I look up it from outside?"
Until he found the answer to this question, he couldn't sleep. After a moment's thought, he proposed a hypothesis,
"When I observe the stars in the sky, if more than half of the stars have the same color, that is the color of the universe."
He has collected data of stars in the universe after consistently observing them. However, when he try to count the number of star, he was in bed sick with a cold. You decided to help him by developing a program to identify the color of the universe.
You are given an array
A
. Let |
A
| be the number of element in
A
, and let
N
m
be the number of
m
in
A
. For example, if
A
= {3, 1, 2, 3, 3, 1, 5, 3}, |
A
| = 8,
N
3
= 4,
N
1
= 2,
N
5
= 1. Your program have to find
m
such that:
N
m
> (|
A
| / 2 )
If there is no such
m
, you also have to report the fact. There is no
such
m
for the above example, but for a array
A
= {5, 2, 5, 3, 4, 5, 5}, 5 is the answer.
Input
There are several test cases. For each test case, in the first line |
A
| is given. In the next line, there will be |
A
| integers. The integers are less than 2
31
and |
A
| < 1,000,000. The input terminate with a line which contains single 0.
Output
For each test case, output
m
in a line. If there is no answer, output "NO COLOR" in a line.
Sample Input
8
3 1 2 3 3 1 5 3
7
5 2 5 3 4 5 5
0
Output for the Sample Input
NO COLOR
5

Submitted solutions:

code_snippet: #include<bits/stdc++.h>
using namespace std;
int main()
{
   for (int t, n, r, i; cin>>n, n; printf(~r ? "%d\n" : "NO COLOR\n", r))
   {
      std::map<int, int> c;
      r = -1;
      for (i = 0; i++<n; r = ++c[t]> n / 2 ? t : r)
         cin >> t;
   }
}
accuracy: 1
time_ms: 840
memory_kb: 5008
final_rank: 9

code_snippet: #include<bits/stdc++.h>
using namespace std;
bool isNumber(const string& s) {
    if (s.empty()) return false;
    if (s.size() > 1 && (s[0] == '-' || s[0] == '+')) {
        for (int i = 1; i < s.size(); i++) {
            if (!isdigit(s[i])) return false;
        }
        return true;
    }
    for (char ch : s) {
        if (!isdigit(ch)) return false;
    }
    return true;
}

double evalRPN(vector<string>& tokens) {
    stack<int> st;

    for (const string& token : tokens) {
        if (isNumber(token)) {
            st.push(stoi(token));
        } else {
            double b = st.top(); st.pop();
            double a = st.top(); st.pop();
            double result = 0;
            if (token == "+") result = a + b;
            else if (token == "-") result = a - b;
            else if (token == "*") result = a * b;
            else if (token == "/") result = a / b;
            st.push(result);
        }
    }

    return st.top();
}
int main() {
    // string line;
    // while (getline(cin, line) && !line.empty()) {
    //     stringstream ss(line);
    //     string token;
    //     vector<string> tokens;\
    //     while (ss >> token) {
    //         tokens.push_back(token);
    //     }
    //     cout << fixed << setprecision(6) << evalRPN(tokens) << '\n';
        
    // }

    int n;

    while (cin >> n)
    {
        if(n == 0) return 0;
        vector<int> v(n);
        for(auto &it : v) cin >> it;
        unordered_map<int, int>mp;
        vector<int> ans;
        for(auto  it : v) mp[it]++;
        for(auto it : mp) {
            if(it.second > n / 2) ans.push_back(it.first);
        }
        if(ans.size()) {
            for(auto it : ans) cout << it << '\n';
        } else cout << "NO COLOR" << '\n';
    }
    
    return 0;
}
accuracy: 1
time_ms: 580
memory_kb: 9556
final_rank: 11

code_snippet: #include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
using namespace std;

int main() {
    fastio;
    
    int n;
    while (cin >> n && n != 0) {
        vector<int> arr(n);
        map<int, int> freq;
        
        for (int i = 0; i < n; i++) {
            cin >> arr[i];
            freq[arr[i]]++;
        }
        
        bool found = false;
        int result = 0;
        
        for (map<int, int>::iterator it = freq.begin(); it != freq.end(); it++) {
            int color = it->first;
            int count = it->second;
            
            if (count > n / 2) {
                found = true;
                result = color;
                break;
            }
        }
        
        if(found)
            cout << result << "\n";
		else
            cout << "NO COLOR" << "\n";
    }
    
    return 0;
}
accuracy: 1
time_ms: 460
memory_kb: 10788
final_rank: 10

code_snippet: #include <iostream>
#include <vector>
#include <map>
using namespace std;
int main() {
    long long  n;
    while(cin >> n){
        if(n == 0){
            break;
        }
        map<long long, long long> num;
        long long half = n / 2, result = 0;
        for(long long i = 0 ; i < n ; i++){
            long long temp;
            cin >> temp;
            num[temp]++;
            if(num[temp] > half){
                result = temp;
            }
        }
        if(result == 0){
            cout << "NO COLOR\n";
        }else{
            cout << result << "\n";
        }
    }
}
accuracy: 1
time_ms: 970
memory_kb: 5384
final_rank: 13

code_snippet: #include <bits/stdc++.h>

signed main() {
    int n;
    while (std::cin >> n) {
        if (!n) {
            return 0;
        }
        std::vector<int> a(n);
        for (int i = 0; i < n; i++) {
            std::cin >> a[i];
        }
        std::sort(a.begin(), a.end());
        if (std::count(a.begin(), a.end(), a[n / 2]) > n / 2) {
            std::cout << a[n / 2] << "\n";
        } else {
            std::cout << "NO COLOR\n";
        }
    }
}
accuracy: 1
time_ms: 850
memory_kb: 8328
final_rank: 15

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    while (cin >> n, n) {
        map<int, int> mp;
        for (int i = 0; i < n; i++) {
            int a;
            cin >> a;
            mp[a] += 1;
        }
        int res = -1;
        for (auto p : mp)
            if (p.second + p.second > n) res = p.first;
        if (res == -1) {
            cout << "NO COLOR" << endl;
        } else {
            cout << res << endl;
        }
    }
}
accuracy: 1
time_ms: 480
memory_kb: 4684
final_rank: 1

code_snippet: #include <algorithm>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const double EPS = 1e-8;
const ll MAXN = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 1e6 + 5;

int a[N];


int main(int argc, char* argv[]) {
   
    std::ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, x;
label:
    while(~scanf("%d", &n)) {
        if(!n) break;
        map<int, int> m;
        for(int i = 0; i < n; i++) {
            scanf("%d", &x);
            // m[a[i]]++;
            m[x]++;
        }
        double tmp = n / 2.0;
        for (auto i : m) {
            if (i.second > tmp) {
                printf("%d\n", i.first);
                goto label;
            }
        }
        puts("NO COLOR");
    }

    return 0;
}
accuracy: 1
time_ms: 500
memory_kb: 5060
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) return 0;
        vector<int> a(n);
        for(int i = 0; i < n; i++){
            cin >> a[i];
        }
        vector<int> temp = a;
        sort(temp.begin(), temp.end());
        temp.erase(unique(temp.begin(), temp.end()), temp.end());
        for(int i = 0; i < n; i++) a[i] = lower_bound(temp.begin(), temp.end(), a[i]) - temp.begin();
        vector<int> cnt(temp.size());
        for(int i = 0; i < n; i++) cnt[a[i]]++;
        int ans = 0;
        for(int i = 0; i < (int)temp.size(); i++){
            if(2 * cnt[i] > n) ans = temp[i];
        }
        if(ans == 0) cout << "NO COLOR" << endl;
        else cout << ans << endl;
    }
}
accuracy: 1
time_ms: 830
memory_kb: 14036
final_rank: 19

code_snippet: #include<iostream>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<bitset>
#include<vector>
#include<string>
#include <iomanip>
#include <deque>
#include<list>
#include<cmath>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using P_S=pair<int,string>;
using P_D=pair<double,int>;
using T=tuple<int,int,char,ll,string>;

int main(){
    int n;
    while(1){
        cin>>n;
       if(n==0) break;
       map<int,int>c;
       rep(i,n){
           int a;
           cin>>a;
           c[a]++;
       }
       int ans=-1;
       for(auto m:c){
           //cout<<m.second<<endl;
           if(m.second*2>n){
           ans=m.first;
           break;
           }
       }
       if(ans==-1) cout<<"NO COLOR"<<endl;
       else cout<<ans<<endl;
    }
}
accuracy: 1
time_ms: 840
memory_kb: 4880
final_rank: 8

code_snippet: #include<cstdio>
#include<map>
int main(){for(int t,n,r,i;scanf("%d",&n),n;printf(~r?"%d\n":"NO COLOR\n",r)){std::map<int,int>c;r=-1;for(i=0;i++<n;r=++c[t]>n/2?t:r)scanf("%d",&t);}}
accuracy: 1
time_ms: 570
memory_kb: 4200
final_rank: 4

code_snippet: #define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
  	int n;
  	while (cin >> n, n > 0){
	   map<int, int> m;
	   int ret;
	   for (int i = 0; i < n; i++){
		  int x;
		  cin >> x;
		  m[x]++;   
		}
	  bool ok = false;
	  for (auto it : m){
		 if (it.s > n / 2){
			ok = true;
			ret = it.f;
			break; 
		  }
		}
	 if (ok) cout << ret << endl;
	 else cout << "NO COLOR" << endl;	
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}
accuracy: 1
time_ms: 500
memory_kb: 5128
final_rank: 5

code_snippet: #include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  while (cin >> n && n) {
    VI a(n);
    REP(i, 0, n) cin >> a[i];
    int cnt = 0;
    int cur = -1;
    REP(i, 0, n) {
      if (cnt == 0) {
        cur = a[i];
        cnt = 1;
      } else if (cur == a[i]) {
        cnt += 1;
      } else {
        cnt -= 1;
      }
    }
    cnt = 0;
    REP(i, 0, n) cnt += a[i] == cur;
    if (2 * cnt > n) {
      cout << cur << endl;
    } else {
      cout << "NO COLOR" << endl;
    }
  }
}
accuracy: 1
time_ms: 210
memory_kb: 8260
final_rank: 2

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

int main()
{
    int n, c;
    map<int,int> m;

    while( cin >> n )
    {
        if( !n )
            break;

        int id = 0, max = 0;
        for( int i = 0; i < n; i++ )
        {
            cin >> c;

            if( m[c] == 0 )
                m[c] = 1;
            else
                m[c]++;

            if( m[c] > max )
            {
                max = m[c];
                id = c;
            }
        }
        if( max > n / 2 )
            cout << id << endl;
        else
            cout << "NO COLOR" << endl;
        m.clear();
    }
    return 0;
}
accuracy: 1
time_ms: 1340
memory_kb: 4548
final_rank: 18

code_snippet: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,f=-1;
  long num;
  cin >> n;
  while(n!=0){
  vector<long> ar;
  f=-1;
  for(int i=0;i<n;i++){
  cin >> num;
    ar.push_back(num);
  }
  sort(ar.begin(),ar.end());
  int i=0;
  while(i<n){
    num=ar[i];
    int j=i+1;
    while(num==ar[j]&&j<n){
      j++;
    }
    if(2*(j-i)>n){
      f=num;
      break;
    }
    i=j;
  }
    if(f==-1) cout<<"NO COLOR"<<endl;
    else cout << f<<endl;
    cin >> n;
  }
}
accuracy: 1
time_ms: 890
memory_kb: 18984
final_rank: 20

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

int a[1000000];

signed main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    sort(a,a+n);
    int count=0,ans=0;
    if(n==1) cout<<a[0]<<endl;
    else{
      for(int i=0;i<n;i++){
	if(i==0) continue;
	if(a[i]==a[i-1]) count++;
	if(a[i]!=a[i-1]||i==n-1){
	  if(2*(count+1)>n){
	    cout<<a[i-1]<<endl;
	    ans=1;
	    break;
	  }
	  count=0;
	}
      }
      if(ans==0)
	cout<<"NO COLOR"<<endl;
    }
  }
  return 0;
}
accuracy: 1
time_ms: 830
memory_kb: 10884
final_rank: 17

code_snippet: #include <bits/stdc++.h>
#define full(c) c.begin(), c.end()
typedef signed long long int ll;
typedef unsigned long long int ull;
using namespace std;

int main(){
  while(1){
    bool end=false;
    int i,n;
    map<int, int> cnt;
    cin>>n;
    if(n==0) break;
    for(i=0; i<n; i++){
      int a;
      cin>>a;
      cnt[a]++;
      if(cnt[a] > n/2){
        cout<<a<<endl;
        end=true;
        break;
      }
      if(end==true) break;
    }
    if(end == true){
      i++;
      while(i < n){
        int a;
        cin>>a;
        i++;
      }
      continue;
    }
    cout<<"NO COLOR"<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 1230
memory_kb: 4596
final_rank: 16

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

typedef long long ll;

int main(){
  while(1){
  map<ll,ll> M;
  ll n;
  cin>>n;
  if(n==0){break;}
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    M[a]++;
  }
  bool done=false;
  for(auto i=M.begin();i!=M.end();i++){
    if((*i).second>n/2){cout<<(*i).first<<endl; done=true; break;}
  }
  if(!done){cout<<"NO COLOR"<<endl;}
  }

    return 0;
}
accuracy: 1
time_ms: 1070
memory_kb: 5144
final_rank: 14

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

int main(){
    int n;
    while(scanf("%d", &n), n){
        map<int,int> m;
        int a;
        for(int i = 0; i < n; i++){
            scanf("%d", &a);
            m[a]++;
        }

        string res = "NO COLOR";
        for(auto p : m) if(p.second > n/2)  res = to_string(p.first);
        printf("%s\n", res.c_str());
    }
    return 0;
}
accuracy: 1
time_ms: 560
memory_kb: 4660
final_rank: 6

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

int main(){
    int n;
    while(cin >> n, n){
        map<int,int> m;
        int a;
        for(int i = 0; i < n; i++){
            cin >> a;
            m[a]++;
        }

        string res = "NO COLOR";
        for(auto p : m) if(p.second > n/2)  res = to_string(p.first);
        cout << res << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 1000
memory_kb: 4788
final_rank: 12

code_snippet: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  while(cin>>n,n){
    int ans=-1;
    map<int,int>m;
    r(i,n){
      int a;
      scanf("%d",&a);
      m[a]++;
      if(m[a]>n/2)ans=a;
    }
    if(ans==-1)cout<<"NO COLOR"<<endl;
    else cout<<ans<<endl;
  }
}
accuracy: 1
time_ms: 700
memory_kb: 4688
final_rank: 7