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 <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
class team
{
public:
	int id,b,acc,pen;
	team(int i = 0,int b = 0,int a = 0, int p = 0):
	id(i),b(b),acc(a),pen(p){}
	bool operator < (const team &t)const {
		if(acc==t.acc){
			if(pen==t.pen){
				return id < t.id;
			}else return pen < t.pen;
		}else return acc > t.acc;
	}
};
int n;
team T[1010];
int main(){
	while(cin>>n,n){
		for(int i =0;i < n;i++){
			cin>>T[i].id>>T[i].b>>T[i].acc>>T[i].pen;
		}
		sort(T,T + n);
		int select = 0;
		int bel_sele[100] ={0};
		for(int i =0;i < n;i++){
			int id = T[i].id;
			int belong = T[i].b;
			if(select < 10){
				if(bel_sele[belong] < 3){
					select++;
					bel_sele[belong]++;
					cout <<id<<endl;
				}
			}else if(select < 20){
				if(bel_sele[belong] < 2){
					select++;
					bel_sele[belong]++;
					cout <<id<<endl;
				}
			}else if(select < 26){
				if(bel_sele[belong]==0){
					select++;
					bel_sele[belong]++;
					cout <<id<<endl;
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n;
  while(cin>>n){
    if(n==0)break;
    map<int,int> m;
    vector<pair<pi,pi > >data;
    pair<pi,pi> d;
    rep(i,n){
      cin>>d.second.first>>d.second.second>>d.first.first>>d.first.second;
      d.second.first=(-d.second.first);
      d.first.second=(-d.first.second);
      data.pb(d);
    }
    sort(all(data));reverse(all(data));
    int win=0;
    rep(i,n){
      if(win<10&&m[data[i].second.second]<3){
	cout<<-data[i].second.first<<endl;
	m[data[i].second.second]++;
	win++;
      }else if(win<20&&m[data[i].second.second]<2){
	cout<<-data[i].second.first<<endl;
	m[data[i].second.second]++;
	win++;
      }else if(win<26&&m[data[i].second.second]==0){
	cout<<-data[i].second.first<<endl;
	m[data[i].second.second]++;
	win++;
      }
    }
  }
  return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int num_of_selected[1001],total;

struct Info{
	Info(){
		id = group = ans = penalty = 0;
	}
	int id,group,ans,penalty;
};

void func(int N){

	Info info[N];

	for(int i = 0; i < N; i++){
		scanf("%d %d %d %d",&info[i].id,&info[i].group,&info[i].ans,&info[i].penalty);
	}

	for(int i = 1; i <= N-1; i++){
		for(int k = N-1; k >= i; k--){
			if((info[k].ans > info[k-1].ans) || (info[k].ans == info[k-1].ans && info[k].penalty < info[k-1].penalty) ||
					(info[k].ans == info[k-1].ans && info[k].penalty == info[k-1].penalty && info[k].id < info[k-1].id))swap(info[k],info[k-1]);
		}
	}

	total = 0;
	int limit = min(N,26);
	for(int i = 0; i < limit; i++){
		if(total < 10 && num_of_selected[info[i].group] < 3){
			num_of_selected[info[i].group]++;
			total++;
			printf("%d\n",info[i].id);
		}else if(total < 20 && num_of_selected[info[i].group] < 2){
			num_of_selected[info[i].group]++;
			total++;
			printf("%d\n",info[i].id);
		}else if(total < 26 && num_of_selected[info[i].group] == 0){
			num_of_selected[info[i].group]++;
			total++;
			printf("%d\n",info[i].id);
		}
	}
}

int main(){

	int N;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 1; i<= 1000; i++)num_of_selected[i] = 0;

		func(N);
	}

	return 0;
}