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;
int n,sc[10010],selected;
struct Set{
  int I,U,A,P;
};
bool comp(const Set& a, const Set& b){
  if(a.A!=b.A){
    return a.A>b.A;
  }else{
    return a.P<b.P;
  }
}
vector<Set> vec;
void el(int x){
  sc[vec[x].U]++;
  selected++;
  cout<<vec[x].I<<endl;
}
int main(){
  while(1){
    cin>>n;
    for(int i=0;i<n;i++)sc[i]=0;
    vec.clear();selected=0;
    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&&selected<26;i++){
      if(selected<10){
	if(sc[vec[i].U]<3)el(i);
      }else if(selected<20){
	if(sc[vec[i].U]<2)el(i);
      }else{
	if(sc[vec[i].U]==0)el(i);
      }
    }
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int n,id,u,a,p;
  while(cin>>n){
    if(n==0) break;
    vector<pair<PII,int> > data;
    map<int,int> t;
    int team[1001]={0};
    REP(i,n){
      cin>>id>>u>>a>>p;
      t[id] = u;
      data.push_back(pair<PII,int>(PII(-a,p),id));
    }
    sort(data.begin(),data.end());
    int select=0;
    REP(i,data.size()){
      pair<PII,int> d = data[i];
      int id = d.second;
      int univ = t[id];
      int count = team[univ]; 
      if((select<10&&count<3)
          ||(select<20&&count<2)
          ||(select<26&&count<1)){
        team[univ]++;
        select++;
        cout<<id<<endl;
      }
    }
  }
  return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)

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

int main()
{
	int n,l,p,a,u;
	while(cin >> n && n)
	{
		int univ[1001] = {};
		map<pp,int> m;
		REP(n)
		{
			cin >> l >> u >> a >> p ;
			m[pp(-a,make_pair(p,make_pair(l,u)))] = l;
		}
		int y = 0;
		for(map<pp,int>::iterator it = m.begin();it!=m.end();++it)
		{
			int j = it->first.second.second.second;
			if(y<10&&univ[j]<3 || y<20&&univ[j]<2 || y<26&&univ[j]<1)
			{
				y++;univ[j]++;
				cout << it->second << endl;
			}

		}

	}
	return 0;
}

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

struct Team {
	int id, u, ac, time;
	bool operator<(Team &r) {
		if (ac != r.ac) return ac > r.ac;
		if (time != r.time) return time < r.time;
		return id < r.id;
	}
}teams[1000];

bool is_select(int num, int unum) {
	if (num < 10) { return unum < 3; }
	if (num < 20) { return unum < 2; }
	if (num < 26) { return unum < 1; }
	return false;
}

void solve(int n) {
	for (int i = 0; i < n; i++) {
		cin >> teams[i].id >> teams[i].u >> teams[i].ac >> teams[i].time;
	}
	sort(teams, teams + n);
	
	int u_num[1000] = {0};
	int num = 0;
	
	for (int i = 0; i < n; i++) {
		if (is_select(num, u_num[teams[i].u])) {
			cout << teams[i].id << endl;
			u_num[teams[i].u]++;
			num++;
		}
	}
}

int main() {
	int n;
	while (cin >> n, n) {
		solve(n);
	}
	return 0;
}

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

struct Team {
	int id;
	int uni;
	int solved;
	int penalty;
	bool selected;

	bool operator<(const Team& another) const {
		if(solved != another.solved) {
			return (solved > another.solved);
		}
		if (penalty != another.penalty) {
			return (penalty < another.penalty);
		}
		return id < another.id;
	}
};

int selectedCounts[1001];

int main() {
	int n;
	while(true) {
		cin >> n;
		if (n == 0) {
			break;
		}

		vector<Team> teams(n);
		for (int i = 0; i < n; i++) {
			cin >> teams[i].id >> teams[i].uni >> teams[i].solved >> teams[i].penalty;
			teams[i].selected = false;
		}

		for (int i = 0; i < 1001; i++) {
			selectedCounts[i] = 0;
		}

		sort(teams.begin(), teams.end());

		int entireSelectedCount = 0;

		for (int i = 0; i < n; i++) {
			if(entireSelectedCount < 10 && selectedCounts[teams[i].uni] < 3
					|| entireSelectedCount < 20 && selectedCounts[teams[i].uni] < 2
					|| entireSelectedCount < 26 && selectedCounts[teams[i].uni] < 1) {
				selectedCounts[teams[i].uni]++;
				entireSelectedCount++;
				cout << teams[i].id << endl;
			}
		}

	}
	return 0;
}