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
}

Python: while 1:
    n = int(input())
    if n == 0:
        break

    data = []
    for _ in range(n):
        i, u, a, p = map(int, input().split())
        data.append([i, u, a, p])

    data = sorted(data, key=lambda x: (-x[2], x[3], x[0]))
    union = [0] * 1001

    cnt = 0
    for d in data:
        i, u, a, p = d
        if cnt < 10 and union[u] < 3:
            print(i)
            cnt += 1
            union[u] += 1
        elif cnt < 20 and union[u] < 2:
            print(i)
            cnt += 1
            union[u] += 1
        elif cnt < 26 and union[u] < 1:
            print(i)
            cnt += 1
            union[u] += 1

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
//#define int long long
using namespace std;

struct team{
    int id, univ, ac, pen;
    //team(int id, int univ, int ac, int pen):id(id), univ(univ), ac(ac), pen(pen){}
};

bool cmp(team d1, team d2){
    if(d1.ac != d2.ac){
        return d1.ac > d2.ac;    
    }else if(d1.pen != d2.pen){
        return d1.pen < d2.pen;
    }else{
        return d1.id < d2.id;
    }
}

signed main(){
    int n;
    while(cin >> n, n){
        vector<team> d(n);
        rep(i, 0, n){
            cin >> d[i].id >> d[i].univ >> d[i].ac >> d[i].pen;
        }
        sort(all(d), cmp);
        /*rep(i, 0, d.size()){
            cout << ' ' << d[i].id << endl;
        }*/
        map<int, int> mp;
        set<int> st;
        int cnt = 0;
        vector<int> ans;
        rep(i, 0, n){
            if(cnt >= 10) break;
            if(mp[d[i].univ] <= 2 && !st.count(d[i].id)){
                ans. push_back(d[i].id);
                st.insert(d[i].id);
                mp[d[i].univ]++;
                cnt++;
            }
        }
        rep(i, 0, n){
            if(cnt >= 20) break;
            if(mp[d[i].univ] <= 1 && !st.count(d[i].id)){
                ans. push_back(d[i].id);
                st.insert(d[i].id);
                mp[d[i].univ]++;
                cnt++;
            }
        }
        rep(i, 0, n){
            if(cnt >= 26) break;
            if(mp[d[i].univ] == 0 && !st.count(d[i].id)){
                ans. push_back(d[i].id);
                st.insert(d[i].id);
                mp[d[i].univ]++;
                cnt++;
            }
        }
        rep(i, 0, cnt){
            cout << ans[i] << endl;
        }
    }
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        vector<pair<int, pair<int, int>>> v;
        int m[1010], af[1010] = {};
        for(int i=0; i < n; i++){
            int id, u, a, p;
            cin >> id >> u >> a >> p;
            m[i] = u;
            v.push_back(make_pair(a*-1, make_pair(p, id)));
        }
        sort(v.begin(), v.end());
        int count = 0;
        for(int i=0; i< n; i++){
            if(count < 10 && af[m[i]] < 3 || count < 20 && af[m[i]] < 2 || count < 26 && af[m[i]] < 1){cout << v[i].second.second << endl; af[m[i]]++; count++;}
        }
    }
}

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

struct Team{
  int id, u, a, p;
  bool operator<(const Team& rhs) const{
    return a > rhs.a || (a == rhs.a && 
			 (p < rhs.p || 
			  (p == rhs.p && id < rhs.id))
			 );
  }
};

int main(){
  int N;
  while(cin >> N, N){
    vector<Team> ts(N);
    for(int i=0;i<N;++i)
      cin >> ts[i].id >> ts[i].u >> ts[i].a >> ts[i].p;
    sort(ts.begin(),ts.end());
    int cnt = 0, U[1001];
    fill(U,U+1001,0);
    for(int i=0;i<N;++i){
      if(cnt < 10 && U[ts[i].u] < 3){
	++cnt, ++U[ts[i].u];
	cout << ts[i].id << endl;
      }
      else if(cnt < 20 && U[ts[i].u] < 2){
	++cnt, ++U[ts[i].u];
	cout << ts[i].id << endl;
      }
      else if(cnt < 26 && U[ts[i].u] < 1){
	++cnt, ++U[ts[i].u];
	cout << ts[i].id << endl;
      }
    }
  }

  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAX = 1001;
const int INF = 1<<29;
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]={0};
    vector<P> v;

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

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

  return 0;
}