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<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>
#include<tuple>

using namespace std;

#define reep(i, s, n) for(int i=s;i<(int)n;i++)
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define REP(i, n) for(int i=0;i<(int)n;i++)
#define all(v) v.begin(), v.end()
#define tyd typedef
#define vc vector
#define pb push_back
#define eb emplace_back
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int IINF = 1<<28;

#define fs first
#define sc second
#define X real()
#define Y imag()
typedef long double R;
R EPS = 1e-9;
inline int sig(const R &x){return abs(x) < EPS ? 0 : x > 0 ? 1 : -1;}
typedef complex<R> P;
inline  R inp(const P &a, const P &b){ return (conj(a)*b).X;}
inline R outp(const P &a, const P &b){ return (conj(a)*b).Y;}
inline int ccw(const P &s, const P &t, const P &p){
	int res = sig(outp(t-s, p-s));
	if(res) return res;
	if(sig(inp(t-s, p-s)) < 0) return -2;
	if(sig(inp(s-t, p-t)) < 0) return 2;
	return 0;
}
int intersect(const P &s0, const P &s1, const P &t0, const P &t1){
	int p = ccw(t0, t1, s0) * ccw(t0, t1, s1);
	int q = ccw(s0, s1, t0) * ccw(s0, s1, t1);
	return !(p>0 || q>0);
}

struct Data
{
	int id, af, sol, pen;
	Data( int id = 0, int af = 0, int sol = 0, int pen = 0 )
		:id(id), af(af), sol(sol), pen(pen)
	{
	}

	friend bool operator < ( const Data& d1, const Data& d2 )
	{
		return (d1.sol == d2.sol ? (d1.pen == d2.pen ? d1.id < d2.id : d1.pen < d2.pen) : d1.sol > d2.sol );
	}
};

int main(){
	Data data[200];
	int n;
	while( cin >> n, n != 0 ){
		rep(i, n){
			int id, af, sol, pen;
			cin >> id >> af >> sol >> pen;
			--af;
			data[i] = Data(id, af, sol, pen);
		}

		sort( data, data+n );
		int cnt_af[1000] = { 0 };
		vi rank;
		rep(i, n){
			if ( rank.size() < 10 ){
				if( cnt_af[data[i].af] < 3 ){
					rank.pb(data[i].id);
					cnt_af[data[i].af]++;
				}
			}
			else if ( rank.size() < 20 ){
				if( cnt_af[data[i].af] < 2 ){
					rank.pb(data[i].id);
					cnt_af[data[i].af]++;
				}
			}
			else if ( rank.size() < 26 ){
				if( cnt_af[data[i].af] == 0 ){
					rank.pb(data[i].id);
					cnt_af[data[i].af]++;
				}
			}			
		}

		rep(i, rank.size()){
			cout << rank[i] << endl;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

map<int,bool> used;
map<int,int> count_t;
map<int,bool> isDecided;
vector<bool> ans;

int main(){
    while(true){
	int n;
	vector< pair< pair<int,int> , pair<int,int> > > t;
	cin >> n;
	if(n==0) break;
	REP(i,n){
	    int I,A,U,P;
	    cin >> I >> U >> A >> P;
	    t.PB( MP( MP(-A,P) , MP(I,U) ) );
	    used[I] = false;
	    count_t[U] = false;
	    isDecided[I] = false;
	}
	sort(ALL(t));
	int temp = 0;

	REP(i,n){
	    if(!used[t[i].second.second]){
		used[t[i].second.second] = true;
		count_t[t[i].second.second]++;
		isDecided[t[i].second.first] = true;
		temp++;
	    }
	}

	if(temp < 10){
	    REP(i,n){
		if(!isDecided[t[i].second.first] && count_t[t[i].second.second] < 3){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
		    temp++;
		}
	    }
	}


	if(temp < 20){
	    REP(i,n){
		if(!isDecided[t[i].second.first] && count_t[t[i].second.second] < 2){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
			temp++;
		}
	    }
	}

	if(temp < 26){
	    REP(i,n){
		if(!isDecided[t[i].second.second] && count_t[t[i].second.second] < 1){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
		    temp++;
		}
	    }
	}

	REP(i,n){
	    if(isDecided[t[i].second.first]) cout << t[i].second.first << endl;
	}
    }

    return 0;
}