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

using namespace std;

bool cmp(pair<int, int[3]> p, pair<int, int[3]> q)
{
    return (p.second[1] > q.second[1]) || (p.second[1] == q.second[1] && p.second[2] < q.second[2])
        || (p.second[1] == q.second[1] && p.second[2] == q.second[2] && p.first < q.first);
}

int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;

        pair<int, int[3]> team[300];
        int select[1000] = {0};

        for (int i = 0; i < n; i++) {
            cin >> team[i].first >> team[i].second[0] 
                >> team[i].second[1] >> team[i].second[2];
        }
        sort(team, team + n, cmp);
        
        int sl = 0;  // Number of the selected team.
        for (int i = 0; i < n; i++) {
            if ((sl < 10 && select[team[i].second[0] - 1] < 3) ||
                (sl < 20 && select[team[i].second[0] - 1] < 2) ||
                (sl < 26 && select[team[i].second[0] - 1] == 0)) {
                    sl++;
                select[team[i].second[0] - 1]++;
                cout << team[i].first << endl;
            }
        }
    }

    return 0;
}

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

class team{
public:
  int I,U,A,P;
  bool operator<(const team x)const{
    if(A!=x.A)return A>x.A;
    if(P!=x.P)return P<x.P;
    return I<x.I;
  }
};

int main(){
  int n,num[2000];
  team t[500];

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

    sort(t,t+n);

    int cnt = 0;
    for(int i=0;i<n;i++){
      if(cnt<10 && num[t[i].U]<3){
	cout << t[i].I << endl;
	cnt++;
      }
      else if(cnt<20 && num[t[i].U]<2){
	cout << t[i].I << endl;
	cnt++;
      }
      else if(cnt<26 && num[t[i].U]<1){
	cout << t[i].I << endl;
	cnt++;
      }
      num[t[i].U]++;
    }
  }
}

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

int a,b,c,d,n,cnt,tmp;
string str;
int id[300],id2[300],ac[300],wa[300],used[1001];

void change(int x){
  tmp=id[x];id[x]=id[x+1];id[x+1]=tmp;
  tmp=id2[x];id2[x]=id2[x+1];id2[x+1]=tmp;
  tmp=ac[x];ac[x]=ac[x+1];ac[x+1]=tmp;
  tmp=wa[x];wa[x]=wa[x+1];wa[x+1]=tmp;
}
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>id[i]>>id2[300]>>ac[300]>>wa[300];
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(id[j]>id[j+1]){
	  change(j);
	}
      }
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(wa[j]>wa[j+1]){
	  change(j);
	}
      }
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(ac[j]<ac[j+1]){
	  change(j);
	}
      }
    }
    cnt=0;
    for(int i=0;i<1001;i++)used[i]=0;

    for(int i=0;i<n;i++){
      if(cnt<10){
	if(used[id2[i]]<3){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }else if(cnt<20){
	if(used[id2[i]]<2){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }else if(cnt<26){
	if(used[id2[i]]==0){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }
    }


  }
  
  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.first]<3){
	cout<<-data[i].second.first<<endl;
	m[data[i].second.first]++;
	win++;
      }else if(win<20&&m[data[i].second.first]<2){
	cout<<-data[i].second.first<<endl;
	m[data[i].second.first]++;
	win++;
      }else if(win<26&&m[data[i].second.first]==0){
	cout<<-data[i].second.first<<endl;
	m[data[i].second.first]++;
	win++;
      }
    }
  }
  return 0;
}