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>

using namespace std;

struct TEAM
{
	short id;
	short af;
	int pt;
	char ac;
};
typedef struct TEAM team;

int main()
{
	int n;
	team tt[300];
	char ok[1001];

	while(cin >> n, n)
	{
		for(int i=0; i < n; i++) {
			cin >> tt[i].id;
			cin >> tt[i].af;
			char tmp; cin >> tmp; tt[i].ac = tmp - '0';
			cin >> tt[i].pt;
		}
		// sort
		int nn = n - 1;
		for(int i=0; i < nn; i++) {
			for(int j=i+1; j < n; j++) {
				if(tt[i].ac < tt[j].ac) {
					swap(tt[i], tt[j]);
				}
				else if(tt[i].ac == tt[j].ac) {
					if(tt[i].pt > tt[j].pt) {
						swap(tt[i], tt[j]);
					}
					else if(tt[i].pt == tt[j].pt) {
						if(tt[i].id > tt[j].id) {
							swap(tt[i], tt[j]);
						}
					}
				}
			}
		}
		// \sort
		for(int i=0; i < 1001; i++) ok[i] = 0;
		int cnt = 0;
		for(int i=0; i < n; i++) {
			if(cnt < 10) { // rule1
				if(ok[tt[i].af] < 3) {
					ok[tt[i].af]++;
					cout << tt[i].id << endl;
				}
			}
			else if(cnt < 20) { // rule2
				if(ok[tt[i].af] < 2) {
					ok[tt[i].af]++;
					cout << tt[i].id << endl;
				}
			}
			else if(cnt < 26) { // rule3
				if(ok[tt[i].af] < 1) {
					ok[tt[i].af]++;
					cout << tt[i].id << endl;
				}
			}
			else
				break;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <functional>
#include <queue>

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> Q;
typedef pair<int, Q> R;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int hyou2[1005] = {0};
		priority_queue<R> pq;
		R r;
		for (int i = 0; i < n; i++) {
			cin >> ((r.second).second).first >> ((r.second).second).second >> r.first >> (r.second).first;
			pq.push(r);
		}
		vector<int> hyou;
		while (!pq.empty()) {
			R rr = pq.top();
			pq.pop();
			priority_queue< Q, vector<Q>, greater<Q> > pqq;
			pqq.push(rr.second);
			while (!pq.empty() && (pq.top()).first == rr.first) {
				pqq.push((pq.top()).second);
				pq.pop();
			}
			while (!pqq.empty()) {
				Q q = pqq.top();
				pqq.pop();
				priority_queue< P, vector<P>, greater<P> > pqp;
				pqp.push(q.second);
				while (!pqq.empty() && (pqq.top()).first == q.first) {
					pqp.push((pqq.top()).second);
					pqq.pop();
				}
				while (!pqp.empty()) {
					P p = pqp.top();
					pqp.pop();
					if (hyou.size() < 10) {
						if (hyou2[p.second] < 3) {
							hyou.push_back(p.first);
							hyou2[p.second]++;
						}
					} else if (hyou.size() < 20) {
						if (hyou2[p.second] < 2) {
							hyou.push_back(p.first);
							hyou2[p.second]++;
						}
					} else if (hyou.size() < 26) {
						if (hyou2[p.second] < 1) {
							hyou.push_back(p.first);
							hyou2[p.second]++;
						}
					}
				}
			}
		}
		for (int i = 0; i < hyou.size(); i++) {
			cout << hyou[i] << endl;
		}
	}
	return 0;
}

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

using namespace std;

const int MAX = 300;
const int UMAX = 1001;
typedef pair<int,int> P;

int n;
struct team{
  int I;
  int U;
  int A;
  int P;
  bool passed;
};
int UNUM[UMAX];
team T[MAX];
int pass;
P p[3] = {P(10,3),P(20,2),P(26,1)};


void T_sort(){

  for(int i = 0; i < n; i++)
    for(int j = i; j < n; j++)
      if(T[i].A < T[j].A || T[i].A == T[j].A && T[i].P > T[i].P ||
	 T[i].A == T[j].A && T[i].P == T[j].P && T[i].I > T[j].I)
	swap(T[i],T[j]);
}

void solve(){
 
  for(int R = 0; R < 3; R++)
    for(int i = 0; pass < p[R].first,i < n; i++){
      if(T[i].passed == false && UNUM[T[i].U] < p[R].second){
	cout << T[i].I << endl;
	T[i].passed = true;
	UNUM[T[i].U]++;
	pass++;
      }
    }
}


void init(){
  pass = 0;
  fill(UNUM,UNUM+UMAX,0);
}
int main(){
  while(cin >> n && n){
    init();
    for(int i = 0; i < n; i++){
      cin >> T[i].I >> T[i].U >> T[i].A >> T[i].P;
      T[i].passed = false;
    }
    T_sort();
    solve();
  }
  
  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;
}