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<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007

typedef struct team{

    int id;
    int belongs;
    int AC;
    int penalty;

}TEAM;

bool comp(const TEAM& a,const TEAM& b){

    if(a.AC == b.AC && a.penalty == b.penalty){/*AC数もペナルティも同じ場合はID順*/
        return a.id > b.id;
    }else if(a.AC == b.AC){
        return a.penalty > b.penalty;
    }else{
        return a.AC < b.AC;
    }
}




int main(){

    int n;
    while(cin >> n){

        int I,U,A,P;
        vector<TEAM> arr(n);

        int total_accept_team = 0;/*通過したチーム*/
        vector<int> ac_team_of_each_team(1001,0);


        REP(i,n){
            cin >> arr[i].id >> arr[i].belongs >> arr[i].AC >> arr[i].penalty;
        }

        /*昇順ソート*/
        sort(arr.begin(),arr.end(),comp);
        /*降順に直す*/
        reverse(arr.begin(),arr.end());

        REP(i,n){

            if(total_accept_team < 10){

                if(ac_team_of_each_team[arr[i].belongs] < 3){
                    cout << arr[i].id << endl;
                    total_accept_team++;
                    ac_team_of_each_team[arr[i].belongs]++;
                }

            }else if(total_accept_team >= 10 && total_accept_team < 20){

                if(ac_team_of_each_team[arr[i].belongs] < 2){
                    cout << arr[i].id << endl;
                    total_accept_team++;
                    ac_team_of_each_team[arr[i].belongs]++;
                }
            }else if(total_accept_team >= 20 && total_accept_team < 26){

                if(ac_team_of_each_team[arr[i].belongs] == 0){
                    cout << arr[i].id << endl;
                    total_accept_team++;
                    ac_team_of_each_team[arr[i].belongs]++;
                }

            }
        }
    }
    return 0;
}

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;
				}
			}
		}
	
		
		for(int i=1;i<=n;i++){
			if(idcount[team[i].belong]<10 && idcount[team[i].belong]<3){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
			else if(idcount[team[i].belong]<=10 && idcount[team[i].belong]<20 && idcount[team[i].belong]<2){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
			else if(idcount[team[i].belong]<=20 && idcount[team[i].belong]<26 && idcount[team[i].belong]==0){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
		}
	}
}

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

using namespace std;

struct comparator {
  bool operator() (const int *lhs, const int *rhs) const{
    if (lhs[2] == rhs[2] && lhs[3] == rhs[3])
      return lhs[0] < rhs[0];
    else if (lhs[2] == rhs[2])
      return lhs[3] < rhs[3];
    else
      return lhs[2] > rhs[2];
  }
};

int main(int argc, char *argv[]) {
  int n;
  set<int*, comparator> team;
  multiset<int> result;
  while (true) {
    cin >> n;
    if (n == 0)
      break;
    for (int i = 0; i < n; i++) {
      int *tmp = new int[4];
      cin >> tmp[0] >> tmp[1] >> tmp[2] >> tmp[3];
      team.insert(tmp);
    }

    for (set<int*>::iterator itr = team.begin();
         itr != team.end(); itr++) {
      //cout << (*itr)[0];                                                                                                                                                
      if (result.size() < 10 && result.count((*itr)[1]) < 3) {
        cout << (*itr)[0] << endl;
        result.insert((*itr)[1]);
      } else if (result.size() < 20 && result.count((*itr)[1]) < 2) {
        cout << (*itr)[0] << endl;
        result.insert((*itr)[1]);
      } else if (result.size() < 26 && result.count((*itr)[1]) < 1) {
        cout << (*itr)[0] << endl;
        result.insert((*itr)[1]);
      }
    }
    team.clear();
    result.clear();
  }
  return 0;
}