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 <map>
using namespace std;

class Team{
public:
  int i,u,a,p;
  bool operator<(const Team &t)const{
    if(a!=t.a) return a>t.a;
    else if(p!=t.p) return p<t.p;
    else return i<t.i;
  }
};

int main(void){
  int n;
  while(cin>>n,n){
    vector<Team> teams;
    for(int i=0;i<n;++i){
      Team t;
      cin>>t.i>>t.u>>t.a>>t.p;
      teams.push_back(t);
    }
    sort(teams.begin(),teams.end());
    map<int,int> univ;
    vector<int> ans;
    for(int i=0;i<n;++i){
    	if(count(ans.begin(),ans.end(),teams[i].i))continue;
    	if(ans.size()<10){
    		if(univ[teams[i].u]<3){++univ[teams[i].u];ans.push_back(teams[i].i);i=0;}
    	}else if(ans.size()<20){
    		if(univ[teams[i].u]<2){++univ[teams[i].u];ans.push_back(teams[i].i);i=0;}
    	}else if(ans.size()<26){
    		if(univ[teams[i].u]==0){++univ[teams[i].u];ans.push_back(teams[i].i);i=0;}
    	}
    }
  	for(int i=0;i<ans.size();++i)cout<<ans[i]<<endl;
  }
  return 0;
}

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

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	while(cin>>n,n){
		vector<pair<pii,pii> > v;
		vint tt(2000,0);
		rep(i,n){
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			v.PB(mkp(mkp(100-c,d),mkp(a,b)));
		}
		sort(ALL(v));
		// rep(i,n){
			// cout<<v[i].S.F<<" "<<v[i].S.S<<endl;
		// }
		int cnt=0;
		rep(i,n){
			bool f=false;
			if(cnt<10&&tt[v[i].S.S]<3){
				f=true;
			}
			else if(cnt<20&&tt[v[i].S.S]<2){
				f=true;
			}
			else if(cnt<26&&tt[v[i].S.S]<1){
				f=true;
			}
			if(f){
				cnt++;
				cout<<v[i].S.F<<endl;
			}
		}
	}
}

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

typedef pair <int, int> PII;
typedef pair <PII, PII> PPP;
typedef vector <PPP> VPPP;
typedef vector <int> VI;

int main() {
    int n;
    while ( cin >> n && n ) {
        VPPP L(n);
        VI H(1000,0);
        for ( int i = 0; i < n; ++ i ) {
            cin >> L[i].second.first >> L[i].second.second;
            cin >> L[i].first.first >> L[i].first.second;
            L[i].second.first = 1000 - L[i].second.first;
            L[i].second.second = 1000 - L[i].second.second;
            L[i].first.second = 100000 - L[i].first.second;
        }
        sort( L.rbegin(), L.rend() );
        int cnt = 0;
        for ( int i = 0; i < n; ++ i ) {
            int ID = 1000 - L[i].second.first;
            int AF = 1000 - L[i].second.second;
            bool flag = false;
            if ( cnt < 10 ) {
                if ( H[AF] < 3 ) {
                    cnt ++;
                    H[AF] ++;
                    flag = true;
                }
            } else if ( cnt < 20 ) {
                if ( H[AF] < 2 ) {
                    cnt ++;
                    H[AF] ++;
                    flag = true;
                }
            } else if ( cnt < 16 ) {
                if ( H[AF] < 1 ) {
                    cnt ++;
                    H[AF] ++;
                    flag = true;
                }
            }
            if ( flag ) cout << ID << endl;
        }
    }
	return 0;
}

C++: #include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
struct box{
	int id,bel,acc,pen;
};
bool cpm(const box &a,const box &b){
	if(a.acc!=b.acc)
	return a.acc>b.acc;
	else if(a.pen!=b.pen)
	return a.pen<b.pen;
	else
	return a.id<b.id;
}
int main(){
	int n;
	while(cin>>n,n){
		int now=0;
		map<int,int> mp;
		vector<box> tab;
		box e;
		for(int i=0;i<n;i++){
			cin>>e.id>>e.bel>>e.acc>>e.pen;
			tab.push_back(e);
		}
		sort(tab.begin(),tab.end(),cpm);
		for(int i=0;i<n;i++){
			if(now<10){
				if(mp[tab[i].bel]<3){
					mp[tab[i].bel]++;
					now++;
					cout<<tab[i].id<<endl;
				}
			}else if(now<20){
				if(mp[tab[i].bel]<2){
					mp[tab[i].bel]++;
					now++;
					cout<<tab[i].id<<endl;
				}
			}else if(now<26){
				if(mp[tab[i].bel]==0){
					mp[tab[i].bel]++;
					now++;
					cout<<tab[i].id<<endl;
				}
			}else break;
		}
	}
	return 0;
}