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>
#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 + 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(26 <= now )break;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <algorithm>
#include <functional>
#define REP(i,n) for(int i=0;i<n;++i)

using namespace std;

typedef pair<int, int> P;

class team{
public:
	int id,uni,ac,pe;
	team(int _id,int _uni, int _ac, int _pe){
		id=_id; uni=_uni; ac=_ac; pe=_pe;
	}
	
	bool operator<(const team& t) const{
		if(ac>t.ac) return true;
		else if(ac==t.ac && pe<t.pe) return true;
		else if(ac==t.ac && pe==t.pe && id<t.id) return true;
		else return false;
	}
};

int main(void) {
	int n;
	while(cin>>n,n){
		vector<team> vt;
		for(int i=0;i<n;i++){
			int id,uni,ac,pe;
			cin>>id>>uni>>ac>>pe;
			vt.push_back(team(id,uni,ac,pe));
		}
		sort(vt.begin(),vt.end());
		//for(int i=0;i<n;i++) cout<<vt[i].id<<" ";
		//cout<<endl;
		
		
		int sum=0;
		vector<int> adv(1001,0);
		for(int i=0;i<n;i++){
			if(sum<10 && adv[vt[i].uni]<3){sum++; adv[vt[i].uni]++; cout<<vt[i].id<<endl;}
			else if(sum<20 && adv[vt[i].uni]<2){sum++; adv[vt[i].uni]++; cout<<vt[i].id<<endl;}
			else if(sum<26 && adv[vt[i].uni]<1){sum++; adv[vt[i].uni]++; cout<<vt[i].id<<endl;}
		}
	}
	
	return 0;
	

	
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

struct T
{
    int i, u, a, p;
};

bool operator<( T const& lhs, T const& rhs )
{
    return ( lhs.a > rhs.a )
        || ( lhs.a == rhs.a && lhs.p < rhs.p )
        || ( lhs.a == rhs.a && lhs.p == rhs.p && lhs.i < rhs.i );
}
ostream& operator<<( ostream& os, T const& t )
{
    os << t.i << " " << t.u << " " << t.a << " " << t.p;
    return os;
}

int main()
{
    for(;;) {
        int n;
        cin >> n;

        if ( n == 0 )
            break;

        vector<T> v;
        for( int iii=0; iii<n; ++iii ) {
            T t;
            cin >> t.i >> t.u >> t.a >> t.p;
            v.push_back( t );
        }

        stable_sort( v.begin(), v.end() );

        

        map<int, int> teams;
        vector<T> selected;
        for( int i=0; i<v.size(); ++i ) {
            T const& t = v[i];

            if ( selected.size() < 10 ) {
                if ( teams[t.u] < 3 ) {
                    selected.push_back( t );
                    ++teams[t.u];
                }
            } else if ( selected.size() < 20 ) {
                if ( teams[t.u] < 2 ) {
                    selected.push_back( t );
                    ++teams[t.u];
                }
            } else if ( selected.size() < 26 ) {
                if ( teams[t.u] < 1 ) {
                    selected.push_back( t );
                    ++teams[t.u];
                }
            }
        }


        for( int i=0; i<selected.size(); ++i )
            cout << selected[i].i << endl;    
    }
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,sc[10010];
struct Set{
  int I,U,A,P;
};
bool comp(const Set& a, const Set& b){
  double ap,bp;
  ap=(double)a.A-((double)a.P)/100000.0;
  bp=(double)b.A-((double)b.P)/100000.0;
  return ap>bp;
}
vector<Set> vec;
void el(int x){
  sc[vec[x].U]++;
  cout<<vec[x].I<<endl;
}
int main(){
  while(1){
    cin>>n;
    for(int i=0;i<n;i++)sc[i]=0;
    vec.clear();
    if(n==0)break;
    for(int i=0;i<n;i++){
      Set t;
      cin>>t.I>>t.U>>t.A>>t.P;
      vec.push_back(t);
    }
    sort(vec.begin(),vec.end(),comp);
    for(int i=0;i<n;i++){
      if(i<10){
	if(sc[vec[i].U]<3)el(i);
    }else if(i<20){
	if(sc[vec[i].U]<2)el(i);
      }else{
	if(sc[vec[i].U]==0)el(i);
      }
    }
  }
  return 0;
}