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 <bits/stdc++.h>
using namespace std;

struct Team{
  int id;
  int university;
  int solve;
  int penalty;

  Team(int i, int u, int s, int p) {
    id = i;
    university = u;
    solve = s;
    penalty = p;
  }
  bool operator < (const Team& o) const {
    if (solve != o.solve) return solve > o.solve;
    if (penalty != o.penalty) return penalty < o.penalty;
    return id < o.id;
  }
};

int main() {
  int n, i, u, a, p;
  while (cin >> n, n != 0) {
    vector<Team> v;
    for (int j = 0; j < n; j++) {
      cin >> i >> u >> a >> p;
      v.push_back(Team(i, u, a, p));
    }
    sort(v.begin(), v.end());
    
    int univ[n] = {}, cnt = 0;
    for (auto t : v) {
      int limit = cnt < 10 ? 3 : cnt < 20 ? 2 : cnt < 26 ? 1 : 0;
      if (univ[t.university] < limit) {
	cout << t.id << endl;
	univ[t.university]++;
	cnt++;
      }
    }
  } 
  return 0;
}

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

int main(){
  int total,i,u,a,p,n,m;
  for(;cin>>n,n;){
    map<int,int> school,senbatsu;
    vector< pair< pair<int,int>,int > > v;
    for(total=m=0;m<n;m++){
      cin>>i>>u>>a>>p;
      school[i]=u;
      v.push_back(make_pair(make_pair(-a,p),i));
    }
    sort(v.begin(),v.end());

    for(m=0;m<n;m++){
      if(
        (total<10&&senbatsu[school[v[m].second]]<3) ||
        (total<20&&senbatsu[school[v[m].second]]<2) ||
        (total<26&&senbatsu[school[v[m].second]]<1)
      ){
        senbatsu[school[v[m].second]]++;total++;
        cout<<v[m].second<<endl;
      }
    }
  }
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

#define DEBUG(x) cout<<"#x"<<": "<<x<<endl

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

map<int,bool> used;
map<int,int> count_t;
map<int,bool> isDecided;

int main(){
    while(true){
	int n;
	vector< pair< pair<int,int> , pair<int,int> > > t;
	cin >> n;
	if(n==0) break;
	used.clear();
	count_t.clear();
	isDecided.clear();
	REP(i,n){
	    int I,A,U,P;
	    cin >> I >> U >> A >> P;
	    t.PB( MP( MP(-A,P) , MP(I,U) ) );
	    used[I] = false;
	    count_t[U] = false;
	    isDecided[I] = false;
	}
	sort(ALL(t));
// 	REP(i,n) printf("A: %d P: %d I: %d U: %d\n",-t[i].first.first,t[i].first.second,t[i].second.first,t[i].second.second);
	int temp = 0;

	REP(i,n){
	    if(!used[t[i].second.second]){
		used[t[i].second.second] = true;
		count_t[t[i].second.second]++;
		isDecided[t[i].second.first] = true;
		temp++;
	    }
	}

	if(temp < 10){
	    REP(i,n){
		if(!isDecided[t[i].second.first] && count_t[t[i].second.second] < 3){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
		    temp++;
		}
		if(temp == 10) break;
	    }
	}


	if(temp < 20){
	    REP(i,n){
		if(!isDecided[t[i].second.first] && count_t[t[i].second.second] < 2){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
			temp++;
		}
		if(temp == 20) break;
	    }
	}

	if(temp < 26){
	    REP(i,n){
		if(!isDecided[t[i].second.second] && count_t[t[i].second.second] < 1){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
		    temp++;
		}
		if(temp == 26) break;
	    }
	}

	REP(i,n){
	    if(isDecided[t[i].second.first]) cout << t[i].second.first << endl;
	}
    }

    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#define F first
#define S second
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;

bool cmp(const PP &p,const PP &q){
  if(p.S.F != q.S.F)return p.S.F > q.S.F;
  if(p.S.S != q.S.S)return p.S.S < q.S.S;
}


int main(){
  int n;
  int I,U,A,Po;
  while(cin >> n && n){
    vector<PP> vec;
    map<int,int> entitle; 
    for(int i=0;i<n;i++){
      cin >> I >> U >> A >> Po;
      vec.push_back(PP(P(I,U),P(A,Po)));
    }
    sort(vec.begin(),vec.end(),cmp);
    int norisuke = 0; 
    int limit;
    for(int i=0;i<n;i++){
      limit = norisuke<10?3:norisuke<20?2:norisuke<26?1:0;
      int AD = vec[i].F.S;
      if(entitle[AD] < limit){
	entitle[AD]++;
	cout << vec[i].F.F << endl;
	norisuke++;
      }
    }

  }
  return 0;
}