Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	for n := getNextInt(scanner); n > 0; n = getNextInt(scanner) {
		tt := make([]team, n)
		for i := 0; i < n; i++ {
			tt[i].id = getNextInt(scanner)
			tt[i].uni = getNextInt(scanner)
			tt[i].ac = getNextInt(scanner)
			tt[i].pn = getNextInt(scanner)
		}
		sort.SliceStable(tt, func(i, j int) bool {
			if tt[i].ac == tt[j].ac {
				if tt[i].pn == tt[j].pn {
					return tt[i].id < tt[j].id
				}
				return tt[i].pn < tt[j].pn
			}
			return tt[i].ac > tt[j].ac
		})
		cc := make([]int, 100005)
		ans := make([]int, 0)
		for i := 0; i < n; i++ {
			if cc[0] < 10 && cc[tt[i].uni] < 3 {
				cc[0]++
				cc[tt[i].uni]++
				ans = append(ans, tt[i].id)
				continue
			}
			if cc[0] < 20 && cc[tt[i].uni] < 2 {
				cc[0]++
				cc[tt[i].uni]++
				ans = append(ans, tt[i].id)
				continue
			}
			if cc[0] < 26 && cc[tt[i].uni] < 1 {
				cc[0]++
				cc[tt[i].uni]++
				ans = append(ans, tt[i].id)
				continue
			}
		}
		for i := 0; i < len(ans); i++ {
			fmt.Fprintln(writer, ans[i])
		}
	}
}

type team struct {
	id, uni, ac, pn int
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

int main() {
  int n;
  while(cin >> n && n) {
    vector<PP> teams;
    rep(i, n) {
      int i, u, a, p;
      cin >> i >> u >> a >> p;
      teams.push_back(PP(P(-a, p), P(i, u)));
    }
    sort(ALL(teams));

    vector<int> ans;
    map<int, int> count;
    rep(i, n) {
      int c = ans.size();
      PP &e = teams[i];
      int id = e.second.first, u = e.second.second,
          a = -e.first.first, p = e.first.second;
      count[u] += 1;
      if(c < 10) {
        if(count[u]<=3) {
          ans.push_back(id);
        }
      }else if(c < 20) {
        if(count[u]<=2) {
          ans.push_back(id);
        }
      }else if(c < 26) {
        if(count[u]<=1) {
          ans.push_back(id);
        }
      }
    }
    rep(i, ans.size()) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int a,b,c,d,n,cnt,tmp;
string str;
int id[300],id2[300],ac[300],wa[300],used[1001];

void change(int x){
  tmp=id[x];id[x]=id[x+1];id[x+1]=tmp;
  tmp=id2[x];id2[x]=id2[x+1];id2[x+1]=tmp;
  tmp=ac[x];ac[x]=ac[x+1];ac[x+1]=tmp;
  tmp=wa[x];wa[x]=wa[x+1];wa[x+1]=tmp;
}
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>id[i]>>id2[300]>>ac[300]>>wa[300];
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(id[j]>id[j+1]){
	  change(j);
	}
      }
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(wa[j]>wa[j+1]){
	  change(j);
	}
      }
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(ac[j]<ac[j+1]){
	  change(j);
	}
      }
    }
    cnt=0;
    for(int i=0;i<1001;i++)used[i]=0;

    for(int i=0;i<n;i++){
      if(cnt<10){
	if(used[id2[i]]<3){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }else if(cnt<20){
	if(used[id2[i]]<2){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }else if(cnt<26){
	if(used[id2[i]]==0){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }
    }


  }
  
  return 0;
}

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

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1;
    for (size_t i = 0; i < size; ++i) {
        vec1.push_back(cin2var<T>());
    }
    return vec1;
}

struct Team
{
    int id;
    int group;
    int answer;
    int penalty;
};

int main()
{
    vec1<Team>              teams;
    vec1<Team>              winner;
    unordered_map<int, int> map_group_wins;
    while (true) {
        const auto N(cin2var<int>());
        if (!N) break;
        teams.clear();
        winner.clear();
        map_group_wins.clear();
        for (int i = 0; i < N; ++i) {
            const auto Ns(cin2vec<int>(4));
            auto       ite(Ns.cbegin());
            Team       team{};
            team.id      = *ite++;
            team.group   = *ite++;
            team.answer  = *ite++;
            team.penalty = *ite++;
            teams.push_back(move(team));
        }
        sort(teams.begin(), teams.end(), [](const Team& l, const Team& r) {
            if (l.answer < r.answer) return false;
            if (l.answer > r.answer) return true;
            if (l.penalty < r.penalty) return true;
            if (l.penalty > r.penalty) return false;
            return l.id < r.id;
        });
        for (const auto& team : teams) {
            const bool is_win = [&] {
                const auto winner_size(winner.size());
                const auto group_wins(map_group_wins[team.group]);
                if (winner_size < 10 && group_wins < 3) {
                    return true;
                }
                if (winner_size < 20 && group_wins < 2) {
                    return true;
                }
                if (winner_size < 26 && group_wins == 0) {
                    return true;
                }
                return false;
            }();
            if (is_win) {
                cout << team.id << endl;
                ++map_group_wins[team.group];
                winner.push_back(team);
            }
        }
    }
    return 0;
}