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>
using namespace std;
//const int RULE[3] = {10,20,26};
//const int MEM[3] = {3,2,1};

int main(){
  while(1){
    int n;
    cin >> n;

    if(n == 0)break;///// テヲツュツ」ティツァツ」テヲツ閉ー,テ「ツ按津ッツシツ妥ッツシツ甘」ツδ堙」ツδ甘」ツδォテ」ツδ?ID,テヲツ可?・ツアツ?
    
    vector<pair<pair<int,int>,
		pair<int,int>		
		>
	   > vec(n,pair<pair<int,int>,pair<int,int> >());
    for(int i = 0;i < n;i++){
      int l,u,a,p;
      cin >> l >> u >> a >> p;
      vec[i].first = pair<int,int>(-1*a,p);
      vec[i].second = pair<int,int>(l,u);
    }
    sort(vec.begin(),vec.end());
    vector<int> cnt(1000,0);
    //int ii = 0;
    for(int i = 0;i < n;i++){
      //      cout << vec[i].second.second << "DEGG" << cnt[vec[i].second.second]<< endl;
      
      cnt[vec[i].second.second]++;
      if(i < 9 && cnt[vec[i].second.second] > 3){
      }else if(9 <=i && i < 19&& cnt[vec[i].second.second] > 2){
      }else if(19 <= i && i < 25 && cnt[vec[i].second.second] > 1){
      }else{
	cout << vec[i].second.first << endl;
      } 
      
    }
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;

static const double EPS = 1e-8;

const int tx[] = {0,1,0,-1};
const int ty[] = {-1,0,1,0};

class Team{
public:
	int id;
	int univ;
	int success;
	int penalty;

	Team() : id(0),univ(0),success(0),penalty(0){}
	Team(int id,int univ,int success,int penalty){
		this->id = id;
		this->univ = univ;
		this->success = success;
		this->penalty = penalty;
	}
};

class mycmp{
public:
	bool operator()(const Team t1,const Team t2){
		if(t1.success == t2.success
			&& t1.penalty == t2.penalty){
				return (t1.id < t2.id);
		}
		else if(t1.success == t2.success){
			return (t1.penalty < t2.penalty);
		}

		return (t1.success > t2.success);
	}
};

int main(){
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		vector<Team> teams;
		for(int i=0;i<n;i++){
			int ID,U,A,P;
			scanf("%d %d %d %d",&ID,&U,&A,&P);
			teams.push_back(Team(ID,U,A,P));
		}

		map<int,bool> passedTeam;
		map<int,int> univCount;
		sort(teams.begin(),teams.end(),mycmp());
		for(int i=0;i<teams.size();i++){
			if(passedTeam.size() < 10){
				if(univCount[teams[i].univ] < 3){
					univCount[teams[i].univ]++;
					passedTeam[teams[i].id] = true;
					printf("%d\n",teams[i].id);
				}
			}
			else if(passedTeam.size() < 20){
				if(univCount[teams[i].univ] < 2){
					univCount[teams[i].univ]++;
					passedTeam[teams[i].id] = true;
					printf("%d\n",teams[i].id);
				}
			}
			else if(passedTeam.size() < 26){
				if(univCount[teams[i].univ] < 1){
					univCount[teams[i].univ]++;
					passedTeam[teams[i].id] = true;
					printf("%d\n",teams[i].id);
				}
			}
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//const int RULE[3] = {10,20,26};
//const int MEM[3] = {3,2,1};

int main(){
  while(1){
    int n;
    cin >> n;

    if(n == 0)break;///// テヲツュツ」ティツァツ」テヲツ閉ー,テ「ツ按津ッツシツ妥ッツシツ甘」ツδ堙」ツδ甘」ツδォテ」ツδ?ID,テヲツ可?・ツアツ?
    
    vector<pair<pair<int,int>,
		pair<int,int>		
		>
	   > vec(n,pair<pair<int,int>,pair<int,int> >());
    for(int i = 0;i < n;i++){
      int l,u,a,p;
      cin >> l >> u >> a >> p;
      vec[i].first = pair<int,int>(-1*a,p);
      vec[i].second = pair<int,int>(l,u);
    }
    sort(vec.begin(),vec.end());
    vector<int> cnt(1000,0);
    //int ii = 0;
    int f = 0;
    for(int i = 0;i < n;i++){
      //      cout << vec[i].second.second << "DEGG" << cnt[vec[i].second.second]<< endl;
      
      cnt[vec[i].second.second]++;
      if(i < 10 && cnt[vec[i].second.second] > 3){
	
      }else if(10 <=i && i < 20&& cnt[vec[i].second.second] > 2){
       
      }else if(20 <= i && i < 26 && cnt[vec[i].second.second] > 1){
	
      }else{
	cout << vec[i].second.first << endl;
	f++;
	if(f == 26)break;
      } 
      
    }
  }
  return 0;
}