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<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP((i),0,(n))
#define RREP(i,a,b) for(int i=(int)(b-1);i>=(int)(a);i--)
#define rrep(i,n) RREP(i,n,0)
#define each(it,X) for(__typeof((X).begin())  it=(X).begin();it!=(X).end();it++)
#define all(v) ((v).begin(),(v).end())
#define rall(v) ((v).rbegin(),(v).rend())
#define fi first
#define se second
#define pb push_back
typedef long long LL;
typedef pair<int,int>P;
typedef pair<P,int>PI;
typedef pair<int,P>IP;
typedef vector<int>VI;
typedef vector<VI>VVI;
typedef vector<string>VS;


struct D{
    int id,u,a,p;

    D(int id,int u,int a,int p):id(id),u(u),a(a),p(p){}
    D(){}

    bool operator<(const D &d)const{
        if(a!=d.a)return a<d.a;
        if(p!=d.p)return p>d.p;
        return id>d.id;
    }
};



int main(){
    int N;
    while(cin>>N,N){
        vector<D>V(N);
        for(int i=0;i<N;i++){
            int a,b,c,d;
            cin>>a>>b>>c>>d;
            V[i]=D(a,b-1,c,d);
        }

        sort(V.rbegin(),V.rend());
        int U[1000]={0};
        int cnt=0;
        for(int i=0;i<N;i++){
            if(U[V[i].u]<(cnt<10?3:(cnt<20?2:(cnt<26?1:0)))){
                cout<<V[i].id<<endl;
                U[V[i].u]++;
                cnt++;
            }
        }
    }

    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};

vector<bool> used;
vector<int> count_t;
vector<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) ) );
	    sort(ALL(t));
	}
	used = vector<bool>(200000,false);
	count_t = vector<int>(200000,0);
	isDecided = vector<bool>(200000,false);
	int temp = 0;

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

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


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

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

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

    return 0;
}

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

#define MAX 1000
#define AMAX 100

class Team{
    public:
    int id, aff, acc, pen;
    Team( int i = 0, int f = 0, int a = 0, int p = 0 ):
	id(i), aff(f), acc(a), pen(p){}

    bool operator < ( const Team &t ) const {
	if ( acc == t.acc ){
	    if ( pen == t.pen ) {
		return id < t.id;
	    } else return pen < t.pen;
	} else return acc > t.acc;
    }
};

Team T[MAX];
int n;

void compute(){
    sort( T, T + n );
    int selected[AMAX] = {0};
    
    int nselected = 0;

    for ( int i = 0; i < n; i++ ){
	int aff = T[i].aff;
	int id = T[i].id;
	if ( nselected < 10 ){
	    if ( selected[aff] < 3 ){
		nselected++;
		selected[aff]++;
		cout << id << endl;
	    }
	} else if ( nselected < 20 ){
	    if ( selected[aff] < 2 ){
		nselected++;
		selected[aff]++;
		cout << id << endl;
	    }
	} else if ( nselected < 26 ){
	    if ( selected[aff] == 0 ){
		nselected++;
		selected[aff]++;
		cout << id << endl;
	    }
	}
    }
}

main(){
    while ( cin >> n &&  n ){
	for ( int i = 0; i < n; i++ ){
	    cin >> T[i].id >> T[i].aff >> T[i].acc >> T[i].pen;
	   
	}
	compute();
    }
}

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

struct data{
    int i, u, a, p;
    data(int _i, int _u, int _a, int _p) : i(_i), u(_u), a(_a), p(_p) {}
    bool operator<(const data other) const{
        if(a != other.a)      return a > other.a;
        else if(p != other.p) return p < other.p;
        else                  return i < other.i;               
    }
};

int main(){
    int n;
    while(cin >> n, n){
        int i, u, a, p;
        vector<data> v;
        
        for(int t = 0; t < n; t++){
            cin >> i >> u >> a >> p;
            v.push_back(data(i,u,a,p));
        }
        
        sort(v.begin(), v.end());
        
        int uni[1001] = {};
        int passed = 0;

        for(data x : v){
            bool rulea = passed < 10 && uni[x.u] < 3;
            bool ruleb = passed < 20 && uni[x.u] < 2;
            bool rulec = passed < 26 && uni[x.u] < 1;
            if(rulea || ruleb || rulec){
                cout << x.i << endl;
                uni[x.u]++;
                passed++;
            }
        }

    }
    return 0;
}