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 <vector>
#include <iostream>

using namespace std;

int main()
{
    int N; vector<int> I, U, A, P, C;
    
    while(true)
    {
        cin >> N;
        
        if(N == 0) { break; }
        
        I = vector<int>(N);
        U = vector<int>(N);
        A = vector<int>(N);
        P = vector<int>(N);
        
        for(int i = 0; i < N; i++)
        {
            cin >> I[i] >> U[i] >> A[i] >> P[i];
        }
        
        C = vector<int>(1001, 0);
        
        for(int i = 0; i < N; i++)
        {
            for(int j = i + 1; j < N; j++)
            {
                if(A[i] < A[j] || (A[i] == A[j] && P[i] > P[j]))
                {
                    swap(A[i], A[j]);
                    swap(P[i], P[j]);
                    swap(I[i], I[j]);
                    swap(U[i], U[j]);
                }
            }
        }
        
        int count_ = 0;
        
        for(int i = 0; i < N; i++)
        {
            if((count_ < 10 && C[U[i]] < 3) || (count_ < 20 && C[U[i]] < 2) || (count_ < 26 && C[U[i]] == 0))
            {
                cout << I[i] << endl;
                
                C[U[i]]++; count_++;
            }
        }
    }
    
    return 0;
}

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

int main(){
  int total,i,u,a,p,n,m;
  for(;cin>>n,n;){
    map<int,int> school,senbatsu;
    vector< pair< pair<int,int>,int > > v;
    for(total=m=0;m<n;m++){
      cin>>i>>u>>a>>p;
      school[i]=u;
      v.push_back(make_pair(make_pair(-a,p),i));
    }
    sort(v.begin(),v.end());

    for(m=0;m<n;m++){
      if(
        (total<10&&senbatsu[school[v[m].second]]<3) ||
        (total<20&&senbatsu[school[v[m].second]]<3) ||
        (total<10&&senbatsu[school[v[m].second]]<3)
      ){
        senbatsu[school[v[m].second]]++;
        cout<<v[m].second<<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(20,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;
					pass++;
				}
			}
			else if (pass < 20)
			{
				if (n_af[now.af] < 2)
				{
					n_af[now.af]++;
					cout << now.id << endl;
					pass++;
				}
			}
			else
			{
				if (n_af[now.af] < 1)
				{
					n_af[now.af]++;
					cout << now.id << endl;
					pass++;
				}
			}
		}
	}
}

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 boundary[] = { 10, 20, 26 };
			static const int limit[] = { 3, 2, 10000 };
			for (int j = 0; j < 3; ++j)
			{
				if (s < boundary[j] && select[team[i].u] < limit[j])
				{
					++s;
					++select[team[i].u];
					printf("%d\n", team[i].id);
					break;
				}
			}
		}
	}
}