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>

using namespace std;

struct Team {
	int id, univ, ac, pen;
	Team(int id, int univ, int ac, int pen) : id(id), univ(univ), ac(ac), pen(pen){}
	Team(){}
	bool operator < (const Team x) const {
		if (ac != x.ac) return (ac < x.ac);
		if (pen != x.pen) return (pen > x.pen);
		return (id > x.id);
	}
};

int main()
{
	int n;

	while (scanf("%d", &n) && n){
		Team teams[512];
		for (int i = 0; i < n; i++){
			scanf("%d %d %d %d", &teams[i].id, &teams[i].univ, &teams[i].ac, &teams[i].pen);
		}

		sort(teams, teams + n);
		reverse(teams, teams + n);

		int sel = 0;
		int uCount[1024];
		memset(uCount, 0, sizeof(uCount));

		for (int i = 0; i < n; i++){
			if (sel < 10 && uCount[teams[i].univ] < 3){
				printf("%d\n", teams[i].id); uCount[teams[i].univ]++; sel++;
			}
			else if (sel < 20 && uCount[teams[i].univ] < 2){
				printf("%d\n", teams[i].id); uCount[teams[i].univ]++; sel++;
			}
			else if (sel < 26 && uCount[teams[i].univ] < 1){
				printf("%d\n", teams[i].id); uCount[teams[i].univ]++; sel++;
			}
		}
	}

	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;
        int m[1010], uni[1010] = {0};
        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, make_pair(p, id)));
        }
        sort(v.begin(), v.end());
        int count = 0;
        for(int i=0; i< v.size(); i++){
            if((count <= 10 && uni[m[i]] < 3) || (count <= 20 && uni[m[i]] < 2) || (count <= 26 && uni[m[i]] < 1)){cout << v[i].second.second << endl; uni[m[i]]++; count++;}
        }
    }
}

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

typedef long long ll;


struct hoge{
    ll id, solved, penalty, team;
    hoge(ll id, ll solved, ll penalty, ll team) : id(id), solved(solved), penalty(penalty), team(team) { }
};
bool operator < (const hoge &a, const hoge &b){
    return a.solved == b.solved ? (a.penalty == b.penalty ? a.id < b.id : a.penalty < b.penalty) : a.solved > b.solved;
}

int main(void){
    while(true){
        ll n;
        cin >> n;
        if(n==0) break;
        vector<hoge> v;
        for(ll i=0; i<n; i++){
            ll id, u, a, p;
            cin >> id >> u >> a >> p;
            v.push_back(hoge(id, a, p, u));
        }
        sort(v.begin(), v.end());
        
        ll unity[1010];
        ll count=0;
        fill(unity, unity+1010, 0);
        for(ll i=0; i<v.size(); i++){
            unity[v[i].team]++;
            //cout << "i="<<i<<" unity[" <<v[i].team << "]=" << unity[v[i].team] << "\n";
            if(count<10){
                if(unity[v[i].team]<=3){
                    cout << v[i].id << "\n";
                    count++;
                }
            }else if(count<20){
                if(unity[v[i].team]<=2){
                    cout << v[i].id << "\n";
                    count++;
                }
            }else if(count<26){
                //cout << "here" << "\n";
                if(unity[v[i].team]<=1){
                    cout << v[i].id << "\n";
                    count++;
                }
            }
            
        }
        
    }
     
     
    return 0;
}

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

using namespace std;

const double inf = (int)1e8;

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(20-a, 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 <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(N);

        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;
                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;
}