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 <algorithm>
#include <vector>
using namespace std;
const int MAX = 1001;
typedef pair<int,int> QQ;
typedef pair<int,int> PP;
typedef pair<PP,QQ> P;

int main(){
  int n;

  while(cin >> n ,n){
    int id,uni,ac,pe;
    int tc[MAX+1];
    fill(tc,tc+MAX,0);
    vector<P> v;

    while(n--){
      cin >> id >> uni >> ac >> pe;
      v.push_back(P(PP(-ac,pe),QQ(id,uni)));
    } 
    sort(v.begin(),v.end());

    int cnt = 0;
    int size = v.size();
    for(int i = 0; i < size ; i++){
      int u = v[i].second.second;
   
      if(cnt < 10){
	if(tc[u] < 3){
	  cout << v[i].second.first << endl;
	}
      }
      else if(cnt < 20){
	if(tc[u] < 2){
	  cout << v[i].second.first << endl;
	}
      }
      else if(cnt < 26){
	if(tc[u] < 1){
	  cout << v[i].second.first << endl;
	}
      }
      cnt++;
      tc[u]++;
    } 
  }

  return 0;
}

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

typedef pair<int,int> P;

int main() {
  int n;
  while(cin >> n && n!=0) {
    int u[MAX];
    priority_queue< P, vector<P>, greater<P> > que;
    for(int i=0; i<n; i++) {
      int id,a,q;
      cin >> id;
      cin >> u[id] >> a >> q;
      a=-a*1000000+q;
      que.push(P(a,id));
    }
    int d[MAX];
    for(int i=0; i<MAX; i++) d[i]=0;
    vector<int> ans;
    while(!que.empty()) {
      P p=que.top();
      que.pop();
      int a=p.first,ID=p.second;
      if(ans.size()<10 && d[u[ID]]<3) ans.push_back(ID);
      else if(ans.size()<20 && d[u[ID]]<2) ans.push_back(ID);
      else if(ans.size()<26 && d[u[ID]]<1) ans.push_back(ID);
      d[u[ID]]++;
      if(ans.size()>25) break;
    }
    for(int i=0; i<ans.size(); i++) cout << ans[i] << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>

using namespace std;

struct team{
    int id,school,right,penalty;
};
bool sor(const team& e,const team& t){
    return e.right==t.right?e.penalty==t.penalty?e.id<t.id:e.penalty<t.penalty:e.right>t.right;
}
int main(){
    int n;
    while(cin>>n,n){
        vector<team>vec;
        for(int i=0;i<n;i++){
            team t;
            cin>>t.id>>t.school>>t.right>>t.penalty;
            vec.push_back(t);
        }
        sort(vec.begin(),vec.end(),sor);
        vector<int>v;
        int sc[1002]={0};
        for(int i=0;i<vec.size();i++){
            if(v.size()<10){
                if(sc[vec[i].school]<3){
                    sc[vec[i].school]++;
                    v.push_back(vec[i].id);
                }
            } else if(v.size()<20){
                if(sc[vec[i].school]<2){
                    sc[vec[i].school]++;
                    v.push_back(vec[i].id);
                }
            } else if(v.size()<26){
                if(sc[vec[i].school]<1){
                    sc[vec[i].school]++;
                    v.push_back(vec[i].id);
                }
            }
        }
        for(int i=0;i<v.size();i++){
            cout<<v[i]<<endl;
        }
    }
}

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

using namespace std;

class State{
public:
  int a, b, c, d;
  State(int a = 0, int b = 0, int c = 0, int d = 0)
    : a(a), b(b), c(c), d(d) {}
  bool operator < (const State& s) const {
    if(c == s.c){
      if(d == s.d) return a < s.a;
      return d < s.d;
    }
    return c > s.c;
  }
};

int n;
map<int, int> univ;
State data[300];

main(){
  while(cin >> n && n){
    univ.clear();
    for(int i=0;i<n;i++){
      cin >> data[i].a >> data[i].b >> data[i].c >> data[i].d;
    }
    sort(data, data+n);
    int cnt = 0;
    for(int i=0;i<n&&cnt<26;i++){
      if(cnt < 10){
        if(univ[data[i].b] < 3){
          cout << data[i].a << endl;
          univ[data[i].b]++;
          cnt++;
        }
      }else if(cnt < 20){
        if(univ[data[i].b] < 2){
          cout << data[i].a << endl;
          univ[data[i].b]++;
          cnt++;
        }
      }else{
        if(univ[data[i].b] < 1){
          cout << data[i].a << endl;
          univ[data[i].b]++;
          cnt++;
        }
      }
    }
  }
}

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



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

void change(int x){
  tmp=id[x];id[x]=id[x+1];id[x+1]=tmp;
  tmp=id2[x];id2[x]=id2[x+1];id2[x+1]=tmp;
  tmp=ac[x];ac[x]=ac[x+1];ac[x+1]=tmp;
  tmp=wa[x];wa[x]=wa[x+1];wa[x+1]=tmp;
}
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;
    for(int i=0;i<1001;i++)used[i]=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;
}