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

class team{
public:
  team(int a, int b, int c, int d){
    id = a;
    aff = b;
    ac = c;
    pen = d;
  }
  int id;
  int aff;
  int ac;
  int pen;

  bool operator <(const team arg) const{
    if(ac != arg.ac){
      return ac > arg.ac;
    }else{
      if(pen != arg.pen){
	return pen < arg.pen;
      }else{
	return id < arg.id;
      }
    }
  }
};

int main(void){
  int n;
  while(cin >> n && n){
    vector<team> v;
    map<int,int> m;
    int a,b,c,d;
    int selected = 0;
    for(int i=0;i<n;i++){
      cin >> a >> b >> c >> d;
      v.push_back(team(a,b,c,d));
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++){
      if(selected < 10 && m[v[i].aff] < 3){
	cout << v[i].id <<endl;
	m[v[i].aff]++;
	selected++;
	continue;
      }
      if(selected < 20 && m[v[i].aff] < 2){
	cout << v[i].id <<endl;
	m[v[i].aff]++;
	selected++;
	continue;
      }
      if(selected < 26 && m[v[i].aff] == 0){
	cout << v[i].id <<endl;
	m[v[i].aff]++;
	selected++;
	continue;
      }
    }
  }
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

class C{
  public:
    int id, u, a, p;
    C(){}
    bool operator < (const C &c) const {
      if(a != c.a) return a > c.a;
      if(p != c.p) return p < c.p;
      return id < c.id;
    }
};

int main() {
  int N;
  while(cin >>N && N){
    vector<C> T(N);
    REP(i, N) cin >>T[i].id >>T[i].u >>T[i].a >>T[i].p;
    SORT(T);
    map<int, int> m;
    int cnt = 0;
    REP(i, N){
      if(cnt < 10){
        if(m[T[i].u] < 3){
          cout <<T[i].id <<endl;
          m[T[i].u] += 1;
        }
      } else if(cnt < 20){
        if(m[T[i].u] < 2){
          cout <<T[i].id <<endl;
          m[T[i].u] += 1;
        }
      } else if(cnt < 26){
        if(m[T[i].u] < 1){
          cout <<T[i].id <<endl;
          m[T[i].u] += 1;
        }
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef pair <int, int> PII;
typedef pair <PII, PII> PPP;
typedef vector <PPP> VPPP;
typedef vector <int> VI;

int main() {
    int n;
    while ( cin >> n && n ) {
        VPPP L(n);
        VI H(1000,0);
        for ( int i = 0; i < n; ++ i ) {
            cin >> L[i].second.first >> L[i].second.second;
            cin >> L[i].first.first >> L[i].first.second;
            L[i].second.first = 1000 - L[i].second.first;
            L[i].second.second = 1000 - L[i].second.second;
            L[i].first.second = 100000 - L[i].first.second;
        }
        sort( L.rbegin(), L.rend() );
        int cnt = 0;
        for ( int i = 0; i < n; ++ i ) {
            int ID = 1000 - L[i].second.first;
            int AF = 1000 - L[i].second.second;
            bool flag = false;
            if ( cnt < 10 ) {
                if ( H[AF] < 3 ) {
                    cnt ++;
                    H[AF] ++;
                    flag = true;
                }
            } else if ( cnt < 20 ) {
                if ( H[AF] < 2 ) {
                    cnt ++;
                    H[AF] ++;
                    flag = true;
                }
            } else if ( cnt < 26 ) {
                if ( H[AF] < 1 ) {
                    cnt ++;
                    H[AF] ++;
                    flag = true;
                }
            }
            if ( flag ) cout << ID << endl;
        }
    }
	return 0;
}

C++: //08
#include<iostream>
#include<algorithm>

using namespace std;

struct T{
  int i,u,a,p;
  T(){}
  T(int ii,int uu,int aa,int pp){
    i=ii;
    u=uu;
    a=aa;
    p=pp;
  }
  bool operator<(T x)const{
    if(a!=x.a){
      return a>x.a;
    }else if(p!=x.p){
      return p<x.p;
    }else{
      return i<x.i;
    }
  }
};

int main(){
  for(int n;cin>>n,n;){
    T team[300];
    for(int j=0;j<n;j++){
      int i,u,a,p;
      cin>>i>>u>>a>>p;
      team[j]=T(i,u,a,p);
    }
    sort(team,team+n);
    int ci[1001]={};
    for(int i=0,c=0;i<n&&c<26;i++){
      if(ci[team[i].u]<(c<10)+(c<20)+(c<26)){
	cout<<team[i].i<<endl;
	ci[team[i].u]++;
	c++;
      }
    }
  }
  return 0;
}