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(v, a, b) for(int v = (int)(a); v < (int)(b); ++v)
#define FORE(v, a, b) for(int v = (int)(a); v <= (int)(b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

void split(string str, char chr, vector< string > *res){
	stringstream ss(str);
	string itm;
	while(getline(ss, itm, chr)){
		(*res).PB(itm);
	}
}

class Score{
public:
	int i, u, a, p;
	Score() : i(0), u(0), a(0), p(0) {}
};

bool comp(Score a, Score b){
	if(a.a != b.a){
		return a.a > b.a;
	}
	if(a.p != b.p){
		return a.p < b.p;
	}
	return a.i < b.i;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, i, u, p, a;
	vector< Score > s;
	queue< int > q;
	vector< int > univ;
	
	
	while(cin >> n, n){
		s.RS(n);
		univ.CLR();
		univ.RS(1000);
		
		REP(j, n){
			cin >> i >> u >> a >> p;
			s[j].i = i;
			s[j].u = u;
			s[j].a = a;
			s[j].p = p;
		}
		
		sort(ALL(s), comp);
		
		REP(j, n){
			if(q.size() < 10 && univ[s[j].u - 1] < 3){
				q.push(s[j].i);
				++univ[s[j].u - 1];
			}else if(q.size() < 20 && univ[s[j].u - 1] < 2){
				q.push(s[j].i);
				++univ[s[j].u - 1];
			}else if(q.size() < 26 && univ[s[j].u - 1] == 0){
				q.push(s[j].i);
				++univ[s[j].u - 1];
			}
		}
		
		while(!q.empty()){
			cout << q.front() << endl;
			q.pop();
		}
	}
	
	return 0;
}

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

using namespace std;

class Rank {
public:
  int I, U, A, P;
  Rank();
  Rank(int I, int U, int A, int P) : I(I), U(U), A(A), P(P) {}

};

bool comp(const Rank &r1, const Rank &r2) {
  if(r1.A != r2.A) return r1.A > r2.A;
  if(r1.P != r2.P) return r1.P < r2.P;
  return r1.I < r2.I;
}

int main() {
  
  int n;
  int ii, uu, aa, pp;
  while(cin >> n && n) {
    vector<Rank> vec;
    for(int i=0; i<n; i++) {
      cin >> ii >> uu >> aa >> pp;
      vec.push_back(Rank(ii, uu, aa, pp));
    }
    sort(vec.begin(), vec.end(), comp);
    
    vector<Rank> res;
    vector<int> UCnt(1001,0);
    
    for(int i=0; i<vec.size(); i++) {
      if(res.size() < 10 && UCnt[vec[i].U] < 3) {
	res.push_back(vec[i]);
      }
      else if(res.size() < 20 && UCnt[vec[i].U] < 2) res.push_back(vec[i]);
      else if(res.size() < 26 && UCnt[vec[i].U] == 0) res.push_back(vec[i]);
      UCnt[vec[i].U] ++;
    }
    
    for(int i=0; i<res.size(); i++) {
      cout << res[i].I << endl;
    }
  }
  
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;

int main() {
    int N;
    while (cin >> N, N) {
        vector<vector<P> > rank(11);
        vector<int> univ_id(1001);

        for (int c = 0; c < N; c++) {
            int i, u, a, p;
            cin >> i >> u >> a >> p;
            rank[a].push_back(P(p,i));
            univ_id[i] = u;
        }

        for (auto& i : rank)
            sort(i.begin(), i.end());

        int count = 0;
        vector<int> univ_cnt(1001);
        for (int i = 10; i > -1; i--) {
            for (auto team : rank[i]) {
                int I = team.second;
                int pena = team.first;
                int limit = 0;
                if (count < 10) limit = 3;
                else if (count < 20) limit = 2;
                else if (count < 26) limit = 1;
                if (univ_cnt[univ_id[I]] < limit) {
                    cout << I << endl;
                    univ_cnt[univ_id[I]]++;
                }
            }
        }
    }

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        vector<pair<int, pair<int, int>>> v;
        map<int, int> m, af;
        for(int i=0; i < n; i++){
            int id, u, a, p;
            cin >> id >> u >> a >> p;
            m[i] = u;
            v.push_back(make_pair(a*-1, make_pair(p, id)));
        }
        sort(v.begin(), v.end());
        int count = 0;
        for(int i=0; i< n; i++){
            if(count < 10 && af[m[i]] < 3 || count < 20 && af[m[i]] < 2 || count < 26 && af[m[i]] < 1){cout << v[i].second.second << endl; af[m[i]]++; count++;}
        }
    }
}

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

using namespace std;

struct DATA{
  int id, t, ac, pn;
  DATA(){}
};

bool comp(const DATA& a, const DATA& b){
  if(a.ac != b.ac) return a.ac > b.ac;
  if(a.pn != b.pn) return a.pn < b.pn;
  return a.id < b.id;
}

int main(){
  int n;
  while(1){
    cin >> n;
    if(!n) break;
    map<int, int> team;
    vector<int> ans;
    vector<DATA> data(n,DATA());
    for(int i=0; i<n; ++i){
      cin >> data[i].id >> data[i].t >> data[i].ac >> data[i].pn;
      team.insert(make_pair(data[i].t, 0));
    }
    sort(data.begin(), data.end(), comp);
    for(int i=0; i<data.size() && ans.size()<26; ++i){
      if(ans.size() < 10){
	if(team[data[i].t] < 3){
	  ans.push_back(data[i].id);
	  ++team[data[i].t];
	}
      }else if(ans.size() < 20){
	if(team[data[i].t] < 2){
	  ans.push_back(data[i].id);
	  ++team[data[i].t];
	}
      }else{
	if(team[data[i].t] < 1){
	  ans.push_back(data[i].id);
	  ++team[data[i].t];
	}
      }
    }
    for(int i=0; i<ans.size(); ++i) cout << ans[i] << endl;
  }
  return 0;
}