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:
  team(int a, int b, int c, int d){
    id = a;
    aff = b;
    ac = c;
    pen = d;
  }
  int id;
  int aff;
  int ac;
  int pen;

  bool operator <(const team arg) const{
    if(ac != arg.ac){
      return ac > arg.ac;
    }else{
      if(pen != arg.pen){
	return pen < arg.pen;
      }else{
	return id < arg.id;
      }
    }
  }
};

int main(void){
  int n;
  while(cin >> n && n){
    vector<team> v;
    map<int,int> m;
    int a,b,c,d;
    int selected = 0;
    for(int i=0;i<n;i++){
      cin >> a >> b >> c >> d;
      v.push_back(team(a,b,c,d));
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
      if(selected < 10 && m[v[i].aff] < 3){
	cout << v[i].id <<endl;
	m[v[i].aff]++;
	continue;
      }
      if(selected < 20 && m[v[i].aff] < 2){
	cout << v[i].id <<endl;
	m[v[i].aff]++;
	continue;
      }
      if(selected < 26 && m[v[i].aff] == 0){
	cout << v[i].id <<endl;
	m[v[i].aff]++;
	continue;
      }
    }
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+7
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

ll n, I, u, a, p;
vector< pair<P, P> > vpp;

bool flag(const pair<P, P> pp1, pair<P, P> pp2){
	if (pp1.first.first == pp2.first.first){
		if (pp1.first.second == pp2.first.second){
			return pp1.second.first < pp2.second.first;
		}
		return pp1.first.second < pp2.first.second;
	}
	return pp1.first.first > pp2.first.first;
}

int main(){
	while (cin >> n&&n){
		vpp.clear();
		ll cntall = 0;
		int cnt[1010] = {};
		REP(i, n){
			cin >> I >> u >> a >> p;
			vpp.push_back(make_pair(P(a, p), P(I, u)));
		}
		sort(ALL(vpp), flag);
		REP(i, vpp.size()){
			int t = vpp[i].second.first, id = vpp[i].second.second;
			if (cntall < 10){
				if (cnt[id] < 3){
					cout << t << endl;
					cnt[id]++;
					cntall++;
				}
			}
			else if (cntall < 20){
				if (cnt[id] < 2){
					cout << t << endl;
					cnt[id]++;
					cntall++;
				}
			}
			else if (cntall < 26){
				if (cnt[id] < 1){
					cout << t << endl;
					cnt[id]++;
					cntall++;
				}
			}
		}
	}
}

C++: #include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstdio>

using namespace std;

typedef pair<int, pair<int, pair<int, int> > > data;

#define f first
#define s second
#define ID s.s.f
#define AF s.s.s
#define SL f
#define PN s.f

#define REP(i,n) for(int i=0; i<(int)(n); i++)


int getInt(){
  int ret; scanf("%d", &ret);
  return ret;
}

int main(){
  while(int n = getInt()){
    vector<data> v(n);

    REP(i, n){
      v[i].ID = -getInt();
      v[i].AF = getInt();
      v[i].SL = getInt();
      v[i].PN = -getInt();
    }

    sort(v.rbegin(), v.rend());

    int all = 0;
    map<int, int> cnt;

    for(int i = 0; i < n; i++){
      int id = -v[i].ID;
      int af = v[i].AF;

      if(all < 10){
	if(cnt[id] < 3){
	  cnt[id]++;
	  cout << id << endl;
	  all++;
	}
      }else if(all < 20){
	if(cnt[id] < 2){
	  cnt[id]++;
	  cout << id << endl;
	  all++;
	}
      }else if(all < 26){
	if(cnt[id] < 1){
	  cnt[id]++;
	  cout << id << endl;
	  all++;
	}
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;

bool cmp(const PP &p,const PP &q){
  if(p.S.F != q.S.F)return p.S.F > q.S.F;
  if(p.S.S != q.S.S)return p.S.S < q.S.S;
}

int main(){
  int n;
  int I,U,A,Po;
  while(cin >> n && n){
    vector<PP> vec;
    map<int,int> entitle; 
    for(int i=0;i<n;i++){
      cin >> I >> U >> A >> Po;
      vec.push_back(PP(P(I,U),P(A,Po)));
    }
    sort(vec.begin(),vec.end(),cmp);
    int limit = n<10?3:n<20?2:1;
    for(int i=0;i<n;i++){
      int AD = vec[i].F.S;
      if(entitle[AD] < limit){
	entitle[AD]++;
	cout << vec[i].F.F << endl;
      }
    }

  }
  return 0;
}

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() );
		
		rep(i,v.size()){
			if( i<10 ){
				if( m[v[i].U]<3 ){
					printf("%d\n",v[i].I);
					m[v[i].U]++;
				}
			}else if( i<20 ){
				if( m[v[i].U]<2 ){
					printf("%d\n",v[i].I);
					m[v[i].U]++;
				}
			}else if( i<26 ){
				if( m[v[i].U]==0 ){
					printf("%d\n",v[i].I);
					m[v[i].U]++;
				}
			}
		}
	}
	return 0;
}