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<string>
#include<vector>
using namespace std;
typedef pair<pair<int, int>, pair<int, int>> Pr;
signed main() {
	int n;
	while (cin >> n, n) {
		Pr p; vector<Pr>v;
		for (int i = 0; i < n; i++) {
			cin >> p.second.first >> p.second.second >> p.first.first >> p.first.second;
			p.first.first = 11 - p.first.first;
			v.push_back(p);
		}
		sort(v.begin(), v.end());
		int f[1200]; for (int i = 1; i <= 1000; i++)f[i] = 0;
		vector<int>ans;
		for (Pr i : v) {
			if (ans.size() < 10) {
				if (f[i.second.second] < 3) {
					ans.push_back(i.second.first);
					f[i.second.second]++;
				}
			}
			else if (ans.size() < 20) {
				if (f[i.second.second] < 2) {
					ans.push_back(i.second.first);
					f[i.second.second]++;
				}
			}
			else if (ans.size() < 26) {
				if (f[i.second.second] < 1) {
					ans.push_back(i.second.first);
					f[i.second.second]++;
				}
			}
		}
		for (int i : ans)cout << i << endl;
	}
}

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;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<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> Pi;

int main(){
  int n;
  Pi team[333];
  while(cin >> n,n){
    for(int i=0;i<n;i++){
      int I,U,A,B;
      cin >> I >> U >> A >> B;
      P tmp1; tmp1.first = A; tmp1.second = -B;
      P tmp2; tmp2.first = -I; tmp2.second = U;
      team[i].first = tmp1; team[i].second = tmp2;
    }
    sort(team,team+n,greater<Pi>() );
    int idx = 0;
    int cnt = 0;
    int flg[1111]={0};
    while(idx < n && cnt < 26){
      int num = team[idx].second.second;
      int ID = -team[idx].second.first;
      if(cnt < 10){
	if(flg[num] < 3){
	  flg[num]++;
	  cout << ID << endl;
	}
      } else if(cnt < 20){
	if(flg[num] < 2){
	  flg[num]++;
	  cout << ID << endl;
	}
      } else if(cnt < 26){
	if(flg[num] < 1){
	  flg[num]++;
	  cout << ID << endl;
	}
      }
      idx++;
    }
  }
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <map>
#include <set>
using namespace std;

#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,s,n) for(int i=s; i<n; i++)
#define ALL(x) x.begin(), x.end()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;

int passed[1001];

struct team {
	int i, u, a, p;
	team(int I, int U, int A, int P) {
		i = I;
		u = U;
		a = A;
		p = P;
	}
};

bool operator<(const team& l, const team& r) {
	if( l.a == r.a ) {
		if( l.p == r.p ) {
			return l.i < r.i;
		}
		return l.p < r.p;
	}
	return l.a > r.a;
}

int main() {
	int n;
	while(cin >> n, n) {
		memset(passed, 0, sizeof(passed));
		vector<team> t;
		rep(i, n) {
			int I, U, A, P;
			cin >> I >> U >> A >> P;
			t.push_back( team(I,U,A,P) );
		}
		sort( t.begin(), t.end() );
		vector<int> id;
		rep(i, n) {
			if(id.size() < 10) {
				if( passed[t[i].u] < 3 ) {
					id.push_back(t[i].i);
					passed[t[i].u]++;
				}
			}
			else if(id.size() < 20) {
				if( passed[t[i].u] < 2 ) {
					id.push_back(t[i].i);
					passed[t[i].u]++;
				}
			}
			else if(id.size()<26) {
				if( passed[t[i].u] < 1 ) {
					id.push_back(t[i].i);
					passed[t[i].u]++;
				}
			}
		}
		rep(i, id.size()) {
			cout << id[i] << endl;
		}
	}
	return 0;
}