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]++;
			q.pop();
		}
	}
	return 0;
}

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<algorithm>
#include<cstring>
using namespace std;
int x[1000][4], t[1000], n, team, maxn, maxp, maxid, loop; vector<int>p[10000];
int main() {
	while (true) {
		cin >> n;
		memset(t, 0, sizeof(t));
		for (int i = 0; i < 10000; i++) { p[i].clear(); }
		if (!n) { break; }
		for (int i = 0; i < n; i++) {
			cin >> x[i][0] >> x[i][1] >> x[i][2] >> x[i][3];
		}
		team = 0; loop = 0;
		while (loop < n) {
			maxn = 0; maxp = 1000000;

			for (int i = 0; i < n; i++) {
				if (t[i] == 0) {
					if (maxn < x[i][2]) {
						maxn = x[i][2]; maxid = i; maxp = x[i][3];
					}
					else if (maxn == x[i][2] && maxp > x[i][3]) {
						maxp = x[i][3]; maxid = i;
					}
				}
			}

			if (p[x[maxid][1]].size() < 3 && team < 10) {
				goto E;
			}
			if (p[x[maxid][1]].size() < 2 && team < 20) {
				goto E;
			}
			if (p[x[maxid][1]].size() < 1 && team < 26) {
				goto E;
			}
			goto F;
		E:;
			cout << x[maxid][0] << endl;
			p[x[maxid][1]].push_back(maxid);
			team++;
		F:;
			t[maxid] = 1;
			loop++;
		}
	}
}

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

class Team {
public:
    int id, belong, correct, penalty;
};

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

        vector<Team> teams(n);
        for (int i = 0; i < n; i++) {
            cin >> teams[i].id >> teams[i].belong >> teams[i].correct >> teams[i].penalty;
        }
        for (int i = 0; i < n - 1; i++) {
            for (int j = n - 1; j > i; j--) {
                if (teams[j - 1].correct < teams[j].correct
                    || (teams[j - 1].correct == teams[j].correct && teams[j - 1].penalty > teams[j].penalty)
                    || (teams[j - 1].correct == teams[j].correct && teams[j - 1].penalty == teams[j].penalty
                        && teams[j - 1].id > teams[j].id)) {
                    swap(teams[j - 1], teams[j]);
                }
            }
        }
        int selected = 0;
        queue<int> selected_i;
        int belongs[11] = {};
        for (int i = 0; i < n; i++) {
            if (selected < 10) {
                if (belongs[teams[i].belong] < 3) {
                    selected_i.push(i);
                    belongs[teams[i].belong]++;
                }
            } else if (selected < 20) {
                if (belongs[teams[i].belong] < 2) {
                    selected_i.push(i);
                    belongs[teams[i].belong]++;
                }
            } else if (selected < 26) {
                if (belongs[teams[i].belong] == 0) {
                    selected_i.push(i);
                    belongs[teams[i].belong]++;
                }
            } else {
                break;
            }
        }
        while (selected_i.empty() == false) {
            cout << teams[selected_i.front()].id << endl;
            selected_i.pop();
        }
    }
}