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>
#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<int> 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>(20000,false);
	count_t = vector<int>(20000,0);
	isDecided = vector<bool>(20000,false);
	ans = vector<int>();

	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;
		ans.PB(t[i].second.first);
	    }
	}

	if(ans.size() < 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.second-1] = true;
		    ans.PB(t[i].second.first);
		}
	    }
	}


	if(ans.size() < 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;
		    ans.PB(t[i].second.first);
		}
	    }
	}

	if(ans.size() < 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;
		    ans.PB(t[i].second.first);
		}
	    }
	}

	sort(ALL(ans));
	REP(i,ans.size()) cout << ans[i] << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string.h>

using namespace std;

struct log{
	int id,belong,correct,penalty;
};

int main(void){
	
	struct log team[1001];
	int n,idcount[1001];

	while(cin>>n,n){
		
		memset(team,0,sizeof(team));
		memset(idcount,0,sizeof(idcount));
		
		for(int i=1;i<=n;i++){
			cin>>team[i].id>>team[i].belong>>team[i].correct>>team[i].penalty;
		}
		
		for(int i=1;i<=n;i++){
			for(int j=n;j>=i+1;j--){
				if(team[j-1].correct<team[j].correct){
					struct log temp;
					temp=team[j];
					team[j]=team[j-1];
					team[j-1]=temp;
				}
			}
		}

		for(int i=1;i<=n;i++){
			for(int j=n;j>=i+1;j--){
				if(team[j-1].correct==team[j].correct && team[j-1].penalty>team[j].penalty){
					struct log temp;
					temp=team[j];
					team[j]=team[j-1];
					team[j-1]=temp;
				}
			}
		}
			
		for(int i=1;i<=n;i++){
			for(int j=n;j>=i+1;j--){
				if(team[j-1].correct==team[j].correct && team[j-1].penalty==team[j].penalty && team[j-1].id>team[j].id){
					struct log temp;
					temp=team[j];
					team[j]=team[j-1];
					team[j-1]=temp;
				}
			}
		}
	
		
		for(int i=1,sum=0;i<=n;i++){
			if(sum<10 && idcount[team[i].belong]<3){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
			else if(sum<=10 && sum<20 && idcount[team[i].belong]<2){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
			else if(sum<=20 && sum<26 && idcount[team[i].belong]==0){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
				sum++;
			}
		}
	}
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

class team{
public:
	int I,U,A,P;
	team(int a, int b, int c, int d){
		I=a, U=b, A=c, P=d;
	}
	bool operator<(const team& a)const{
		if( A>a.A ) return true;
		if( A<a.A ) return false;
		if( P<a.P ) return true;
		if( P>a.P ) return false;
		return I<a.I;
	}
};

int main(){
	int n;
	while(scanf("%d",&n),n){
		vector<team> v;
		map<int,int> m;
		rep(i,n){
			int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d);
			v.push_back( team(a,b,c,d) );
		}
		sort( v.begin(), v.end() );
		
		int cnt = 0;
		rep(i,v.size()){
			if( cnt<10 ){
				if( m[v[i].U]<3 ){
					printf("%d\n",v[i].I);
					m[v[i].U]++;
					cnt++;
				}
			}else if( cnt<20 ){
				if( m[v[i].U]<2 ){
					printf("%d\n",v[i].I);
					m[v[i].U]++;
					cnt++;
				}
			}else if( cnt<26 ){
				if( m[v[i].U]==0 ){
					printf("%d\n",v[i].I);
					m[v[i].U]++;
					cnt++;
				}
			}
		}
	}
	return 0;
}