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 <cstdio>
#include <queue>

using namespace std;

typedef struct Score {
	Score(int i, int u, int a, int p){
		id = i; school = u; success = a; penalty = p;
	}
	int id, school, success, penalty;
} Score;

typedef struct MyComparator {
	bool operator()(Score &a, Score &b){
		if(a.success < b.success){ return true; }
		if(a.success > b.success){ return false; }
		if(a.penalty > b.penalty){ return true; }
		if(a.penalty < b.penalty){ return false; }
		return (a.id > b.id);
	}
} MyComparator;

int main(){
	while(true){
		int n;
		scanf("%d", &n);
		if(n == 0){ break; }
		priority_queue<Score, vector<Score>, MyComparator> q;
		int cs[1001] = { 0 };
		int rank = 1;
		while(n--){
			int i, u, a, p;
			scanf("%d%d%d%d", &i, &u, &a, &p);
			q.push(Score(i, u, a, p));
		}
		while(!q.empty() && rank <= 26){
			Score s = q.top();
			if(rank <= 10){
				if(cs[s.school] < 3){ printf("%d\n", s.id); }
			}else if(rank <= 20){
				if(cs[s.school] < 2){ printf("%d\n", s.id); }
			}else{
				if(cs[s.school] < 1){ printf("%d\n", s.id); }
			}
			cs[s.school]++;
			rank++;
			q.pop();
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;

int main() {
    int N;
    while (cin >> N, N) {
        vector<vector<P> > rank(11);
        vector<int> univ_id(1001);

        for (int c = 0; c < N; c++) {
            int i, u, a, p;
            cin >> i >> u >> a >> p;
            rank[a].push_back(P(p,i));
            univ_id[i] = u;
        }

        for (auto& i : rank)
            sort(i.begin(), i.end());

        int count = 0;
        vector<int> univ_cnt(1001);
        for (int i = 10; i > -1; i--) {
            for (auto team : rank[i]) {
                int I = team.second;
                int pena = team.first;
                int limit = 0;
                if (count < 10) limit = 3;
                else if (count < 20) limit = 2;
                else if (count < 26) limit = 1;
                else limit = 0;
                if (univ_cnt[univ_id[I]] < limit) {
                    cout << I << endl;
                    univ_cnt[univ_id[I]]++;
                    count++;
                }
            }
        }
    }

    return 0;
}

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

map<int,bool> used;
map<int,int> count_t;
map<int,bool> isDecided;

int main(){
    while(true){
	int n;
	vector< pair< pair<int,int> , pair<int,int> > > t;
	cin >> n;
	if(n==0) break;
	used.clear();
	count_t.clear();
	isDecided.clear();
	REP(i,n){
	    int I,A,U,P;
	    cin >> I >> U >> A >> P;
	    t.PB( MP( MP(-A,P) , MP(I,U) ) );
	    used[I] = false;
	    count_t[U] = false;
	    isDecided[I] = false;
	}
	sort(ALL(t));
// 	REP(i,n) printf("A: %d P: %d I: %d U: %d\n",-t[i].first.first,t[i].first.second,t[i].second.first,t[i].second.second);
	int temp = 0;

// 	REP(i,n){
// 	    if(!used[t[i].second.second]){
// 		used[t[i].second.second] = true;
// 		count_t[t[i].second.second]++;
// 		isDecided[t[i].second.first] = true;
// 		temp++;
// 	    }
// 	}

	if(temp < 10){
	    REP(i,n){
		if(!isDecided[t[i].second.first] && count_t[t[i].second.second] < 3){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
		    temp++;
		}
		if(temp == 10) break;
	    }
	}


	if(temp < 20){
	    REP(i,n){
		if(!isDecided[t[i].second.first] && count_t[t[i].second.second] < 2){
		    count_t[t[i].second.second]++;
		    isDecided[t[i].second.first] = true;
			temp++;
		}
		if(temp == 20) break;
	    }
	}

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

	REP(i,n){
	    if(isDecided[t[i].second.first]) cout << t[i].second.first << endl;
	}
    }

    return 0;
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, pair<int , pair<int , int> > > pppi;

bool cmp(const pppi &a, const pppi &b){
  if(a.S.S.F != b.S.S.F) return a.S.S.F > b.S.S.F;
  if(a.S.S.S != b.S.S.S) return a.S.S.S < b.S.S.S;
  return a.F < b.F;
}

int main(){
  int n;
  while(scanf("%d", &n) && n){

    vector<pppi> re(n);

    int l, u, a, p;
    rep(i, n){

      scanf("%d%d%d%d", &l, &u, &a, &p); l--; u--;
      re[i] = make_pair(l, make_pair(u, make_pair(a, p)));
    }

    sort(re.begin(), re.end(), cmp);

    vector<int>j(1000, 0);
    int all = 0;
    rep(i, n){
      if((all < 10 && j[re[i].S.F] < 3) || (all < 20 && j[re[i].S.F] < 2) || (all < 26 && j[re[i].S.F] < 1)){
	printf("%d\n", re[i].F+1);
	j[re[i].S.F]++;
	all++;
      }
    }
  }
  return 0;
}