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



int a,b,c,d,n,cnt;
string str;
int id[300],id2[300],ac[300],wa[300],used[1001];

void change(int x){
  swap(id[x],id[x+1]);
  swap(id2[x],id2[x+1]);
  swap(ac[x],ac[x+1]);
  swap(wa[x],wa[x+1]);
}
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>id[i]>>id2[300]>>ac[300]>>wa[300];
    }
    for(int i=n-1;i>0;i--){
      for(int j=0;j<i;j++){
	if(ac[j]<ac[j+1]){
	  change(j);
	}else if(ac[j]==ac[j+1]&&wa[j]>wa[j+1]){
	  change(j);
	}else if(ac[j]==ac[j+1]&&wa[j]==wa[j+1]&&id[j]>id[j+1]){
	  change(j);
	}
      }
    }
    cnt=0;
    fill(used,used+1001,0);
    for(int i=0;i<n;i++){
      if(cnt<10){
	if(used[id2[i]]<3){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }else if(cnt<20){
	if(used[id2[i]]<2){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }else if(cnt<26){
	if(used[id2[i]]==0){
	  used[id2[i]]++;
	  cout<<id[i]<<endl;
	  cnt++;
	}
      }
    }


  }
  
  return 0;
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int num_of_selected[1001],total;

struct Info{
	Info(){
		id = group = ans = penalty = 0;
	}
	int id,group,ans,penalty;
};

void func(int N){

	Info info[N];

	for(int i = 0; i < N; i++){
		scanf("%d %d %d %d",&info[i].id,&info[i].group,&info[i].ans,&info[i].penalty);
	}

	for(int i = 1; i <= N-1; i++){
		for(int k = N-1; k >= i; k--){
			if((info[k].ans > info[k-1].ans) || (info[k].ans == info[k-1].ans && info[k].penalty < info[k-1].penalty) ||
					(info[k].ans == info[k-1].ans && info[k].penalty == info[k-1].penalty && info[k].id < info[k-1].id))swap(info[k],info[k-1]);
		}
	}

	total = 0;
	for(int i = 0; i < N && total < 26; i++){
		if(total < 10 && num_of_selected[info[i].group] < 3){
			num_of_selected[info[i].group]++;
			total++;
			printf("%d\n",info[i].id);
		}else if(total < 20 && num_of_selected[info[i].group] < 2){
			num_of_selected[info[i].group]++;
			total++;
			printf("%d\n",info[i].id);
		}else if(total < 26 && num_of_selected[info[i].group] == 0){
			num_of_selected[info[i].group]++;
			total++;
			printf("%d\n",info[i].id);
		}
	}
}

int main(){

	int N;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 1; i<= 1000; i++)num_of_selected[i] = 0;

		func(N);
	}

	return 0;
}

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], uni[1010] = {0};
        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, make_pair(p, id)));
        }
        sort(v.begin(), v.end());
        int count = 0;
        for(int i=0; i< v.size(); i++){
            if((count < 10 && uni[m[i]] < 3) || (count < 20 && uni[m[i]] < 2) || (count < 26 && uni[m[i]] < 1)){cout << v[i].second.second << endl; uni[m[i]]++; count++;}
        }
    }
}

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

int main() {
    while (1) {
        int n;
        cin >> n;
        if (!n) break;
        
        vector< vector<int> > v(n, vector<int>(4, 0));
        for (int i = 0; i < n; i++) {
            int I, U, A, P;
            cin >> I >> U >> A >> P;
            v.at(i).at(0) = A;
            v.at(i).at(1) = 100000 - P;
            v.at(i).at(2) = 1000 - I;
            v.at(i).at(3) = 1000 - U;
        }
        
        sort(v.begin(), v.end());
        reverse(v.begin(), v.end());
        
        int cnt = 0;
        map<int, int> m;
        for (int i = 0; i < n; i++) {
            int x = 0;
            if (cnt < 10 - 1) {
                x = 3;
            } else if (cnt < 20 - 1) {
                x = 2;
            } else if (cnt < 26 - 1) {
                x = 1;
            }
            if (m.count(v.at(i).at(3))) {
                if (m.at(v.at(i).at(3)) >= x) {
                    continue;
                } else {
                    m.at(v.at(i).at(3))++;
                }
            } else {
                m[v.at(i).at(3)] = 1;
            }
            cout << 1000 - v.at(i).at(2) << endl;
            cnt++;
            if (cnt == 26) break;
        }
    }
    
    return 0;
}

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;
          ++cnt;
        }
      } else if(cnt < 20){
        if(m[T[i].u] < 2){
          cout <<T[i].id <<endl;
          m[T[i].u] += 1;
          ++cnt;
        }
      } else if(cnt < 26){
        if(m[T[i].u] < 1){
          cout <<T[i].id <<endl;
          m[T[i].u] += 1;
          ++cnt;
        }
      }
    }
  }
  return 0;
}