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;
    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(i < 9 && cnt[vec[i].second.second] > 3){
      }else if(9 <=i && i < 19&& cnt[vec[i].second.second] > 2){
      }else if(19 <= i && i < 25 && cnt[vec[i].second.second] > 0){
      }else{
	cout << vec[i].second.first << endl;
      } 
      
    }
  }
  return 0;
}

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 <map>
#include <algorithm>
using namespace std;
int n,teamnum;
const int NMAX = 1000;
struct team{
  int i,u,a,p,ur;
} t[NMAX];

map<int,int> area;

bool operator < (team a, team b){
  if(a.a == b.a){
    if(a.p == b.p){
      return a.i > b.i;
    }else{return a.p > b.p;}
  }else{return a.a < b.a;}
}

template<class T>
bool greater(const T &a, const T &b){
  return b < a;
}

int main(){
  while(1){
    area.clear();
    teamnum = 0;
    cin >> n;
    if(n == 0)return 0;
    for(int i = 0;i < n;i++){
      cin >> t[i].i >> t[i].u >> t[i].a >> t[i].p;
    }
    sort(t,t+n);
    //reverse(t, t + n);

    for(int i = n-1;i >= 0;i--){
      if(teamnum < 10 && area[t[i].u] < 3){
	teamnum++;
	area[t[i].u]++;
	cout << t[i].i << endl;
      }
      else if(teamnum < 20 && area[t[i].u] < 2){
	teamnum++;
	area[t[i].u] ++;
	cout << t[i].i << endl;
      }else if(teamnum < 26 && area[t[i].u] < 1){
	teamnum++;
	area[t[i].u]++;
	cout << t[i].i << endl;
      }
    }
  }

  return 0;
}

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

using namespace std;

struct Team{
	int id,blg,ac,pen;
	bool operator<(const Team &t)const{
		if(this->ac>t.ac)	return true;
		if(this->ac==t.ac){
			if(this->pen<t.pen)	return true;
			if(this->pen==t.pen){
				return (this->id<t.id);
			}
		}
		return false;
	}
};

int main(){
	for(int n;scanf("%d",&n),n;){
		Team tm[300];
		for(int i=0;i<n;i++)	scanf("%d%d%d%d",&tm[i].id,&tm[i].blg,&tm[i].ac,&tm[i].pen);

		sort(tm,tm+n);

		int selected=0,cnt[1001]={};
		for(int i=0;i<n;i++){
			if(selected<10){
				if(cnt[tm[i].blg]<3){
					selected++;
					printf("%d\n",tm[i].id);
					cnt[tm[i].blg]++;
				}
			}
			else if(selected<20){
				if(cnt[tm[i].blg]<2){
					selected++;
					printf("%d\n",tm[i].id);
					cnt[tm[i].blg]++;
				}
			}
			else if(selected<26){
				if(cnt[tm[i].blg]<1){
					selected++;
					printf("%d\n",tm[i].id);
					cnt[tm[i].blg]++;
				}
			}
		}
	}

	return 0;
}

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

using namespace std;

int main()
{
    int N; vector<int> I, U, A, P, C;
    
    while(true)
    {
        cin >> N;
        
        if(N == 0) { break; }
        
        for(int i = 0; i < N; i++)
        {
            cin >> I[i] >> U[i] >> A[i] >> P[i];
        }
        
        C = vector<int>(1001, 0);
        
        for(int i = 0; i < N; i++)
        {
            for(int j = i + 1; j < N; j++)
            {
                if(A[i] < A[j] || (A[i] == A[j] && P[i] > P[j]))
                {
                    swap(A[i], A[j]);
                    swap(P[i], P[j]);
                    swap(I[i], I[j]);
                    swap(U[i], U[j]);
                }
            }
        }
        
        int count_ = 0;
        
        for(int i = 0; i < N; i++)
        {
            if((count_ < 10 && C[U[i]] < 3) || (count_ < 20 && C[U[i]] < 2) || (count_ < 26 && C[U[i]] == 0))
            {
                cout << I[i] << endl;
                
                C[U[i]]++; count_++;
            }
        }
    }
    
    return 0;
}