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<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n;
	while(cin>>n,n){
		vvi in(n,vi(4));
		rep(i,n)rep(j,4)cin>>in[i][j];
		map<int,map<int,vi> >m;
		vi h;
		rep(i,n)m[-in[i][2]][in[i][3]].pb(i);
		for(map<int,map<int,vi> >::iterator it=m.begin();it!=m.end();it++){
			int t=it->first;
			for(map<int,vi>::iterator itt=m[t].begin();itt!=m[t].end();itt++){
				vi out=itt->second;
//				rep(i,out.size())cout<<in[out[i]][0]<<endl;
				vector<pii>w;
				rep(i,out.size())w.pb(pii(in[out[i]][0],out[i]));
				sort(all(w));
				rep(i,w.size()){
					int co=0;
					bool H=false;
					rep(j,h.size())if(in[h[j]][1]==in[w[i].second][1])co++;
					if(h.size()<10){
						if(co<3)H=true;
					}else if(h.size()<20){
						if(co<2)H=true;
					}else if(h.size()<26){
						if(co<1)H=true;
					}
					if(H){
						h.pb(w[i].second);
						cout<<w[i].first<<endl;
					}
				}
			}
		}
	}
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

struct team{
	int id;
	int bl;
	int an;
	int pn;
};

int main()
{
	int n, m, u[1001];
	team t[301], s;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		}
		fill(u, u+1001, 0);
		for(int i = 0; i < n; i++){
			cin >> t[i].id >> t[i].bl >> t[i].an >> t[i].pn;
		}
		
		for(int i = n-1; i >= 0; i--){
			for(int j = 1; j <= i; j++){
				if(t[j-1].id > t[j].id){
					s = t[j];
					t[j] = t[j-1];
					t[j-1] = s;
				}
			}
		}
		
		for(int i = n-1; i >= 0; i--){
			for(int j = 1; j <= i; j++){
				if(t[j-1].pn > t[j].pn){
					s = t[j];
					t[j] = t[j-1];
					t[j-1] = s;
				}
			}
		}
		
		for(int i = n-1; i >= 0; i--){
			for(int j = 1; j <= i; j++){
				if(t[j-1].an < t[j].an){
					s = t[j];
					t[j] = t[j-1];
					t[j-1] = s;
				}
			}
		}
		
		m = 0;
		for(int i = 0; i < n && m < 26; i++){
			if(u[t[i].bl] == 0){
				u[t[i].bl]++;
				cout << t[i].id << endl;
				m++;
			} else if(u[t[i].bl] == 1 && m < 20){
				u[t[i].bl]++;
				cout << t[i].id << endl;
				m++;
			} else if(u[t[i].bl] == 2 && m < 10){
				u[t[i].bl]++;
				cout << t[i].id << endl;
				m++;
			}
		}
	}
	
	return 0;
}

C++: #include<stdio.h>
#include<string.h>

int main(){
	int team[301][4],U[1001],n,i,j,sen,k,a,deru[27];
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		memset(team,0,sizeof(team));
		
		for(i=0;i<n;i++){
			for(j=0;j<4;j++)
			scanf("%d",&team[i][j]);
		}

		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				if(team[i][0]>team[j][0]){
					for(k=0;k<4;k++){
						a=team[i][k];
						team[i][k]=team[j][k];
						team[j][k]=a;
					}
				}
			}
		}
		
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				if(team[i][3]>team[j][3]){
					for(k=0;k<4;k++){
						a=team[i][k];
						team[i][k]=team[j][k];
						team[j][k]=a;
					}
				}
			}
		}
		
		for(i=0;i<n;i++){
			for(j=i;j<n;j++){
				if(team[i][2]<team[j][2]){
					for(k=0;k<4;k++){
						a=team[i][k];
						team[i][k]=team[j][k];
						team[j][k]=a;
					}
				}
			}
		}
		memset(U,0,sizeof(U));
		memset(deru,0,sizeof(deru));
		sen=1;
		deru[0]=team[0][0];
		i=1;
		U[team[0][1]]=1;
		while(0!=team[i][0]){
			if(sen<10 && U[team[i][1]]<3){
				++U[team[i][1]];
				deru[sen]=team[i][0];
				++sen;
				++i;
				continue;
			}
			
			if(sen<20 && U[team[i][1]]<2){
				++U[team[i][1]];
				deru[sen]=team[i][0];
				++sen;
				++i;
				continue;
			}
			
			if(sen<26 && U[team[i][1]]==0){
				++U[team[i][1]];
				deru[sen]=team[i][0];
				++sen;
				++i;
				continue;
			}
			++i;
			if(i>=n)break;
		}
		i=0;
		while(deru[i]!=0){
			printf("%d\n",deru[i]);
			++i;
		}
	}
	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]++;
				sum++;
			}
			else if(sum<20 && idcount[team[i].belong]<2){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
				sum++;
			}
			else if(sum<26 && idcount[team[i].belong]==0){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
				sum++;
			}
		}
	}
}