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>(a,-1*p);
      vec[i].second = pair<int,int>(-1*l,u);
    }
    sort(vec.begin(),vec.end());
    vector<int> cnt(1000,0);
    int ii = 0;
    for(int i = n-1;i >= 0;i--){
      //      cout << vec[i].second.second << "DEGG" << cnt[vec[i].second.second]<< endl;
      
      cnt[vec[i].second.second]++;
      if(ii < 9 && cnt[vec[i].second.second] > 3){
      }else if(9 <= ii && ii < 19&& cnt[vec[i].second.second] > 2){
      }else if(19 <= ii && ii < 25 && cnt[vec[i].second.second] > 1){
      }else{
	cout << -1*vec[i].second.first << endl;
      } 
      ii++;
    }
  }
  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,sum=0;i<=n;i++){
			if(sum<10 && idcount[team[i].belong]<3){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
			else if(sum<=10 && sum<20 && idcount[team[i].belong]<2){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
			else if(sum<=20 && sum<26 && idcount[team[i].belong]==0){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
				sum++;
			}
		}
	}
}

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) return a > t.a;
		if (p != t.p) return 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;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep0(i,n) for(i=0;i<(n);i++)
#define repp(i,m,n) for(int i=(m);i<(n);i++)

#define PUTLINE cout<<__LINE__<<endl;

class Team{
public:
	int i,u,a,p;
	bool operator<(Team team)const{return a>team.a?true:a<team.a?false:p<team.p?true:p>team.p?false:i<team.i;}
};

Team teams[310];
int uni[1100];

int main() {
	for(;;){
		int n;
		memset(uni,0,sizeof(uni));
		cin>>n;
		if(n==0)break;
		rep(i,n)cin>>teams[i].i>>teams[i].u>>teams[i].a>>teams[i].p;
		sort(teams,teams+n);
		int clear=0;
		rep(i,n){
			if(clear<10){
				if(uni[teams[i].u]<3){
					cout<<teams[i].i<<endl;
					clear++;
					uni[teams[i].u]++;
				}
			}else if(clear<20){
				if(uni[teams[i].u]<2){
					cout<<teams[i].i<<endl;
					clear++;
					uni[teams[i].u]++;
				}
			}else if(clear<26){
				if(uni[teams[i].u]<1){
					cout<<teams[i].i<<endl;
					clear++;
					uni[teams[i].u]++;
				}
			}
		}
	}
	return 0;
}