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>

using namespace std;

const double inf = (int)1e8;

int main(){
    int n;
    while(cin >> n, n){
        vector<pair<int, pair<int, int>>> v;
        map<int, int> m, af;
        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(inf-a, make_pair(p, id)));
        }
        sort(v.begin(), v.end());
        int count = 0;
        for(int i=0; i< n; i++){
            if(count < 10 && af[m[i]] < 3 || count < 20 && af[m[i]] < 2 && count < 26 && af[m[i]] < 1){cout << v[i].second.second << endl; af[m[i]]++;}
        }
    }
}

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

using namespace std;

bool cmp(pair<int, int[3]> p, pair<int, int[3]> q)
{
    return (p.second[1] > q.second[1]) || (p.second[1] == q.second[1] && p.second[2] < q.second[2])
        || (p.second[1] == q.second[1] && p.second[2] == q.second[2] && p.first < q.first);
}

int main()
{
    int n;

    while (cin >> n) {
        if (!n)
            break;

        pair<int, int[3]> team[300];
        int select[1000] = {0};

        for (int i = 0; i < n; i++) {
            cin >> team[i].first >> team[i].second[0] 
                >> team[i].second[1] >> team[i].second[2];
        }
        sort(team, team + n, cmp);
        
        int sl = 0;  // Number of the selected team.
        for (int i = 0; i < n; i++) {
            if (sl < 10 && select[team[i].second[0] - 1] < 3) {
                if (select[team[i].second[0] - 1] == 0) 
                    sl++;
                select[team[i].second[0] - 1]++;
                cout << team[i].first << endl;
            }
            else if (sl < 20 && select[team[i].second[0] - 1] < 2) {
                if (select[team[i].second[0] - 1] == 0)
                    sl++;
                select[team[i].second[0] - 1]++;
                cout << team[i].first << endl;
            }
            else if (sl < 26 && select[team[i].second[0] - 1] == 0) {
                sl++;
                select[team[i].second[0] - 1]++;
                cout << team[i].first << endl;
            }
        }
    }

    return 0;
}

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

using namespace std;

int main ()
{
	int n, select = 0, I, U, A, P;
	vector<pair<int, pair<int, pair<int, int> > > > team;	//正解数,ペナルティ,ID,所属
	vector<int> sr;	//選抜されたチームの所属

	while (cin >> n)
	{
		if(n == 0)	break;

		for (int i=0; i<n; i++){
			cin >> I >> U >> A >> P;
			team.push_back(make_pair(-A, make_pair(P, make_pair(I, U))));
		}

		sr.push_back(0);

		sort(team.begin(), team.end());
	
		for (int i=0; i<n; i++)
		{
			int cont = 0;
			
			for (vector<int>::iterator itsr = sr.begin(); itsr != sr.end(); itsr++){
				if(team[i].second.second.second == *itsr)
					cont++;
			}

			if(select < 10 && cont < 3){
				cout << team[i].second.second.first << endl;
				sr.push_back(team[i].second.second.second);
				select++;
			}
			else if(select < 20 && cont < 2){
				cout << team[i].second.second.first << endl;
				sr.push_back(team[i].second.second.second);
				select++;
			}
			else if(select < 26 && cont < 1){
				cout << team[i].second.second.first << endl;
				sr.push_back(team[i].second.second.second);
				select++;
			}
		}

		team.clear();
		sr.clear();
	}

	return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,sc[10010];
struct Set{
  int I,U,A,P;
};
bool comp(const Set& a, const Set& b){
  if(a.A!=b.A){
    return a.A>b.A;
  }else{
    return a.P<b.P;
  }
}
vector<Set> vec;
void el(int x){
  sc[vec[x].U]++;
  cout<<vec[x].I<<endl;
}
int main(){
  while(1){
    cin>>n;
    for(int i=0;i<n;i++)sc[i]=0;
    vec.clear();
    if(n==0)break;
    for(int i=0;i<n;i++){
      Set t;
      cin>>t.I>>t.U>>t.A>>t.P;
      vec.push_back(t);
    }
    sort(vec.begin(),vec.end(),comp);
    for(int i=0;i<min(26,n);i++){
      if(i<10){
	if(sc[vec[i].U]<3)el(i);
      }else if(i<20){
	if(sc[vec[i].U]<2)el(i);
      }else{
	if(sc[vec[i].U]==0)el(i);
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
struct po{
  int I,U,A,P,sum;
};

int main (){
  int n;

  while(1) {
  cin >> n;
  if (n == 0) break;
  vector <po> D;
  D.resize(n);
  for(int i=0;i<n;i++) cin >> D[i].I >> D[i].U >> D[i].A >> D[i].P;

  po t;
  for(int i=0;i<n;i++) {
    for(int j=n-1;j>i;j--){
      if(D[j].A > D[j-1].A){
	t = D[j];
	D[j] = D[j-1];
	D[j-1] = t;
      }
      if(D[j].A == D[j-1].A) {
	if(D[j].P < D[j-1].P) {
	  t = D[j];
	  D[j] = D[j-1];
	  D[j-1] = t;
	}
	if(D[j].P == D[j-1].P && D[j].U <= D[j-1].U) {
	  t  = D[j];
	  D[j] = D[j-1];
	  D[j-1] = t;
	}
      }
    }
  }

  int goukei = 0;
  int flg[1001] = {};

  for(int i=0;i<n;i++) {
    if(goukei < 10 && flg[D[i].U] < 3) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
    else if(goukei < 20 && flg[D[i].U]< 2) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
    else if(goukei < 26 && flg[D[i].U] == 0) {
      cout << D[i].I << endl;
      flg[D[i].U]++;
      goukei++;
    }
  }

  }

  return 0;
}