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 <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class data
{
public:
    int i, u, a, p;
    bool operator<(const data& d) const{
        return a > d.a || (a == d.a && p < d.p) || (a == d.a && p == d.p && i < d.i);
    }
};

void solve(vector<data>& d)
{
    int n = d.size();
    sort(d.begin(), d.end());

    int num = 0;
    map<int, int> cnt;
    for(int i=0; i<n; ++i){
        if(num < 26){
            if(cnt[d[i].u] < (39 - num) / 10){
                cout << d[i].i << endl;
                ++ num;
                ++ cnt[d[i].u];
            }
        }
    }
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<data> d(n);
        for(int i=0; i<n; ++i)
            cin >> d[i].i >> d[i].u >> d[i].a >> d[i].p;
        solve(d);
    }
}

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<stdio.h>
#include<string.h>

int main(){
	int team[301][4],U[1001],n,i,j,sen,k,a,deru[27];
	
	while(0<=scanf("%d",&n)){
		if(n==0)break;
		memset(team,0,sizeof(team));
		
		for(i=0;i<n;i++){
			for(j=0;j<4;j++)
			scanf("%d",&team[i][j]);
		}

		for(i=0;i<n-1;i++){
			for(j=0;j<n-1;j++){
				if(team[j][0]>team[j+1][0]){
					for(k=0;k<4;k++){
						a=team[j+1][k];
						team[j+1][k]=team[j][k];
						team[j][k]=a;
					}
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=0;j<n-1;j++){
				if(team[j][3]>team[j+1][3]){
					for(k=0;k<4;k++){
						a=team[j+1][k];
						team[j+1][k]=team[j][k];
						team[j][k]=a;
					}
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=0;j<n-1;j++){
				if(team[j][2]<team[j+1][2]){
					for(k=0;k<4;k++){
						a=team[j+1][k];
						team[j+1][k]=team[j][k];
						team[j][k]=a;
					}
				}
			}
		}
		memset(U,0,sizeof(U));
		memset(deru,0,sizeof(deru));
		sen=1;
		deru[0]=team[0][0];
		i=1;
		U[team[0][1]]=1;
		while(0!=team[i][0]){
			if(sen<10 && U[team[i][1]]<3){
				++U[team[i][1]];
				deru[sen]=team[i][0];
				++sen;
				++i;
				continue;
			}
			
			if(sen<20 && U[team[i][1]]<2){
				++U[team[i][1]];
				deru[sen]=team[i][0];
				++sen;
				++i;
				continue;
			}
			
			if(sen<26 && U[team[i][1]]==0){
				++U[team[i][1]];
				deru[sen]=team[i][0];
				++sen;
				++i;
				continue;
			}
			++i;
			if(i>=n)break;
		}
		i=0;
		while(deru[i]!=0){
			printf("%d\n",deru[i]);
			++i;
		}
	}
	return 0;
}