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>
#include<vector>
using namespace std;
#define fr first
#define sc second
typedef pair<int,int> Pt;
int main(){
  int n;
  while(cin >> n , n){
    int cnt[1001] = {0},ogimother = 0;
    vector< pair<Pt,Pt> > all;
    bool doing = true,nakamura[1001] = {};
    for(int i = 0 ; i < n ; i++ ){
      int I,U,A,P;
      cin >> I >> U >> A >> P;
      all.push_back(make_pair(Pt(-A,P),Pt(I,U)));
    }
    sort(all.begin(),all.end());

    while(ogimother < 26 && doing ){
      doing = false;
      for(int i = 0 ; i < n ; i++ ){
        if(nakamura[i]) continue;
        if(ogimother < 10){
          if(cnt[all[i].sc.sc] < 3){
            cnt[all[i].sc.sc]++;
            ogimother++;
            nakamura[i]  = true;
            doing = true;
            cout << all[i].sc.fr << endl;
          }
        }else if(ogimother < 20){
          if(cnt[all[i].sc.sc] < 2){
            cnt[all[i].sc.sc]++;
            ogimother++;
            nakamura[i]  = true;
            doing = true;
            cout << all[i].sc.fr << endl;
          }
        }else if(ogimother < 26){
          if(!cnt[all[i].sc.sc]){
            cnt[all[i].sc.sc]++;
            ogimother++;
            nakamura[i]  = true;
            doing = true;
            cout << all[i].sc.fr << endl;
          }
        }
      }
    }
  }
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;

bool cmp(const PP &p,const PP &q){
  if(p.S.F != q.S.F)return p.S.F > q.S.F;
  if(p.S.S != q.S.S)return p.S.S < q.S.S;
}


int main(){
  int n;
  int I,U,A,Po;
  while(cin >> n && n){
    vector<PP> vec;
    map<int,int> entitle; 
    for(int i=0;i<n;i++){
      cin >> I >> U >> A >> Po;
      vec.push_back(PP(P(I,U),P(A,Po)));
    }
    sort(vec.begin(),vec.end(),cmp);
    int norisuke = 0; 
    int limit;
    for(int i=0;i<n;i++){
      limit = norisuke<10?3:norisuke<20?2:norisuke<26?1:0;
      int AD = vec[i].F.S;
      if(entitle[AD] < limit){
	entitle[AD]++;
	cout << vec[i].F.F << endl;
	norisuke++;
      }
    }

  }
  return 0;
}

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

typedef pair<int, pair<int, pair<int, int> > > pp;

const int U_MAX = 1000;
int us[U_MAX];

int main() {
    int n;
    while (cin >> n, n) {
        map<pp, int> ts;
        for (int i = 0; i < n; i++) {
            int id, u, a, p;
            cin >> id >> u >> a >> p;
            ts[make_pair(-a, make_pair(p, make_pair(id, u)))] = id;
        }
        int e = 0;
        fill_n(us, U_MAX, 0);
        for (map<pp, int>::iterator it = ts.begin(); it != ts.end(); it++) {
            int j = it->first.second.second.second - 1;
            if ((e < 10 && us[j] < 3) || (e < 20 && us[j] < 2) || (e < 26 && !us[j])) {
                cout << it->second << endl;
                us[j]++;
                e++;
            }
        }
    }
}

C++: #include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct status{
	int id;
	int unite;
	int ac;
	int pena;
}status;

int cmp(const void* a,const void* b){
	status *s1 = (status *)a;
	status *s2 = (status *)b;
	if(s1->ac > s2->ac)
		return -1;
	else if(s1->ac < s2->ac)
		return 1;
	else{
		if(s1->pena > s2->pena)
			return 1;
		else if(s1->pena < s2->pena)
			return -1;
		else{
			if(s1->id > s2->id)
				return 1;
			else
				return -1;
		}
	}
}

int main(void){
	int i, n, uc[1000]/*unitecount*/,wc;
	status s[300];
	while(1){
		scanf("%d",&n);
		if(!n) break;
		for(i = 0;i < n;i++)
			scanf("%d%d%d%d",&s[i].id,&s[i].unite,&s[i].ac,&s[i].pena);
		memset(uc,0,sizeof(uc));
		qsort(s,n,sizeof(s[0]),cmp);
		wc = 0;
		for(i = 0;i < n;i++){
			if(wc < 10 && uc[s[i].unite] < 3){
				printf("%d\n",s[i].id);
				uc[s[i].unite]++;
				wc++;
			}
			else if(wc < 20 && uc[s[i].unite] < 2){
				printf("%d\n",s[i].id);
				uc[s[i].unite]++;
				wc++;
			}
			else if(wc < 26 && uc[s[i].unite] == 0){
				printf("%d\n",s[i].id);
				uc[s[i].unite]++;
				wc++;
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string.h>

using namespace std;

struct log{
	int id,belong,correct,penalty;
};

int main(void){
	
	struct log team[1001];
	int n,idcount[1001];

	while(cin>>n,n){
		
		memset(team,0,sizeof(team));
		memset(idcount,0,sizeof(idcount));
		
		for(int i=1;i<=n;i++){
			cin>>team[i].id>>team[i].belong>>team[i].correct>>team[i].penalty;
		}
		
		for(int i=1;i<=n;i++){
			for(int j=n;j>=i+1;j--){
				if(team[j-1].correct<team[j].correct){
					struct log temp;
					temp=team[j];
					team[j]=team[j-1];
					team[j-1]=temp;
				}
			}
		}

		for(int i=1;i<=n;i++){
			for(int j=n;j>=i+1;j--){
				if(team[j-1].correct==team[j].correct && team[j-1].penalty>team[j].penalty){
					struct log temp;
					temp=team[j];
					team[j]=team[j-1];
					team[j-1]=temp;
				}
			}
		}
			
		for(int i=1;i<=n;i++){
			for(int j=n;j>=i+1;j--){
				if(team[j-1].correct==team[j].correct && team[j-1].penalty==team[j].penalty && team[j-1].id>team[j].id){
					struct log temp;
					temp=team[j];
					team[j]=team[j-1];
					team[j-1]=temp;
				}
			}
		}
	
		
		for(int i=1,sum=0;i<=n;i++){
			if(sum<10 && idcount[team[i].belong]<3){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
				sum++;
			}
			else if(sum<=10 && sum<20 && idcount[team[i].belong]<2){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
				sum++;
			}
			else if(sum<=20 && sum<26 && idcount[team[i].belong]==0){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
				sum++;
			}
		}
	}
}