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>
using namespace std;
//const int RULE[3] = {10,20,26};
//const int MEM[3] = {3,2,1};

int main(){
  while(1){
    int n;
    cin >> n;

    if(n == 0)break;///// 正解数,−１＊ペナルテ,ID,所属
    
    vector<pair<pair<int,int>,
		pair<int,int>		
		>
	   > vec(n,pair<pair<int,int>,pair<int,int> >());
    for(int i = 0;i < n;i++){
      int l,u,a,p;
      cin >> l >> u >> a >> p;
      vec[i].first = pair<int,int>(-1*a,p);
      vec[i].second = pair<int,int>(l,u);
    }
    sort(vec.begin(),vec.end());
    vector<int> cnt(1000,0);
    //int ii = 0;
    int f = 0;
    for(int i = 0;i < n;i++){
      //      cout << vec[i].second.second << "DEGG" << cnt[vec[i].second.second]<< endl;
      
      cnt[vec[i].second.second]++;
      if(f < 10 && cnt[vec[i].second.second] > 3){
	
      }else if(10 <=f && f < 20&& cnt[vec[i].second.second] > 2){
       
      }else if(20 <= f && f < 26 && cnt[vec[i].second.second] > 1){
	
      }else{
	cout << vec[i].second.first << endl;
	f++;
	if(f == 26)break;
      } 
      
    }
  }
  return 0;
}

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

struct Team {
	int id;
	int uni;
	int solved;
	int penalty;
	bool selected;

	bool operator<(const Team& another) const {
		if(solved != another.solved) {
			return (solved > another.solved);
		}
		if (penalty != another.penalty) {
			return (penalty < another.penalty);
		}
		return id < another.id;
	}
};

int selectedCounts[1001];

int main() {
	int n;
	while(true) {
		cin >> n;
		if (n == 0) {
			break;
		}

		vector<Team> teams(n);
		for (int i = 0; i < n; i++) {
			cin >> teams[i].id >> teams[i].uni >> teams[i].solved >> teams[i].penalty;
			teams[i].selected = false;
		}

		for (int i = 0; i < 1001; i++) {
			selectedCounts[i] = 0;
		}

		sort(teams.begin(), teams.end());

		int entireSelectedCount = 0;

		for (int i = 0; i < n; i++) {
			if(entireSelectedCount < 10 && selectedCounts[teams[i].uni] < 3
					|| entireSelectedCount < 20 && selectedCounts[teams[i].uni] < 2
					|| entireSelectedCount < 26 && selectedCounts[teams[i].uni] < 1) {
				selectedCounts[teams[i].uni]++;
				entireSelectedCount++;
				cout << teams[i].id << endl;
			}
		}

	}
	return 0;
}

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

using namespace std;

const int MAX = 300;
const int UMAX = 1001;
typedef pair<int,int> P;

int n;
struct team{
  int I;
  int U;
  int A;
  int P;
  bool passed;
};
int UNUM[UMAX];
team T[MAX];
int pass;
P p[3] = {P(10,3),P(20,2),P(26,1)};


void T_sort(){

  for(int i = 0; i < n; i++)
    for(int j = i; j < n; j++)
      if(T[i].A < T[j].A || (T[i].A == T[j].A && T[i].P > T[j].P) ||
	 (T[i].A == T[j].A && T[i].P == T[j].P && T[i].I > T[j].I))
	swap(T[i],T[j]);
}

void solve(){
 
  for(int R = 0; R < 3; R++)
    for(int i = 0; pass < p[R].first,i < n; i++){
      if(T[i].passed == false && UNUM[T[i].U] < p[R].second){
	cout << T[i].I << endl;
	T[i].passed = true;
	UNUM[T[i].U]++;
	pass++;
      }
    }
}


void init(){
  pass = 0;
  fill(UNUM,UNUM+UMAX,0);
}
int main(){
  while(cin >> n && n){
    init();
    for(int i = 0; i < n; i++){
      cin >> T[i].I >> T[i].U >> T[i].A >> T[i].P;
      T[i].passed = false;
    }
    T_sort();
    solve();
  }
  
  return 0;
}