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>
#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};

int main(){
    while(true){
	int n;
	vector< pair< pair<int,int> , pair<int,int> > > t;
	cin >> n;
	if(n==0) break;
	REP(i,n){
	    int I,A,U,P;
	    cin >> I >> U >> A >> P;
	    t.PB( MP( MP(-A,P) , MP(I,U) ) );
	    sort(ALL(t));
	}
	vector<bool> used(n,false);
	vector<int> count_t(n,0);
	vector<bool> isDecided(n,false);
	vector<int> ans;
	REP(i,n){
	    if(!used[t[i].second.second-1]){
		used[t[i].second.second-1] = true;
		count_t[t[i].second.second-1]++;
		isDecided[t[i].second.first-1] = true;
		ans.PB(t[i].second.first);
	    }
	}

	if(ans.size() < 10){
	    REP(i,n){
		if(!isDecided[t[i].second.first-1] && count_t[t[i].second.second-1] < 3){
		    count_t[t[i].second.second-1]++;
		    isDecided[t[i].second.second-1] = true;
		    ans.PB(t[i].second.first);
		}
	    }
	}


	if(ans.size() < 20){
	    REP(i,n){
		if(!isDecided[t[i].second.first-1] && count_t[t[i].second.second-1] < 2){
		    count_t[t[i].second.second-1]++;
		    isDecided[t[i].second.first-1] = true;
		    ans.PB(t[i].second.first);
		}
	    }
	}

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

	sort(ALL(ans));
	REP(i,ans.size()) cout << ans[i] << endl;
    }

    return 0;
}

C++: #include<iostream>
#include<vector>
#include<queue>
#include<map>
using namespace std;
struct data{
  int id;
  int team;
  int ans;
  int pena;
  data(int i,int t,int a,int p):id(i),team(t),ans(a),pena(p){}
  bool operator >(const data &e)const{
    if(ans!=e.ans)      
      return ans<e.ans;
    if(pena!=e.pena)
      return pena>e.pena;
    return id>e.id;
  }  
};

int main()
{
  int n;
  for(;cin>>n,n;)
    {
      priority_queue<data,vector<data>,greater<data> >qu;
      for(int i=0;i<n;i++)
	{
	  int l,u,a,p;
	  cin>>l>>u>>a>>p;
	  qu.push(data(l,u,a,p));
	}
      int cnt=0;
      map<int,int> teamcnt;
      for(;!qu.empty();)
	{
	  data tmp=qu.top();
	  qu.pop();
	  if(cnt<10)
	    {
	      if(teamcnt[tmp.team]<3)
		{
		  cout<<tmp.id<<endl;
		  cnt++;
		  teamcnt[tmp.team]++;
		}
	    }
	  else if(cnt<20)
	    {
	      if(teamcnt[tmp.team]<2)
		{
		  cout<<tmp.id<<endl;
		  cnt++;
		  teamcnt[tmp.team]++;
		}
	    }
	  else if(cnt<26)
	    {
	      if(teamcnt[tmp.team]<1)
		{
		  cout<<tmp.id<<endl;
		  cnt++;
		  teamcnt[tmp.team]++;
		}
	    }	  
	}
    }
}

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

int main(){
	int n;
	while( cin >> n , n ){
		vector<pair<int,pair<int,pair<int,int> > > > vc;
		vector<int> ans;
		int u[1001] = {0};

		for(int i=0 ; i < n ; i++ ){
			int ID,Univ,AC,WA;
			cin >> ID >> Univ >> AC >> WA;
			pair<int,int> a(ID,Univ);
			pair<int,pair<int,int> > b(WA,a);
			pair<int,pair<int,pair<int,int> > > c(-AC,b);
			vc.push_back( c );
		}
		sort( vc.begin() , vc.end() );
		for(int i=0 ; i < n ; i++ ){
			int AC = -vc[i].first;
			int WA = vc[i].second.first;
			int ID = vc[i].second.second.first;
			int Univ = vc[i].second.second.second;
			if( ans.size() < 10 && u[Univ] < 3 ){
				ans.push_back( ID );
				u[Univ]++;
			}else if( ans.size() < 20 && u[Univ] < 2 ){
				ans.push_back( ID );
				u[Univ]++;
			}else if( ans.size() < 26 && u[Univ] < 1 ){
				ans.push_back( ID );
				u[Univ]++;
			}
		}
		for(int i=0 ; i < ans.size() ; i++ ){
			cout << ans[i] << endl;
		}
	}
}

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

constexpr int MAX = 1001;
int cnt[MAX];

struct team {
	int id, univ, AC, time;
	team(int id_, int univ_, int AC_, int time_):id(id_), univ(univ_), AC(AC_), time(time_) {}
	bool operator>(const team &t) const {
		if(AC != t.AC) return AC > t.AC;
		if(time != t.time) return time < t.time;
		return id < t.id;
	}
};

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	for(int n; cin >> n && n;) {
		vector<team> teams;
		teams.reserve(n);

		for(int i = 0; i < n; ++i) {
			int id, u, a, p;
			cin >> id >> u >> a >> p;
			teams.emplace_back(id, u, a, p);
		}

		sort(teams.begin(), teams.end(), greater<team>());
		
		int sum = 0;
		memset(cnt, 0, sizeof(cnt));
		int limit = 3;
		for(const auto &t : teams) {
			if(cnt[t.univ] < limit) {
				cout << t.id << endl;
				++cnt[t.univ];
				++sum;
				if(sum == 10 || sum == 20 || sum == 26) --limit;
			}
		}
	}

	return EXIT_SUCCESS;
}