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

#define f first
#define s second

typedef pair<int, int> P;
typedef pair<P, P> P2;

int main(){
  int n;
  P2 team[310];
  int id, u, a, p;
  while(cin >> n, n){
    for(int i = 0 ; i < n ; i++){
      cin >> id >> u >> a >> p;
      team[i].f.f = -a;
      team[i].f.s = p;
      team[i].s.f = u;
      team[i].s.s = id;
    }
    
    sort(team, team+n);
    
    map<int, int> AC_cnt;
    vector<int> AC_team;
    
    for(int i = 0 ; i < n ; i++){
      AC_cnt[team[i].s.f]++;
      if(AC_team.size() < 10 && AC_cnt[team[i].s.f] <= 3){
	AC_team.push_back(team[i].s.s);
      }
      else if(AC_team.size() < 20 && AC_cnt[team[i].s.f] <= 2){
	AC_team.push_back(team[i].s.s);
      }
      else if(AC_team.size() < 26 && AC_cnt[team[i].s.f] <= 1){
	AC_team.push_back(team[i].s.s);
      }
    }
    
    for(int i = 0 ; i < AC_team.size() ; i++){
      cout << AC_team[i] << endl;
    }
    /*
    for(int i = 0 ; i < n ; i++){
      printf("%d %d %d %d\n", team[i].s.s, team[i].s.f, -team[i].f.f, team[i].f.s);
    }
    */
  }
  return 0;
}

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

struct Teams {
  int l,U,A,P;
};
int main() {
  std::ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  while (true) {
    int n; cin>>n; if (!n) break;
    Teams teams[n];
    for (int i=0; i<n; i++) {
      cin>>teams[i].l>>teams[i].U>>teams[i].A>>teams[i].P;
    }
    /* for (int i=0; i<n; i++) {
      for (int j=i+1; j<n; j++) {
	if (teams[i].U>teams[j].U) swap(teams[i],teams[j]);
      }
      }*/
    for (int i=0; i<n; i++) {
      for (int j=i+1; j<n; j++) {
	if (teams[i].U==teams[j].U) {
	  if (teams[i].A<teams[j].A) swap(teams[i],teams[j]);
	}
      }
    }
    for (int i=0; i<n; i++) {
      for (int j=i+1; j<n; j++) {
	if (teams[i].U==teams[j].U) {
	  if (teams[i].P>teams[j].P) swap(teams[i],teams[j]); 
	}
      }
    }
    int N[1001]; memset(N,0,sizeof(N));
    vector<int> AnsteamsID;
    int teamscnt=0;
    for (int i=0; i<n-1; i++) {
      if (teams[i].U==teams[i+1].U) N[teams[i].l]++;
      if (teamscnt<10) {
	if (N[teams[i].l]<3) {
	  teamscnt++;
	  AnsteamsID.push_back(teams[i].l);
	}
      }
      else if (teamscnt<20) {
	if (N[teams[i].l]<2) {
	  teamscnt++;
	  AnsteamsID.push_back(teams[i].l);
	}
      }
      else if (teamscnt<26) {
	int oneteam=0;
	for (int j=0; j<1001; j++) {
	  if (N[j]>0) {
	    oneteam++;
	  }
	}
	if (oneteam==1) AnsteamsID.push_back(teams[i].l);
      } 
    }
    for (int i=0; i<AnsteamsID.size(); i++) {
      cout<<AnsteamsID[i]<<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#define MAX_N 1001
using namespace std;
int n,I[MAX_N],U[MAX_N],A[MAX_N],P[MAX_N];

void b_sort(int a,int b){
  swap(I[a],I[b]);
  swap(U[a],U[b]);
  swap(A[a],A[b]);
  swap(P[a],P[b]);
}

int main(){

  while(cin >> n,n){
    for(int i = 0 ; i < n ; i++  ){
      cin >> I[i] >> U[i] >> A[i] >> P[i]; 
    }

    for(int i = 0 ; i < n-1 ; i++ )
      for(int j = n-1 ; j > 0 ; j-- )
	if(I[j-1] > I[j])b_sort(j-1,j);

    for(int i = 0 ; i < n-1 ; i++ )
      for(int j = n-1 ; j > 0 ; j-- )
	if(P[j-1] > P[j])b_sort(j-1,j);

    for(int i = 0 ; i < n-1 ; i++ )
      for(int j = n-1 ; j > 0 ; j-- )
	if(A[j-1] < A[j])b_sort(j-1,j);
    
    int teamLimit[MAX_N],now = 0;
    fill(teamLimit,teamLimit + n,0);
    for(int i = 0 ; i < n ; i++ ){
      if(26 <= now )break;
      if(now < 10){
	if(teamLimit[U[i]] < 3 ){
	  teamLimit[U[i]]++;
	  cout << I[i] << endl;
	  now++; 
	}
      } else if(now < 20){
	if(teamLimit[U[i]] < 2 ){
	  teamLimit[U[i]]++;
	  cout << I[i] << endl;
	  now++; 
	}
      } 
    }
  }
  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]]++;
        cout<<v[m].second<<endl;
      }
    }
  }
}

C++: #include <iostream>
#define MAX_N 1001
using namespace std;
int n,I[MAX_N],U[MAX_N],A[MAX_N],P[MAX_N];

void b_sort(int a,int b){
  swap(I[a],I[b]);
  swap(U[a],U[b]);
  swap(A[a],A[b]);
  swap(P[a],P[b]);
}

int main(){

  while(cin >> n,n){
    for(int i = 0 ; i < n ; i++  ){
      cin >> I[i] >> U[i] >> A[i] >> P[i]; 
    }

    for(int i = 0 ; i < n-1 ; i++ )
      for(int j = n-1 ; j > 0 ; j-- )
	if(I[j-1] > I[j])b_sort(j-1,j);

    for(int i = 0 ; i < n-1 ; i++ )
      for(int j = n-1 ; j > 0 ; j-- )
	if(P[j-1] > P[j])b_sort(j-1,j);

    for(int i = 0 ; i < n-1 ; i++ )
      for(int j = n-1 ; j > 0 ; j-- )
	if(A[j-1] < A[j])b_sort(j-1,j);
    
    int teamLimit[MAX_N],now = 0;
    fill(teamLimit,teamLimit + MAX_N,0);
    for(int i = 0 ; i < n ; i++ ){
      if(26 == now )break;

      if(now < 10){
	if(teamLimit[U[i]] < 3 ){
	  teamLimit[U[i]]++;
	  cout << I[i] << endl;
	  now++; 
	}
      } else if(now < 20){
	if(teamLimit[U[i]] < 2 ){
	  teamLimit[U[i]]++;
	  cout << I[i] << endl;
	  now++; 
	}
      } 
    }
  }
  return 0;
}