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 <cstdio>
#include <queue>

using namespace std;

typedef struct Score {
	Score(int i, int u, int a, int p){
		id = i; school = u; success = a; penalty = p;
	}
	int id, school, success, penalty;
} Score;

typedef struct MyComparator {
	bool operator()(Score &a, Score &b){
		if(a.success < b.success){ return true; }
		if(a.success > b.success){ return false; }
		if(a.penalty > b.penalty){ return true; }
		if(a.penalty < b.penalty){ return false; }
		return (a.id > b.id);
	}
} MyComparator;

int main(){
	while(true){
		int n;
		scanf("%d", &n);
		if(n == 0){ break; }
		priority_queue<Score, vector<Score>, MyComparator> q;
		int cs[1001] = { 0 };
		int rank = 1;
		while(n--){
			int i, u, a, p;
			scanf("%d%d%d%d", &i, &u, &a, &p);
			q.push(Score(i, u, a, p));
		}
		while(!q.empty() && rank <= 26){
			Score s = q.top();
			if(rank <= 10){
				if(cs[s.school] < 3){ printf("%d\n", s.id); rank++; }
			}else if(rank <= 20){
				if(cs[s.school] < 2){ printf("%d\n", s.id); rank++; }
			}else{
				if(cs[s.school] < 1){ printf("%d\n", s.id); rank++; }
			}
			cs[s.school]++;
			q.pop();
		}
	}
	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];
        fill(uni, 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 <iostream>
#include <vector>
#include <map>
#include <algorithm>
struct team{int i, u, a, p;team(int,int,int,int);};
team::team(int _i, int _u, int _a, int _p)
	:i(_i), u(_u), a(_a), p(_p) {}

bool tsort(const team& l, const team& r){
	if(l.a == r.a){
		if(l.p == r.p)return l.i < r.i;
		return l.p < r.p;
	}
	return l.a > r.a;
}

int main(){
	int n;
	while(std::cin >> n, n){
		int i, u, a, p;
		std::vector<team> v;
		while(n--){
			std::cin >> i >> u >> a >> p;
			team t = team(i, u, a, p);
			v.push_back(t);
		}
		
		std::sort(v.begin(), v.end(), tsort);
		
		int steam = 0;
		std::map<int, int> m;
		std::vector<team>::iterator it = v.begin();
		while(it != v.end()){
			if(steam < 10){
				if(m[(*it).u] < 3){
					std::cout << (*it).i << std::endl;
					steam++, m[(*it).u]++;
				}
			}
			else if(steam < 20){
				if(m[(*it).u] < 2){
					std::cout << (*it).i << std::endl;
					steam++, m[(*it).u]++;
				}
			}
			else if(steam < 26){
				if(!m[(*it).u]){
					std::cout << (*it).i << std::endl;
					steam++, m[(*it).u]++;
				}
			}
			it++;
		}
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


struct Team
{
	int id, u, a, p;
	void input()
	{
		cin >> id >> u >> a >> p;
	}
};
bool operator<(const Team& a, const Team& b)
{
	return a.a > b.a || a.a == b.a && a.p < b.p
		|| a.a == b.a && a.p == b.p && a.id < b.id;
}
int main()
{
	int n;
	while (cin >> n, n)
	{
		Team team[500];
		rep (i, n)
			team[i].input();
		sort(team, team + n);

		int	select[1024];
		fill_n(select, n, 0);
		int s = 0;
		for (int i = 0; i < n && s < 26; ++i)
		{
			static const int limit[] = { 3, 2, 1 };
			if (select[team[i].u] < limit[s / 10])
			{
				++s;
				++select[team[i].u];
				cout << team[i].id << endl;
			}
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;

class Team
{
public:
	int id, af, n, pen;
	Team(int id, int af, int n, int pen)
		: id(id), af(af), n(n), pen(pen) {}
	bool operator<(const Team& t) const {
		if (n != t.n) return n < t.n;
		else if (pen != t.pen) return pen > t.pen;
		else return id > t.id;
	}
};

int main()
{
	int N;
	while (cin >> N, N)
	{
		priority_queue<Team> pq;
		for (int i=0; i<N; i++)
		{
			int id, af, n, pen;
			cin >> id >> af >> n >> pen;
			pq.push(Team(id, af, n, pen));
		}

		int pass = 0;
		vector<int> n_af(11,0);
		while (!pq.empty())
		{
			Team now = pq.top(); pq.pop();

			if (pass < 10)
			{
				if (n_af[now.af] < 3)
				{
					n_af[now.af]++;
					cout << now.id << endl;
				}
			}
			else if (pass < 20)
			{
				if (n_af[now.af] < 2)
				{
					n_af[now.af]++;
					cout << now.id << endl;
				}
			}
			else
			{
				if (n_af[now.af] < 1)
				{
					n_af[now.af]++;
					cout << now.id << endl;
				}
			}
		}
	}
}