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;
#define rep(i,n) for(int i=0;i<n;i++)

struct TEAM{
	int i;
	int u;
	int a;
	int p;
};
bool operator<(const TEAM &a,const TEAM &b){
	pair<pair<int,int>,int> A = make_pair(make_pair(a.a,-a.p),-a.i);
	pair<pair<int,int>,int> B = make_pair(make_pair(b.a,-b.p),-b.i);
	return A < B;
}

int main(){
	int n;
	while(cin >> n){
		vector<TEAM> team(n);
		rep(i,n)cin >> team[i].i >> team[i].u >> team[i].a >> team[i].p;
		sort(team.begin(),team.end());
		reverse(team.begin(),team.end());
		map<int,int> memo;
		vector<int> ret;
		
		int i=0;
		while(1){
			if(i >= team.size() || ret.size()>=26)break;
			TEAM use = team[i];
			if(ret.size()<10){
				if(memo[use.u]<3){
					ret.push_back(use.i);
					memo[use.u]++;
				}
			}else if(ret.size()<	20){
				if(memo[use.u]<2){
					ret.push_back(use.i);
					memo[use.u]++;
				}
			}else{
				if(memo[use.u]<1){
					ret.push_back(use.i);
					memo[use.u]++;
				}
			}
			i++;
		}
		rep(i,ret.size()){
			cout << ret[i] << endl;
		}
	}
}

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

class team{
public:
  int I,U,A,P;
  bool operator<(const team x)const{
    if(A!=x.A)return A>x.A;
    if(P!=x.P)return P<x.P;
    return I<x.I;
  }
};

int main(){
  int n,num[2000];
  team t[500];

  while(cin >> n,n){
    for(int i=0;i<=1000;i++)num[i] = 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);

    int cnt = 0;
    for(int i=0;i<n;i++){
      if(cnt<10 && num[t[i].U]<3){
	cout << t[i].I << endl;
	cnt++;
      }
      else if(cnt<20 && num[t[i].U]<2){
	cout << t[i].I << endl;
	cnt++;
      }
      else if(cnt<26 && num[t[i].U]<1){
	cout << t[i].I << endl;
	cnt++;
      }
      num[t[i].U]++;
    }
  }
}

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] = {};
        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< n; 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 pair<int,int> P;
typedef pair<P,P> Pi;

int main(){
  int n;
  Pi team[333];
  while(cin >> n,n){
    for(int i=0;i<n;i++){
      int I,U,A,B;
      cin >> I >> U >> A >> B;
      P tmp1; tmp1.first = A; tmp1.second = -B;
      P tmp2; tmp2.first = -I; tmp2.second = U;
      team[i].first = tmp1; team[i].second = tmp2;
    }
    sort(team,team+n,greater<Pi>() );
    int idx = 0;
    int cnt = 0;
    int flg[1111]={0};
    while(idx < n && cnt < 26){
      int num = team[idx].second.second;
      int ID = -team[idx].second.first;
      if(cnt < 10){
	if(flg[num] < 3){
	  flg[num]++;
	  cnt++;
	  cout << ID << endl;
	}
      } else if(cnt < 20){
	if(flg[num] < 2){
	  flg[num]++;
	  cnt++;
	  cout << ID << endl;
	}
      } else if(cnt < 26){
	if(flg[num] < 1){
	  flg[num]++;
	  cnt++;
	  cout << ID << endl;
	}
      }
      idx++;
    }
  }
}

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(inf-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<iostream>
#include<algorithm>
#include<vector>
using namespace std;

struct data{
    int i, u, a, p;
    data(int _i, int _u, int _a, int _p) : i(_i), u(_u), a(_a), p(_p) {}
    bool operator<(const data other) const{
        if(a != other.a)      return a > other.a;
        else if(p != other.p) return p < other.p;
        else                  return i < other.i;               
    }
};

int main(){
    int n;
    while(cin >> n, n){
        int i, u, a, p;
        vector<data> v;
        
        for(int t = 0; t < n; t++){
            cin >> i >> u >> a >> p;
            v.push_back(data(i,u,a,p));
        }
        
        sort(v.begin(), v.end());
        
        int uni[1001] = {};
        int passed = 0;

        for(data x : v){
            bool rulea = passed < 10 && uni[x.u] < 3;
            bool ruleb = passed < 20 && uni[x.u] < 2;
            bool rulec = passed < 30 && uni[x.u] < 1;
            if(rulea || ruleb || rulec){
                cout << x.i << endl;
                uni[x.u]++;
                passed++;
            }
        }

    }
    return 0;
}