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<map>
#include<algorithm>
#include<cstdio>

using namespace std;

typedef pair<int, pair<int, pair<int, int> > > data;

#define f first
#define s second
#define ID s.s.f
#define AF s.s.s
#define SL f
#define PN s.f

#define REP(i,n) for(int i=0; i<(int)(n); i++)


int getInt(){
  int ret; scanf("%d", &ret);
  return ret;
}

int main(){
  while(int n = getInt()){
    vector<data> v(n);

    REP(i, n){
      v[i].ID = -getInt();
      v[i].AF = getInt();
      v[i].SL = getInt();
      v[i].PN = -getInt();
    }

    sort(v.rbegin(), v.rend());

    int all = 0;
    map<int, int> cnt;

    for(int i = 0; i < n; i++){
      int id = -v[i].ID;
      int af = v[i].AF;

      if(all < 10){
	if(cnt[id] < 3){
	  cnt[id]++;
	  cout << id << endl;
	}
      }else if(all < 20){
	if(cnt[id] < 2){
	  cnt[id]++;
	  cout << id << endl;
	}
      }else if(all < 26){
	if(cnt[id] < 1){
	  cnt[id]++;
	  cout << id << endl;
	}
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;

typedef struct {
  int l,u,a,p;
} T;

int main(){
  int n;
  T team[1000], tmp;
  int U[1001];

  while( cin>>n && n ){
    for( int i=0;i<n;i++ )
      cin >> team[i].l >> team[i].u >> team[i].a >> team[i].p ;

    bool f;
    do{
      f=false;
      for( int i=1;i<n;i++ ){
	if( team[i-1].a < team[i].a ||
	    ( team[i-1].a==team[i].a && (team[i-1].p>team[i].p || (team[i-1].p==team[i].p && team[i-1].l>team[i].l)))){
	  tmp = team[i-1];
	  team[i-1] = team[i];
	  team[i] = tmp;
	  f=true;
	}	 
      }
    }while( f );

    memset( U,0,sizeof(U) );
    int Nteam=0;
    for( int i=0;i<n && Nteam<26;i++ ){
      if(  (Nteam<10 && U[ team[i].u ]<3 ) ||
	   (Nteam<20 && U[ team[i].u ]<2 ) ||
	   (Nteam<26 && U[ team[i].u ]<1 ) )
	{
	  U[ team[i].u ]++;
	  Nteam++;
	  cout << team[i].l << endl;
	}
    }

    /*
    for( int i=0;i<n;i++ )
      cout << team[i].l << " "<< team[i].u << " "
	   << team[i].a << " "<< team[i].p << endl;
    */
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <queue>
using namespace std;

class Team
{
public:
	int id, af, n, pen;
	Team(int id, int af, int n, int pen)
		: id(id), af(af), n(n), pen(pen) {}
	bool operator<(const Team& t) const {
		if (n != t.n) return n < t.n;
		else if (pen != t.pen) return pen > t.pen;
		else return id > t.id;
	}
};

int main()
{
	int N;
	while (cin >> N, N)
	{
		priority_queue<Team> pq;
		for (int i=0; i<N; i++)
		{
			int id, af, n, pen;
			cin >> id >> af >> n >> pen;
			pq.push(Team(id, af, n, pen));
		}

		int pass = 0;
		vector<int> n_af(1001,0);
		while (!pq.empty())
		{
			Team now = pq.top(); pq.pop();

			if (pass < 10)
			{
				if (n_af[now.af] < 3)
				{
					n_af[now.af]++;
					cout << now.id << endl;
					pass++;
				}
			}
			else if (pass < 20)
			{
				if (n_af[now.af] < 2)
				{
					n_af[now.af]++;
					cout << now.id << endl;
					pass++;
				}
			}
			else if (pass < 26)
			{
				if (n_af[now.af] < 1)
				{
					n_af[now.af]++;
					cout << now.id << endl;
					pass++;
				}
			}
		}
	}
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

map<int,bool> used;
map<int,int> count_t;
map<int,bool> isDecided;
vector<bool> ans;

int main(){
    while(true){
	int n;
	vector< pair< pair<int,int> , pair<int,int> > > t;
	cin >> n;
	if(n==0) break;
	REP(i,n){
	    int I,A,U,P;
	    cin >> I >> U >> A >> P;
	    t.PB( MP( MP(-A,P) , MP(I,U) ) );
	    used[I] = false;
	    count_t[U] = false;
	    isDecided[I] = false;
	    sort(ALL(t));
	}
	int temp = 0;

	REP(i,n){
	    if(!used[t[i].second.second]){
		used[t[i].second.second] = true;
		count_t[t[i].second.second]++;
		isDecided[t[i].second.first] = true;
		temp++;
	    }
	}

	if(temp < 10){
	    REP(i,n){
		if(!isDecided[t[i].second.first] && count_t[t[i].second.second] < 3){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
		    temp++;
		}
	    }
	}


	if(temp < 20){
	    REP(i,n){
		if(!isDecided[t[i].second.first] && count_t[t[i].second.second] < 2){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
			temp++;
		}
	    }
	}

	if(temp < 26){
	    REP(i,n){
		if(!isDecided[t[i].second.second] && count_t[t[i].second.second] < 1){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
		    temp++;
		}
	    }
	}

	REP(i,n){
	    if(isDecided[t[i].second.first]) cout << t[i].second.first << endl;
	}
    }

    return 0;
}