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 <vector>
#include <algorithm>
using namespace std;

typedef struct
{
  int I, U, A, P;
} Team;

class solve
{
public:
  bool operator()(const Team& lhs, const Team& rhs)
  {
    if (lhs.A == rhs.A) {
      if (lhs.P == rhs.P)
	return lhs.I < rhs.I;
      return lhs.P < rhs.P;
    }
    return lhs.A > rhs.A;
  }
};

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

    vector<Team> team(n);
    for (int i = 0; i < n; ++i)
      cin >> team[i].I >> team[i].U >> team[i].A >> team[i].P;
    sort(team.begin(), team.end(), solve());

    int advance = 0;
    vector<int> univ(1000, 0);
    for (int i = 0; i < n; ++i) {
      if (advance < 10) {
	if (univ[team[i].U-1] < 3) {
	  cout << team[i].I << endl;
	  ++univ[team[i].U-1];
	  ++advance;
	}
      } else if (advance < 20) {
	if (univ[team[i].U-1] < 2) {
	  cout << team[i].I << endl;
	  ++univ[team[i].U-1];
	  ++advance;
	}
      } else if (advance < 26) {
	if (univ[team[i].U-1] < 1) {
	  cout << team[i].I << endl;
	  ++univ[team[i].U-1];
	  ++advance;
	}
      }
    }

  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

struct TEAM{
	int i;
	int u;
	int a;
	int p;
};
bool operator<(const TEAM &a,const TEAM &b){
	pair<pair<int,int>,int> A = make_pair(make_pair(a.a,-a.p),-a.i);
	pair<pair<int,int>,int> B = make_pair(make_pair(b.a,-b.p),-b.i);
	return A < B;
}

int main(){
	int n;
	while(cin >> n){
		vector<TEAM> team(n);
		rep(i,n)cin >> team[i].i >> team[i].u >> team[i].a >> team[i].p;
		sort(team.begin(),team.end());
		reverse(team.begin(),team.end());
		rep(i,n)
			cout <<  team[i].i << " " << team[i].u << " " <<  team[i].a << " " <<  team[i].p << endl;
		map<int,int> memo;
		vector<int> ret;
		
		int i=0;
		while(1){
			if(i >= team.size() || ret.size()>=26)break;
			TEAM use = team[i];
			if(ret.size()<10){
				if(memo[use.u]<3){
					ret.push_back(use.i);
					memo[use.u]++;
				}
			}else if(ret.size()<	20){
				if(memo[use.u]<2){
					ret.push_back(use.i);
					memo[use.u]++;
				}
			}else{
				if(memo[use.u]<1){
					ret.push_back(use.i);
					memo[use.u]++;
				}
			}
			i++;
		}
		rep(i,ret.size()){
			cout << ret[i] << endl;
		}
	}
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
struct team{
	int id,univ,solved,pen;
};
team dat[300];
int u[1001];
inline bool operator<(const team&a,const team&b){
	if(a.solved!=b.solved)return a.solved>b.solved;
	if(a.pen!=b.pen)return a.pen<b.pen;
	return a.id<b.id;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<=1000;i++)u[i]=0;
		for(int i=0;i<a;i++){
			scanf("%d%d%d%d",&dat[i].id,&dat[i].univ,&dat[i].solved,&dat[i].pen);
		}
		std::sort(dat,dat+a);
		int now=0;
		for(int i=0;i<a;i++){
			if(now==26)break;
			if((now<10&&u[dat[i].univ]<3)||(now<20&&u[dat[i].univ]<2)||(u[dat[i].univ]==0)){
				now++;
				printf("%d\n",dat[i].id);
				u[dat[i].univ]++;
			}
		}
	}
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,sc[10010];
struct Set{
  int I,U,A,P;
};
bool comp(const Set& a, const Set& b){
  double ap,bp;
  ap=(double)a.A-((double)a.P)/100000.0;
  bp=(double)b.A-((double)b.P)/100000.0;
  return ap>bp;
}
vector<Set> vec;
void el(int x){
  sc[vec[x].U]++;
  cout<<vec[x].I<<endl;
}
int main(){
  while(1){
    cin>>n;
    for(int i=0;i<n;i++)sc[i]=0;
    vec.clear();
    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;i++){
      if(i<10){
	if(sc[vec[i].U]<3)el(i);
      }else if(i<20){
	if(sc[vec[i].U]<2)el(i);
      }else if(i<26){
	if(sc[vec[i].U]==0)el(i);
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

struct P {
	int i, u, a, p;
	P(int i = 0, int u = 0, int a = 0, int p = 0): i(i), u(u), a(a), p(p){}
	bool operator < (const P &t) const {
		if (a != t.a) return a > t.a;
		if (p != t.p) return p < t.p;
		return i < t.i;
	}
};

vector<int> res;
int cnt[1001];

int main()
{
	int n;
	while (scanf("%d", &n), n){
		res.clear();
		memset(cnt, 0, sizeof(cnt));
		vector<P> ps;
		for (int i = 0; i < n; i++){
			int _i, u, a, p;
			scanf("%d %d %d %d", &_i, &u, &a, &p);
			ps.push_back(P(_i, u, a, p));
		}
		sort(ps.begin(), ps.end());
		for (int i = 0; i < ps.size(); i++){
			P &p = ps[i];
			if (res.size() < 10){
				if (cnt[p.u] < 3){
					res.push_back(p.i);
					cnt[p.u]++;
				}
			}
			else if (res.size() < 20){
				if (cnt[p.u] < 2){
					res.push_back(p.i);
					cnt[p.u]++;
				}
			}
			else if (res.size() < 26){
				if (cnt[p.u] < 1){
					res.push_back(p.i);
					cnt[p.u]++;
				}
			}
		}
		sort(res.begin(), res.end());
		for (int i = 0; i < res.size(); i++){
			printf("%d\n", res[i]);
		}
	}
	return 0;
}