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>
#define int long long
using namespace std;
 
signed main(){
int a;
while(cin>>a,a){
    multimap<int,int>s;
    for(int b=0;b<a;b++){
	int c,d,e,f;
	scanf("%lld%lld%lld%lld",&c,&d,&e,&f);
	s.insert(pair<int,int>(-e*10000000000+f*10000-c,d));
	}
	map<int,int>k;
	int sum=0;
	for(auto u=s.begin();u!=s.end()&&sum<26;u++){
	    if(sum<10){
		if(k[u->second]<3){printf("%lld\n",abs((u->first)%10000));k[u->second]++;sum++;}
		}
		else if(sum<20){if(k[u->second]<2){printf("%lld\n",abs(u->first%10000));k[u->second]++;sum++;}}
		else if(k[u->second]==0){printf("%lld\n",abs(u->first%10000));k[u->second]++;sum++;}
	    }
    }
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <utility>
using namespace std;

typedef struct{
	int num;
	int u;
	int ac;
	long p;
}team;


int main(){
	while(1){
		int n;
		team t[300];
		scanf(" %d", &n);
		if(n==0) break;
		for(int i=0; i<n; ++i) scanf(" %d %d %d %ld", &t[i].num, &t[i].u, &t[i].ac, &t[i].p);
		
		//sort
		for(int i=0; i<n; ++i){
			for(int j=i+1; j<n; ++j){
				
				if(t[i].ac<t[j].ac) swap(t[i],t[j]);
				else if(t[i].ac==t[j].ac){
					if(t[i].p>t[j].p) swap(t[i],t[j]);
					else if(t[i].p==t[j].p){
						if(t[i].num>t[j].num) swap(t[i],t[j]);
					}
				}
				
			}
		}
		
		//for(int i=0; i<n; ++i) printf(" %d %d %d %ld\n", t[i].num, t[i].u, t[i].ac, t[i].p);
		
		int now=0;
		int bel[1001]; //????±????????????°?????????????????°	
		bool sel[1001]; //?????°??????????????????
		
		memset(bel, 0, sizeof(bel));
		for(int i=0; i<=1000; ++i) sel[i]=false;
		
		for(int i=0; i<n; ++i){
			if(sel[t[i].num]) continue;
			
			if(bel[t[i].u]<3){
				printf("%d\n", t[i].num);
				sel[t[i].num]=true;
				bel[t[i].u]++;
				now++;
			}
			
			if(now==10) break;
		}
	
		for(int i=0; i<n; ++i){
			if(sel[t[i].num]) continue;
			
			if(bel[t[i].u]<2){
				printf("%d\n", t[i].num);
				sel[t[i].num]=true;	
				bel[t[i].u]++;
				now++;
			}
			
			if(now==20) break;
		}
	
		for(int i=0; i<n; ++i){
			if(sel[t[i].num]) continue;
			
			if(bel[t[i].u]<1){
				printf("%d\n", t[i].num);
				sel[t[i].num]=true;	
				bel[t[i].u]++;
				now++;
			}
			
			if(now==26) break;
		}
	

	}
}

C++: #include<map>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int h,i,j;
  int a[300],b[300],c[300],d[300],n;
  map<int,int> z;
  while(cin>>n&&n){
    for(i=0;i<n;i++)
      cin>>a[i]>>b[i]>>c[i]>>d[i];
    h=1;
    for(i=0;h;i++){
      h=0;
      for(j=1;j<n-i;j++){
	if(0){
	}else if(c[j-1]<c[j]){
	  swap(a[j-1],a[j]);
	  swap(b[j-1],b[j]);
	  swap(c[j-1],c[j]);
	  swap(d[j-1],d[j]);
	  h=1;
	}else if(c[j-1]==c[j]){
	  if(0){
	  }else if(d[j-1]>d[j]){
	    swap(a[j-1],a[j]);
	    swap(b[j-1],b[j]);
	    swap(c[j-1],c[j]);
	    swap(d[j-1],d[j]);
	    h=1;
	  }else if(d[j-1]==d[j]){
	    if(a[j-1]>a[j]){
	      swap(a[j-1],a[j]);
	      swap(b[j-1],b[j]);
	      swap(c[j-1],c[j]);
	      swap(d[j-1],d[j]);
	      h=1;
	    }
	  }
	}
      }
    }
    z.clear();
    j=0;
    for(i=0;i<n;i++){
      if(0){
      }else if(j<10){
	if(z[b[i]]<3){
	  cout<<a[i]<<endl;
	  j++;
	  z[b[i]]++;
	}
      }else if(j<20){
	if(z[b[i]]<2){
	  cout<<a[i]<<endl;
	  j++;
	  z[b[i]]++;
	}
      }else if(j<26){
	if(z[b[i]]<1){
	  cout<<a[i]<<endl;
	  j++;
	  z[b[i]]++;
	}
      }
    }
  }
  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;
    int flag = 0;
    if(n == 0)break;///// テヲツュツ」ティツァツ」テヲツ閉ー,テ「ツ按津ッツシツ妥ッツシツ甘」ツδ堙」ツδ甘」ツδォテ」ツδ?ID,テヲツ可?・ツアツ?
    else if(n < 10)flag = 0;
    else if(n < 20)flag = 1;
    else flag = 2;
    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>(a,-1*p);
      vec[i].second = pair<int,int>(-1*l,u);
    }
    sort(vec.begin(),vec.end());
    vector<int> cnt(1000,0);
    for(int i = n-1;i >= 0;i--){
      //      cout << vec[i].second.second << "DEGG" << cnt[vec[i].second.second]<< endl;
      cnt[vec[i].second.second]++;
      if(cnt[vec[i].second.second] > MEM[flag]){
      }else{
	cout << -1*vec[i].second.first << endl;
      }
	    //   cout << -1*vec[i].second.first << endl;
      /*
      if(i < 10 && cnt[vec[i].second.second] == 4){
      cnt[vec[i].second.second]--;
	pair<pair<int,int>,
	     pair<int,int>		
	     > tmp = vec[i];
	vec[i] = vec[i+1];
	vec[i+1] = tmp;
      }
      if(i < 20 && cnt[vec[i].second.second] == 3){
	cnt[vec[i].second.second]--;
	pair<pair<int,int>,
	     pair<int,int>		
	     > tmp = vec[i];
	vec[i] = vec[i+1];
	vec[i+1] = tmp;
      }
      if(i < 26 && cnt[vec[i].second.second] == 2){
	cnt[vec[i].second.second]--;
	pair<pair<int,int>,
	     pair<int,int>		
	     > tmp = vec[i];
	vec[i] = vec[i+1];
	vec[i+1] = tmp;
	}*/
	///////////
      
    }
    /*    for(int i = 0;i < n;i++){
      cout << vec[i].second.first << endl;
      }*/
  }
  return 0;
}