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<map>
#include<algorithm>
#include<cstdio>

using namespace std;

typedef pair<int, pair<int, pair<int, int> > > data;

#define f first
#define s second
#define ID s.s.f
#define AF s.s.s
#define SL f
#define PN s.f

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


int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  while(int n = getInt()){
    vector<data> v(n);

    REP(i, n){
      v[i].ID = -getInt();
      v[i].AF = getInt();
      v[i].SL = getInt();
      v[i].PN = -getInt();
    }

    sort(v.rbegin(), v.rend());

    int all = 0;
    map<int, int> cnt;

    for(int i = 0; i < n; i++){
      int id = -v[i].ID;
      int af = v[i].AF;

      if(all < 10){
	if(cnt[id] < 3){
	  cnt[id]++;
	  cout << id << endl;
	}
      }else if(all < 20){
	if(cnt[id] < 2){
	  cnt[id]++;
	  cout << id << endl;
	}
      }else if(all < 26){
	if(cnt[id] < 1){
	  cnt[id]++;
	  cout << id << endl;
	}
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> dP;

const int INF = 100000000;
const double EPS = 1e-10;

int d[100001];
int dsum[100001];

struct team{
	int id;
	int univ;
	int solved;
	int pena;
	bool operator <(const team& other) const{
		if(solved == other.solved){
			if(pena == other.pena){
				return id > other.id;
			}else{
				return pena > other.pena;
			}
		}else{
			return solved < other.solved;
		}
	}
};

int main(){
	while(1){
		int n;
		cin >> n;
		if(!n)break;
		vector<team> v;
		rep(i, n){
			team t;
			cin >> t.id >> t.univ>> t.solved >> t.pena;
			v.push_back(t);
		}
		sort(all(v));
		reverse(all(v));

		int cnt = 0;
		map<int, int> univcnt;

		rep(i, n){
			if(cnt < 10){
				if(univcnt[v[i].univ] < 3){
					cout << v[i].id << endl;
					cnt++;
					univcnt[v[i].univ]++;
				}
			}
			else if(cnt < 20){
				if(univcnt[v[i].univ] < 2){
					cout << v[i].id << endl;
					cnt++;
					univcnt[v[i].univ]++;
				}
			}
			else if(cnt < 26){
				if(univcnt[v[i].univ] < 1){
					cout << v[i].id << endl;
					cnt++;
					univcnt[v[i].univ]++;
				}
			}
		}
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAX = 1001;
typedef pair<int,int> QQ;
typedef pair<int,int> PP;
typedef pair<PP,QQ> P;

int main(){
  int n;

  while(cin >> n ,n){
    int id,uni,ac,pe;
    int tc[MAX+1];
    fill(tc,tc+MAX,0);
    vector<P> v;
    v.clear();

    while(n--){
      cin >> id >> uni >> ac >> pe;
      v.push_back(P(PP(-ac,pe),QQ(id,uni)));
    } 
    sort(v.begin(),v.end());

    int cnt = 0;
    int size = v.size();
    for(int i = 0; i < size ; i++){
      int u = v[i].second.second;
      cnt++;
      tc[u]++;
      if(cnt <= 10){
	if(tc[u] <= 3){
	  cout << v[i].second.first << endl;
	}
      }
      else if(cnt <= 20){
	if(tc[u] <= 2){
	  cout << v[i].second.first << endl;
	}
      }
      else if(cnt <= 26){
	if(tc[u] <= 1){
	  cout << v[i].second.first << endl;
	}
      }
    } 
  }

  return 0;
}

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

using namespace std;

int main()
{
    int N; vector<int> I, U, A, P, C;
    
    while(true)
    {
        cin >> N;
        
        if(N == 0) { break; }
        
        for(int i = 0; i < N; i++)
        {
            cin >> I[i] >> U[i] >> A[i] >> P[i];
        }
        
        C = vector<int>(N, 0);
        
        for(int i = 0; i < N; i++)
        {
            for(int j = i + 1; j < N; j++)
            {
                if(A[i] < A[j] || (A[i] == A[j] && P[i] > P[j]))
                {
                    swap(A[i], A[j]);
                    swap(P[i], P[j]);
                    swap(I[i], I[j]);
                    swap(U[i], U[j]);
                }
            }
        }
        
        int count_ = 0;
        
        for(int i = 0; i < N; i++)
        {
            if((count_ < 10 && C[U[i]] < 3) || (count_ < 20 && C[U[i]] < 2) || (count_ < 26 && C[U[i]] == 0))
            {
                cout << I[i] << endl;
                
                C[U[i]]++; count_++;
            }
        }
    }
    
    return 0;
}