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 <algorithm>

using namespace std;

struct TEAM
{
	short id;
	short af;
	int pt;
	char ac;
};
typedef struct TEAM team;

int main()
{
	int n;
	team tt[300];
	char ok[1001];

	while(cin >> n, n)
	{
		for(int i=0; i < n; i++) {
			cin >> tt[i].id;
			cin >> tt[i].af;
			char tmp; cin >> tmp; tt[i].ac = tmp - '0';
			cin >> tt[i].pt;
		}
		// sort
		int nn = n - 1;
		for(int i=0; i < nn; i++) {
			for(int j=i+1; j < n; j++) {
				if(tt[i].ac < tt[j].ac) {
					swap(tt[i], tt[j]);
				}
				else if(tt[i].ac == tt[j].ac) {
					if(tt[i].pt > tt[j].pt) {
						swap(tt[i], tt[j]);
					}
					else if(tt[i].pt == tt[j].pt) {
						if(tt[i].id > tt[j].id) {
							swap(tt[i], tt[j]);
						}
					}
				}
			}
		}
		// \sort
		for(int i=0; i < 1001; i++) ok[i] = 0;
		int cnt = 0;
		for(int i=0; i < n; i++) {
			if(cnt < 10) { // rule1
				if(ok[tt[i].af] < 3) {
					ok[tt[i].af]++;
					cnt++;
					cout << tt[i].id << endl;
				}
			}
			else if(cnt < 20) { // rule2
				if(ok[tt[i].af] < 2) {
					ok[tt[i].af]++;
					cnt++;
					cout << tt[i].id << endl;
				}
			}
			else if(cnt < 26) { // rule3
				if(ok[tt[i].af] < 1) {
					ok[tt[i].af]++;
					cnt++;
					cout << tt[i].id << endl;
				}
			}
			else
				break;
		}
	}
	return 0;
}

C++: #include <iostream>
#define MAX_N 1001
using namespace std;
int n,I[MAX_N],U[MAX_N],A[MAX_N],P[MAX_N];

void b_sort(int a,int b){
  swap(I[a],I[b]);
  swap(U[a],U[b]);
  swap(A[a],A[b]);
  swap(P[a],P[b]);
}

int main(){

  while(cin >> n,n){
    for(int i = 0 ; i < n ; i++  ){
      cin >> I[i] >> U[i] >> A[i] >> P[i]; 
    }

    for(int i = 0 ; i < n-1 ; i++ )
      for(int j = n-1 ; j > 0 ; j-- )
	if(I[j-1] > I[j])b_sort(j-1,j);

    for(int i = 0 ; i < n-1 ; i++ )
      for(int j = n-1 ; j > 0 ; j-- )
	if(P[j-1] > P[j])b_sort(j-1,j);

    for(int i = 0 ; i < n-1 ; i++ )
      for(int j = n-1 ; j > 0 ; j-- )
	if(A[j-1] < A[j])b_sort(j-1,j);
    
    int teamLimit[MAX_N],now = 0;
    fill(teamLimit,teamLimit + MAX_N,0);
    for(int i = 0 ; i < n ; i++ ){


      if(now < 10){
	if(teamLimit[U[i]] < 3 ){
	  teamLimit[U[i]]++;
	  cout << I[i] << endl;
	  now++; 
	}
      } else if(now < 20){
	if(teamLimit[U[i]] < 2 ){
	  teamLimit[U[i]]++;
	  cout << I[i] << endl;
	  now++; 
	} else if(now < 26){
	  if(teamLimit[U[i]] == 0){
	    teamLimit[U[i]]++;
	    cout << I[i] << endl;
	    now++;
	  }
	}
      } 
      if(26 == now )break;
    }
  }
  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<bits/stdc++.h>
using namespace std;

#define rep(X,Y) for(int (X) = 0; (X) < (Y); ++(X))
typedef long long ll;
typedef pair<int, int> pii;

#define all(X) (X).begin(),(X).end()
#define pb push_back
#define eb emplace_back
#define rrep(X,Y) for(int (X)=(Y)-1; (X) >= 0; --(X))
#define X first
#define Y second
#define reps(X,Y,Z) for(int (X)=(Y); (X) <= (Z); ++(X))
#define sz size()
#define in(i,j,k) ((i) >= (j) && (j) <= (k))

#define UNIQUE(X) (X).erase(unique(all(X)), (X).end())

int main(){
    int n;
    while(cin >> n&&n){
        vector<pair<pii,pii > > v;
        rep(i,n){
            int id,u,a,p;
            cin >> id >> u >> a >> p;
            v.eb(pii(-a,p),pii(id,u));
        }
        sort(all(v));
        map<int,int> m;
        vector<int> ans;
        rep(i,n){
            if( ans.sz < 10 && m[v[i].Y.Y] < 3 ||
                ans.sz < 20 && m[v[i].Y.Y] < 2 ||
                ans.sz < 26 && m[v[i].Y.Y] < 1 )
            {
                m[v[i].Y.Y]++;
                ans.pb(v[i].Y.X);
            }
        }
        rep(i,ans.sz){
            cout << ans[i] << endl;
        }
    }
    return 0;
}