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 <vector>
using namespace std;
const int MAX = 1001;
typedef pair<int,int> QQ;
typedef pair<int,int> PP;
typedef pair<PP,QQ> P;

int main(){
  int n;

  while(cin >> n ,n){
    int id,uni,ac,pe;
    int tc[MAX]={0};
    vector<P> v;

    while(n--){
      cin >> id >> uni >> ac >> pe;
      v.push_back(P(PP(-ac,pe),QQ(id,uni)));
    } 
    sort(v.begin(),v.end());

    for(int i = 0; i < v.size() ; i++){
      int u = v[i].second.second;
      tc[u]++;
      if(i+1 < 10){
	if(tc[u] <= 3){
	  cout << v[i].second.first << endl;
	}
      }
      else if(i+1 < 20){
	if(tc[u] <= 2){
	  cout << v[i].second.first << endl;
	}
      }
      else if(i+1 < 26){
	if(tc[u] <= 1){
	  cout << v[i].second.first << endl;
	}
      }
    } 
  }

  return 0;
}

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

using namespace std;

struct DATA{
  int id, t, ac, pn;
  DATA(){}
};

bool comp(const DATA& a, const DATA& b){
  if(a.ac != b.ac) return a.ac > b.ac;
  if(a.pn != b.pn) return a.pn < b.pn;
  return a.id < b.id;
}

int main(){
  int n;
  while(1){
    cin >> n;
    if(!n) break;
    map<int, int> team;
    vector<int> ans;
    vector<DATA> data(n,DATA());
    for(int i=0; i<n; ++i){
      cin >> data[i].id >> data[i].t >> data[i].ac >> data[i].pn;
      team.insert(make_pair(data[i].t, 0));
    }
    sort(data.begin(), data.end(), comp);
    for(int i=0; i<data.size() && i<26; ++i){
      if(i < 10){
	if(team[data[i].t] < 3){
	  ans.push_back(data[i].id);
	  ++team[data[i].t];
	}
      }else if(i < 20){
	if(team[data[i].t] < 2){
	  ans.push_back(data[i].id);
	  ++team[data[i].t];
	}
      }else{
	if(team[data[i].t] < 1){
	  ans.push_back(data[i].id);
	  ++team[data[i].t];
	}
      }
    }
    for(int i=0; i<ans.size(); ++i) cout << ans[i] << endl;
  }
  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[301];
	int n,idcount[301];

	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;i<=n;i++){
			if(i<10 && idcount[team[i].belong]<3){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
			else if(i<=10 && i<20 && idcount[team[i].belong]<2){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
			else if(i<=20 && i<26 && idcount[team[i].belong]==0){
				cout<<team[i].id<<endl;
				idcount[team[i].belong]++;
			}
		}
	}
}

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[af] < 3){
	  cnt[af]++;
	  cout << id << endl;
	  all++;
	}
      }else if(all < 20){
	if(cnt[af] < 2){
	  cnt[af]++;
	  cout << id << endl;
	  all++;
	}
      }else if(all < 26){
	if(cnt[af] < 1){
	  cnt[af]++;
	  cout << id << endl;
	  all++;
	}
      }
    }
  }
  return 0;
}