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 <algorithm>
#include <map>

using namespace std;

class teamInfo{
public:
	int id;
	int u;
	int a;
	int p;

	bool operator<(const teamInfo &ti)const{
		if(ti.a < this->a)
			return true;
		else if(ti.a > this->a)
			return false;
		else{
			if(ti.p < this->p)
				return false;
			else if(ti.a > this->a)
				return true;
			else{
				if(ti.id > this->id)
					return true;
				else
					return false;
			}
		}
	}
};

int main(){

	int n;
	while(cin >> n && n !=0){
		vector<teamInfo> v;
		map<int,int> ucnt;

		for(int i = 0; i < n; i++){
			teamInfo ti;
			cin>>ti.id>>ti.u>>ti.a>>ti.p;
			v.push_back(ti);
		}
		sort(v.begin(),v.end());

		int team=0;
		for(int i = 0; i < n; i++){
			if(team < 10){
				ucnt[v[i].u]++;
				if(ucnt[v[i].u] >= 4){
					ucnt[v[i].u]--;
				}
				else{
					cout << v[i].id << endl;
					team++;
				}
			}
			else if(team < 20){
				ucnt[v[i].u]++;
				if(ucnt[v[i].u] >= 3){
					ucnt[v[i].u]--;
				}
				else{
					cout << v[i].id << endl;
					team++;
				}
			}
			else if(team < 26){
				ucnt[v[i].u]++;
				if(ucnt[v[i].u] >= 2){
					ucnt[v[i].u]--;
				}
				else{
					team++;
					cout << v[i].id << endl;
				}
			}
		}
	}

	return 0;
}

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

using namespace std;

const int MAX = 301;
const int UMAX = 1001;
typedef pair<int,int> P;

int n;
struct team{
  int I;
  int U;
  int A;
  int P;
  bool passed;
};
int UNUM[UMAX];
team T[MAX];
int pass;
P p[3] = {P(10,3),P(20,2),P(26,1)};

void T_sort(){

  for(int i = 0; i < n; i++)
    for(int j = i; j < n; j++)
      if(T[i].A < T[j].A || (T[i].A == T[j].A && T[i].P > T[j].P) ||
	 (T[i].A == T[j].A && T[i].P == T[j].P && T[i].I > T[j].I))
	swap(T[i],T[j]);
}

void solve(){
 
  for(int R = 0; R < 3; R++)
    for(int i = 0; pass < p[R].first,i < n; i++){
      if(T[i].passed == false && UNUM[T[i].U] < p[R].second){
	cout << T[i].I << endl;
	T[i].passed = true;
	UNUM[T[i].U]++;
	pass++;
      }
    }
}


void init(){
  pass = 0;
  fill(UNUM,UNUM+UMAX,0);
}
int main(){
  while(cin >> n && n){
    init();
    for(int i = 0; i < n; i++){
      cin >> T[i].I >> T[i].U >> T[i].A >> T[i].P;
      T[i].passed = false;
    }
    T_sort();
    solve();
  }
  
  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]]<2) ||
        (total<26&&senbatsu[school[v[m].second]]<1)
      ){
        senbatsu[school[v[m].second]]++;
        cout<<v[m].second<<endl;
      }
    }
  }
}

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[id] = 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[v[i].second.second]] < 3 || count < 20 && uni[m[v[i].second.second]] < 2 || count < 26 && uni[m[v[i].second.second]] < 1){cout << v[i].second.second << endl; uni[m[v[i].second.second]]++; count++;}
        }
    }
}

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

struct P {
	int i, u, a, p;
	P(int i = 0, int u = 0, int a = 0, int p = 0): i(i), u(u), a(a), p(p){}
	bool operator < (const P &t) const {
		if (a != t.a) a > t.a;
		if (p != t.p) p < t.p;
		return i < t.i;
	}
};

vector<int> res;
int cnt[1001];

int main()
{
	int n;
	while (scanf("%d", &n), n){
		res.clear();
		memset(cnt, 0, sizeof(cnt));
		vector<P> ps;
		for (int i = 0; i < n; i++){
			int _i, u, a, p;
			scanf("%d %d %d %d", &_i, &u, &a, &p);
			ps.push_back(P(_i, u, a, p));
		}
		sort(ps.begin(), ps.end());
		for (int i = 0; i < ps.size(); i++){
			P &p = ps[i];
			if (res.size() < 10){
				if (cnt[p.u] < 3){
					res.push_back(p.i);
					cnt[p.u]++;
				}
			}
			else if (res.size() < 20){
				if (cnt[p.u] < 2){
					res.push_back(p.i);
					cnt[p.u]++;
				}
			}
			else if (res.size() < 26){
				if (cnt[p.u] < 1){
					res.push_back(p.i);
					cnt[p.u]++;
				}
			}
		}
		sort(res.begin(), res.end());
		for (int i = 0; i < res.size(); i++){
			printf("%d\n", res[i]);
		}
	}
	return 0;
}