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<string.h>

using namespace std;

struct log{
	int id,belong,correct,penalty;
};

int main(void){
	
	struct log team[1001];
	int n,idcount[1001];

	while(cin>>n,n){
		
		memset(team,0,sizeof(team));
		memset(idcount,0,sizeof(idcount));
		
		for(int i=1;i<=n;i++){
			cin>>team[i].id>>team[i].belong>>team[i].correct>>team[i].penalty;
		}
		
		for(int i=1;i<=n;i++){
			for(int j=n;j>=i+1;j--){
				if(team[j-1].correct<team[j].correct){
					struct log temp;
					temp=team[j];
					team[j]=team[j-1];
					team[j-1]=temp;
				}
			}
		}

		for(int i=1;i<=n;i++){
			for(int j=n;j>=i+1;j--){
				if(team[j-1].correct==team[j].correct && team[j-1].penalty>team[j].penalty){
					struct log temp;
					temp=team[j];
					team[j]=team[j-1];
					team[j-1]=temp;
				}
			}
		}
			
		for(int i=1;i<=n;i++){
			for(int j=n;j>=i+1;j--){
				if(team[j-1].correct==team[j].correct && team[j-1].penalty==team[j].penalty && team[j-1].id>team[j].id){
					struct log temp;
					temp=team[j];
					team[j]=team[j-1];
					team[j-1]=temp;
				}
			}
		}
	
		idcount[team[i].belong]=0;
		for(int i=1;i<=n;i++){
			if(i<10 && idcount[team[i].belong]<3){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
			else if(i<=10 && i<20 && idcount[team[i].belong]<2){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
			else if(i<=20 && i<26 && idcount[team[i].belong]==0){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
		}
	}
}

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

using namespace std;
typedef pair<int,pair<int,pair<int,int> > > PP;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		int id, Univ, AC, WA;
		
		map<PP,int> m;
		for(int i = 0; i < n; ++i)
		{
			cin >> id >> Univ >> AC >> WA;
			m[make_pair(-AC, make_pair(WA, make_pair(id, Univ)))] = id;
		}
		int count = 0, u[1001] = {};
		for(map<PP,int>::iterator it = m.begin(); it != m.end(); ++it)
		{
			int j = it->first.second.second.second;
			bool flag = false;
			if(count < 10 && u[j] < 3 || count < 20 && u[j] < 2 || count < 26 && !u[j])
			{
				flag = true;
			}
			if(flag)
			{
				++count, ++u[j];
				cout << it->second << endl;
			}
		}
	}
}

int main()
{
	solve();
	return(0);
	
}

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].id];
				cout << team[i].id << endl;
			}
		}
	}
}

C++: #include<iostream>
#include<set>
#include<map>
using namespace std;
struct Team{int I,U,A,P;};
bool operator<(Team a,Team b){
  return a.A!=b.A?a.A>b.A:(a.P!=b.P?a.P<b.P:a.I<b.I);
}
int main()
{
  int n,I,U,A,P;
  int num;
  while(cin>>n,n){
    map<int,int>dup;
    multiset<Team>record;
    multiset<Team>::iterator it;
    for(int i=0;i<n;i++){
      cin>>I>>U>>A>>P;
      Team t={I,U,A,P};
      record.insert(t);
    }
    num=0;
    for(it=record.begin();it!=record.end();it++){
      if(num<10&&dup[it->U]<3){
	num++;
	dup[it->U]++;
	cout<<it->I<<endl;
      }else if(num<20&&dup[it->U]<2){
	num++;
	dup[it->U]++;
	cout<<it->I<<endl;
      }else if(num<26&&dup.count(it->U)==0){
	num++;
	dup[it->U]++;
	cout<<it->I<<endl;
      }
    }
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int n,teamnum;
const int NMAX = 1000;
struct team{
  int i,u,a,p;
} t[NMAX];

bool operator < (team a, team b){
  if(a.a == b.a){
    if(a.p == b.p){
      return a.i > b.i;
    }else{return a.p > b.p;}
  }else{return a.a < b.a;}
}

int main(){
  while(1){
    cin >> n;
    if(n == 0)return 0;
    for(int i = 0;i < n;i++){
      cin >> t[i].i >> t[i].u >> t[i].a >> t[i].p;
    }
    sort(t,t+n);
    for(int i = n-1;i >= 0;i--){
      cout << t[i].i << endl; 
    }
  }

  return 0;
}